nstd_math/
lib.rs

1use std::os::raw::*;
2#[cfg(feature = "deps")]
3pub mod deps {}
4
5/// Generates the abs function.
6macro_rules! nstd_create_abs_fn {
7    ($name: ident, $type: ty) => {
8        #[inline]
9        #[cfg_attr(feature = "clib", no_mangle)]
10        pub unsafe extern "C" fn $name(x: $type) -> $type {
11            x.abs()
12        }
13    };
14}
15nstd_create_abs_fn!(nstd_math_abs_float, c_float);
16nstd_create_abs_fn!(nstd_math_abs_double, c_double);
17nstd_create_abs_fn!(nstd_math_abs_schar, c_schar);
18nstd_create_abs_fn!(nstd_math_abs_short, c_short);
19nstd_create_abs_fn!(nstd_math_abs_int, c_int);
20nstd_create_abs_fn!(nstd_math_abs_long, c_long);
21nstd_create_abs_fn!(nstd_math_abs_longlong, c_longlong);
22
23/// Generates the mod function.
24macro_rules! nstd_create_mod_fn {
25    ($name: ident, $type: ty) => {
26        #[inline]
27        #[cfg_attr(feature = "clib", no_mangle)]
28        pub unsafe extern "C" fn $name(x: $type, y: $type) -> $type {
29            x % y
30        }
31    };
32}
33nstd_create_mod_fn!(nstd_math_mod_float, c_float);
34nstd_create_mod_fn!(nstd_math_mod_double, c_double);
35nstd_create_mod_fn!(nstd_math_mod_schar, c_schar);
36nstd_create_mod_fn!(nstd_math_mod_short, c_short);
37nstd_create_mod_fn!(nstd_math_mod_int, c_int);
38nstd_create_mod_fn!(nstd_math_mod_long, c_long);
39nstd_create_mod_fn!(nstd_math_mod_longlong, c_longlong);
40
41/// Generates the max function.
42macro_rules! nstd_create_max_fn {
43    ($name: ident, $type: ty) => {
44        #[inline]
45        #[cfg_attr(feature = "clib", no_mangle)]
46        pub unsafe extern "C" fn $name(x: $type, y: $type) -> $type {
47            x.max(y)
48        }
49    };
50}
51nstd_create_max_fn!(nstd_math_max_float, c_float);
52nstd_create_max_fn!(nstd_math_max_double, c_double);
53nstd_create_max_fn!(nstd_math_max_schar, c_schar);
54nstd_create_max_fn!(nstd_math_max_short, c_short);
55nstd_create_max_fn!(nstd_math_max_int, c_int);
56nstd_create_max_fn!(nstd_math_max_long, c_long);
57nstd_create_max_fn!(nstd_math_max_longlong, c_longlong);
58
59/// Generates the min function.
60macro_rules! nstd_create_min_fn {
61    ($name: ident, $type: ty) => {
62        #[inline]
63        #[cfg_attr(feature = "clib", no_mangle)]
64        pub unsafe extern "C" fn $name(x: $type, y: $type) -> $type {
65            x.min(y)
66        }
67    };
68}
69nstd_create_min_fn!(nstd_math_min_float, c_float);
70nstd_create_min_fn!(nstd_math_min_double, c_double);
71nstd_create_min_fn!(nstd_math_min_schar, c_schar);
72nstd_create_min_fn!(nstd_math_min_short, c_short);
73nstd_create_min_fn!(nstd_math_min_int, c_int);
74nstd_create_min_fn!(nstd_math_min_long, c_long);
75nstd_create_min_fn!(nstd_math_min_longlong, c_longlong);
76
77/// Generates the powf function.
78macro_rules! nstd_create_powf_fn {
79    ($name: ident, $type: ty) => {
80        #[inline]
81        #[cfg_attr(feature = "clib", no_mangle)]
82        pub unsafe extern "C" fn $name(x: $type, y: $type) -> $type {
83            x.powf(y)
84        }
85    };
86}
87nstd_create_powf_fn!(nstd_math_pow_float, c_float);
88nstd_create_powf_fn!(nstd_math_pow_double, c_double);
89/// Generates the pow function.
90macro_rules! nstd_create_pow_fn {
91    ($name: ident, $type: ty) => {
92        #[inline]
93        #[cfg_attr(feature = "clib", no_mangle)]
94        pub unsafe extern "C" fn $name(x: $type, y: c_uint) -> $type {
95            x.wrapping_pow(y as u32)
96        }
97    };
98}
99nstd_create_pow_fn!(nstd_math_pow_schar, c_schar);
100nstd_create_pow_fn!(nstd_math_pow_short, c_short);
101nstd_create_pow_fn!(nstd_math_pow_int, c_int);
102nstd_create_pow_fn!(nstd_math_pow_long, c_long);
103nstd_create_pow_fn!(nstd_math_pow_longlong, c_longlong);
104
105/// Generates the sqrt function.
106macro_rules! nstd_create_sqrt_fn {
107    ($name: ident, $type: ty) => {
108        #[inline]
109        #[cfg_attr(feature = "clib", no_mangle)]
110        pub unsafe extern "C" fn $name(x: $type) -> $type {
111            x.sqrt()
112        }
113    };
114}
115nstd_create_sqrt_fn!(nstd_math_sqrt_float, c_float);
116nstd_create_sqrt_fn!(nstd_math_sqrt_double, c_double);
117
118/// Generates the cbrt function.
119macro_rules! nstd_create_cbrt_fn {
120    ($name: ident, $type: ty) => {
121        #[inline]
122        #[cfg_attr(feature = "clib", no_mangle)]
123        pub unsafe extern "C" fn $name(x: $type) -> $type {
124            x.cbrt()
125        }
126    };
127}
128nstd_create_cbrt_fn!(nstd_math_cbrt_float, c_float);
129nstd_create_cbrt_fn!(nstd_math_cbrt_double, c_double);
130
131/// Generates the sin function.
132macro_rules! nstd_create_sin_fn {
133    ($name: ident, $type: ty) => {
134        #[inline]
135        #[cfg_attr(feature = "clib", no_mangle)]
136        pub unsafe extern "C" fn $name(x: $type) -> $type {
137            x.sin()
138        }
139    };
140}
141nstd_create_sin_fn!(nstd_math_sin_float, c_float);
142nstd_create_sin_fn!(nstd_math_sin_double, c_double);
143
144/// Generates the cos function.
145macro_rules! nstd_create_cos_fn {
146    ($name: ident, $type: ty) => {
147        #[inline]
148        #[cfg_attr(feature = "clib", no_mangle)]
149        pub unsafe extern "C" fn $name(x: $type) -> $type {
150            x.cos()
151        }
152    };
153}
154nstd_create_cos_fn!(nstd_math_cos_float, c_float);
155nstd_create_cos_fn!(nstd_math_cos_double, c_double);
156
157/// Generates the tan function.
158macro_rules! nstd_create_tan_fn {
159    ($name: ident, $type: ty) => {
160        #[inline]
161        #[cfg_attr(feature = "clib", no_mangle)]
162        pub unsafe extern "C" fn $name(x: $type) -> $type {
163            x.tan()
164        }
165    };
166}
167nstd_create_tan_fn!(nstd_math_tan_float, c_float);
168nstd_create_tan_fn!(nstd_math_tan_double, c_double);
169
170/// Generates the ceil function.
171macro_rules! nstd_create_ceil_fn {
172    ($name: ident, $type: ty) => {
173        #[inline]
174        #[cfg_attr(feature = "clib", no_mangle)]
175        pub unsafe extern "C" fn $name(x: $type) -> $type {
176            x.ceil()
177        }
178    };
179}
180nstd_create_ceil_fn!(nstd_math_ceil_float, c_float);
181nstd_create_ceil_fn!(nstd_math_ceil_double, c_double);
182
183/// Generates the floor function.
184macro_rules! nstd_create_floor_fn {
185    ($name: ident, $type: ty) => {
186        #[inline]
187        #[cfg_attr(feature = "clib", no_mangle)]
188        pub unsafe extern "C" fn $name(x: $type) -> $type {
189            x.floor()
190        }
191    };
192}
193nstd_create_floor_fn!(nstd_math_floor_float, c_float);
194nstd_create_floor_fn!(nstd_math_floor_double, c_double);
195
196/// Generates the round function.
197macro_rules! nstd_create_round_fn {
198    ($name: ident, $type: ty) => {
199        #[inline]
200        #[cfg_attr(feature = "clib", no_mangle)]
201        pub unsafe extern "C" fn $name(x: $type) -> $type {
202            x.round()
203        }
204    };
205}
206nstd_create_round_fn!(nstd_math_round_float, c_float);
207nstd_create_round_fn!(nstd_math_round_double, c_double);