1 /*
2  * Copyright (c) 2019 Kevin Townsend (KTOWN)
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <math.h>
8 #include <errno.h>
9 #include <zsl/zsl.h>
10 #include <zsl/physics/photons.h>
11 
12 int
zsl_phy_photon_ener(zsl_real_t lambda,zsl_real_t * e)13 zsl_phy_photon_ener(zsl_real_t lambda, zsl_real_t *e)
14 {
15 	if (lambda <= 0) {
16 		*e = NAN;
17 		return -EINVAL;
18 	}
19 
20 	*e = (ZSL_LIGHT_SPEED * ZSL_PLANCK) / (lambda * 1.602176634E-19);
21 
22 	return 0;
23 }
24 
25 int
zsl_phy_photon_mom(zsl_real_t lambda,zsl_real_t * p)26 zsl_phy_photon_mom(zsl_real_t lambda, zsl_real_t *p)
27 {
28 	if (lambda <= 0) {
29 		*p = NAN;
30 		return -EINVAL;
31 	}
32 
33 	*p = ZSL_PLANCK / (lambda * 1.602176634E-19);
34 
35 	return 0;
36 }
37 
38 int
zsl_phy_photon_wavelength(zsl_real_t f,zsl_real_t * lambda)39 zsl_phy_photon_wavelength(zsl_real_t f, zsl_real_t *lambda)
40 {
41 	if (f <= 0) {
42 		*lambda = NAN;
43 		return -EINVAL;
44 	}
45 
46 	*lambda = ZSL_LIGHT_SPEED / f;
47 
48 	return 0;
49 }
50 
51 int
zsl_phy_photon_frequency(zsl_real_t lambda,zsl_real_t * f)52 zsl_phy_photon_frequency(zsl_real_t lambda, zsl_real_t *f)
53 {
54 	if (lambda <= 0) {
55 		*f = NAN;
56 		return -EINVAL;
57 	}
58 
59 	*f = ZSL_LIGHT_SPEED / lambda;
60 
61 	return 0;
62 }
63 
64 int
zsl_phy_photon_photoelectric(zsl_real_t f,zsl_real_t w,zsl_real_t * kmax)65 zsl_phy_photon_photoelectric(zsl_real_t f, zsl_real_t w, zsl_real_t *kmax)
66 {
67 	if (f < 0 || w < 0) {
68 		*kmax = NAN;
69 		return -EINVAL;
70 	}
71 
72 	*kmax = ((ZSL_PLANCK * f) / 1.602176634E-19) - w;
73 
74 	return 0;
75 }
76