]> git.lizzy.rs Git - rust.git/blob - src/libcore/cmath.rs
Attempt to fix build breakage due to lgammaf_r having two leading underscores on...
[rust.git] / src / libcore / cmath.rs
1 export c_float;
2 export c_double;
3
4 // FIXME export c_float_math_consts;
5 // FIXME export c_double_math_consts;
6
7 export c_float_targ_consts;
8 export c_double_targ_consts;
9
10 import ctypes::c_int;
11 import ctypes::c_float;
12 import ctypes::c_double;
13
14 // function names are almost identical to C's libmath, a few have been
15 // renamed, grep for "rename:"
16
17 #[link_name = "m"]
18 #[abi = "cdecl"]
19 native mod c_double {
20
21     // Alpabetically sorted by link_name
22
23     pure fn acos(n: c_double) -> c_double;
24     pure fn asin(n: c_double) -> c_double;
25     pure fn atan(n: c_double) -> c_double;
26     pure fn atan2(a: c_double, b: c_double) -> c_double;
27     pure fn cbrt(n: c_double) -> c_double;
28     pure fn ceil(n: c_double) -> c_double;
29     pure fn copysign(x: c_double, y: c_double) -> c_double;
30     pure fn cos(n: c_double) -> c_double;
31     pure fn cosh(n: c_double) -> c_double;
32     pure fn erf(n: c_double) -> c_double;
33     pure fn erfc(n: c_double) -> c_double;
34     pure fn exp(n: c_double) -> c_double;
35     pure fn expm1(n: c_double) -> c_double;
36     pure fn exp2(n: c_double) -> c_double;
37     #[link_name="fabs"] pure fn abs(n: c_double) -> c_double;
38     // rename: for clarity and consistency with add/sub/mul/div
39     #[link_name="fdim"] pure fn abs_sub(a: c_double, b: c_double) -> c_double;
40     pure fn floor(n: c_double) -> c_double;
41     // rename: for clarity and consistency with add/sub/mul/div
42     #[link_name="fma"] pure fn mul_add(a: c_double, b: c_double,
43                                        c: c_double) -> c_double;
44     #[link_name="fmax"] pure fn fmax(a: c_double, b: c_double) -> c_double;
45     #[link_name="fmin"] pure fn fmin(a: c_double, b: c_double) -> c_double;
46     pure fn nextafter(x: c_double, y: c_double) -> c_double;
47     pure fn frexp(n: c_double, &value: c_int) -> c_double;
48     pure fn hypot(x: c_double, y: c_double) -> c_double;
49     pure fn ldexp(x: c_double, n: c_int) -> c_double;
50     #[link_name="lgamma_r"] pure fn lgamma(n: c_double,
51                                            &sign: c_int) -> c_double;
52     // renamed: log is a reserved keyword; ln seems more natural, too
53     #[link_name="log"] pure fn ln(n: c_double) -> c_double;
54     // renamed: "logb" /often/ is confused for log2 by beginners
55     #[link_name="logb"] pure fn log_radix(n: c_double) -> c_double;
56     // renamed: to be consitent with log as ln
57     #[link_name="log1p"] pure fn ln1p(n: c_double) -> c_double;
58     pure fn log10(n: c_double) -> c_double;
59     #[cfg(target_os="linux")]
60     #[cfg(target_os="macos")]
61     #[cfg(target_os="win32")]
62     pure fn log2(n: c_double) -> c_double;
63     #[link_name="ilogb"] pure fn ilog_radix(n: c_double) -> c_int;
64     pure fn modf(n: c_double, &iptr: c_double) -> c_double;
65     pure fn pow(n: c_double, e: c_double) -> c_double;
66 // FIXME enable when rounding modes become available
67 //    pure fn rint(n: c_double) -> c_double;
68     pure fn round(n: c_double) -> c_double;
69     // rename: for consistency with logradix
70     #[link_name="scalbn"] pure fn ldexp_radix(n: c_double, i: c_int) ->
71         c_double;
72     pure fn sin(n: c_double) -> c_double;
73     pure fn sinh(n: c_double) -> c_double;
74     pure fn sqrt(n: c_double) -> c_double;
75     pure fn tan(n: c_double) -> c_double;
76     pure fn tanh(n: c_double) -> c_double;
77     pure fn tgamma(n: c_double) -> c_double;
78     pure fn trunc(n: c_double) -> c_double;
79
80     // These are commonly only available for doubles
81
82     pure fn j0(n: c_double) -> c_double;
83     pure fn j1(n: c_double) -> c_double;
84     pure fn jn(i: c_int, n: c_double) -> c_double;
85
86     pure fn y0(n: c_double) -> c_double;
87     pure fn y1(n: c_double) -> c_double;
88     pure fn yn(i: c_int, n: c_double) -> c_double;
89 }
90
91 #[link_name = "m"]
92 #[abi = "cdecl"]
93 native mod c_float {
94
95     // Alpabetically sorted by link_name
96
97     #[link_name="acosf"] pure fn acos(n: c_float) -> c_float;
98     #[link_name="asinf"] pure fn asin(n: c_float) -> c_float;
99     #[link_name="atanf"] pure fn atan(n: c_float) -> c_float;
100     #[link_name="atan2f"] pure fn atan2(a: c_float, b: c_float) -> c_float;
101     #[link_name="cbrtf"] pure fn cbrt(n: c_float) -> c_float;
102     #[link_name="ceilf"] pure fn ceil(n: c_float) -> c_float;
103     #[link_name="copysignf"] pure fn copysign(x: c_float,
104                                               y: c_float) -> c_float;
105     #[link_name="cosf"] pure fn cos(n: c_float) -> c_float;
106     #[link_name="coshf"] pure fn cosh(n: c_float) -> c_float;
107     #[link_name="erff"] pure fn erf(n: c_float) -> c_float;
108     #[link_name="erfcf"] pure fn erfc(n: c_float) -> c_float;
109     #[link_name="expf"] pure fn exp(n: c_float) -> c_float;
110     #[link_name="expm1f"]pure fn expm1(n: c_float) -> c_float;
111     #[link_name="exp2f"] pure fn exp2(n: c_float) -> c_float;
112     #[link_name="fabsf"] pure fn abs(n: c_float) -> c_float;
113     #[link_name="fdimf"] pure fn abs_sub(a: c_float, b: c_float) -> c_float;
114     #[link_name="floorf"] pure fn floor(n: c_float) -> c_float;
115     #[link_name="frexpf"] pure fn frexp(n: c_float,
116                                         &value: c_int) -> c_float;
117     #[link_name="fmaf"] pure fn mul_add(a: c_float,
118                                         b: c_float, c: c_float) -> c_float;
119     #[link_name="fmaxf"] pure fn fmax(a: c_float, b: c_float) -> c_float;
120     #[link_name="fminf"] pure fn fmin(a: c_float, b: c_float) -> c_float;
121     #[link_name="nextafterf"] pure fn nextafter(x: c_float,
122                                                 y: c_float) -> c_float;
123     #[link_name="hypotf"] pure fn hypot(x: c_float, y: c_float) -> c_float;
124     #[link_name="ldexpf"] pure fn ldexp(x: c_float, n: c_int) -> c_float;
125
126     #[cfg(target_os="linux")]
127     #[cfg(target_os="macos")]
128     #[link_name="lgammaf_r"] pure fn lgamma(n: c_float,
129                                             &sign: c_int) -> c_float;
130
131     #[cfg(target_os="win32")]
132     #[link_name="__lgammaf_r"] pure fn lgamma(n: c_float,
133                                               &sign: c_int) -> c_float;
134
135     #[link_name="logf"] pure fn ln(n: c_float) -> c_float;
136     #[link_name="logbf"] pure fn log_radix(n: c_float) -> c_float;
137     #[link_name="log1pf"] pure fn ln1p(n: c_float) -> c_float;
138     #[cfg(target_os="linux")]
139     #[cfg(target_os="macos")]
140     #[cfg(target_os="win32")]
141     #[link_name="log2f"] pure fn log2(n: c_float) -> c_float;
142     #[link_name="log10f"] pure fn log10(n: c_float) -> c_float;
143     #[link_name="ilogbf"] pure fn ilog_radix(n: c_float) -> c_int;
144     #[link_name="modff"] pure fn modf(n: c_float,
145                                       &iptr: c_float) -> c_float;
146     #[link_name="powf"] pure fn pow(n: c_float, e: c_float) -> c_float;
147 // FIXME enable when rounding modes become available
148 //    #[link_name="rintf"] pure fn rint(n: c_float) -> c_float;
149     #[link_name="roundf"] pure fn round(n: c_float) -> c_float;
150     #[link_name="scalbnf"] pure fn ldexp_radix(n: c_float, i: c_int)
151         -> c_float;
152     #[link_name="sinf"] pure fn sin(n: c_float) -> c_float;
153     #[link_name="sinhf"] pure fn sinh(n: c_float) -> c_float;
154     #[link_name="sqrtf"] pure fn sqrt(n: c_float) -> c_float;
155     #[link_name="tanf"] pure fn tan(n: c_float) -> c_float;
156     #[link_name="tanhf"] pure fn tanh(n: c_float) -> c_float;
157     #[link_name="tgammaf"] pure fn tgamma(n: c_float) -> c_float;
158     #[link_name="truncf"] pure fn trunc(n: c_float) -> c_float;
159 }
160
161 // PORT check these by running src/etc/machconsts.c for your architecture
162
163 // FIXME obtain machine float/math constants automatically
164
165 mod c_float_targ_consts {
166     const radix: uint = 2u;
167     const mantissa_digits: uint = 24u;
168     const digits: uint = 6u;
169     const min_exp: uint = -125u;
170     const max_exp: uint = 128u;
171     const min_10_exp: int = -37;
172     const max_10_exp: int = 38;
173     // FIXME this is wrong! replace with hexadecimal (%a) constants below
174     const min_value: f32 = 1.175494e-38_f32;
175     const max_value: f32 = 3.402823e+38_f32;
176     const epsilon: f32 = 0.000000_f32;
177 }
178
179 mod c_double_targ_consts {
180     const radix: uint = 2u;
181     const mantissa_digits: uint = 53u;
182     const digits: uint = 15u;
183     const min_exp: uint = -1021u;
184     const max_exp: uint = 1024u;
185     const min_10_exp: int = -307;
186     const max_10_exp: int = 308;
187     // FIXME this is wrong! replace with hexadecimal (%a) constants below
188     const min_value: f64 = 2.225074e-308_f64;
189     const max_value: f64 = 1.797693e+308_f64;
190     const epsilon: f64 = 2.220446e-16_f64;
191 }
192
193 /*
194
195 FIXME use these once they can be parsed
196
197 mod c_float_math_consts {
198     const pi: c_float = 0x1.921fb6p+1_f32;
199     const div_1_pi: c_float = 0x1.45f306p-2_f32;
200     const div_2_pi: c_float = 0x1.45f306p-1_f32;
201     const div_pi_2: c_float = 0x1.921fb6p+0_f32;
202     const div_pi_4: c_float = 0x1.921fb6p-1_f32;
203     const div_2_sqrtpi: c_float = 0x1.20dd76p+0_f32;
204     const e: c_float = 0x1.5bf0a8p+1_f32;
205     const log2_e: c_float = 0x1.715476p+0_f32;
206     const log10_e: c_float = 0x1.bcb7b2p-2_f32;
207     const ln_2: c_float = 0x1.62e43p-1_f32;
208     const ln_10: c_float = 0x1.26bb1cp+1_f32;
209     const sqrt2: c_float = 0x1.6a09e6p+0_f32;
210     const div_1_sqrt2: c_float = 0x1.6a09e6p-1_f32;
211 }
212
213 mod c_double_math_consts {
214     const pi: c_double = 0x1.921fb54442d18p+1_f64;
215     const div_1_pi: c_double = 0x1.45f306dc9c883p-2_f64;
216     const div_2_pi: c_double = 0x1.45f306dc9c883p-1_f64;
217     const div_pi_2: c_double = 0x1.921fb54442d18p+0_f64;
218     const div_pi_4: c_double = 0x1.921fb54442d18p-1_f64;
219     const div_2_sqrtpi: c_double = 0x1.20dd750429b6dp+0_f64;
220     const e: c_double = 0x1.5bf0a8b145769p+1_f64;
221     const log2_e: c_double = 0x1.71547652b82fep+0_f64;
222     const log10_e: c_double = 0x1.bcb7b1526e50ep-2_f64;
223     const ln_2: c_double = 0x1.62e42fefa39efp-1_f64;
224     const ln_10: c_double = 0x1.26bb1bbb55516p+1_f64;
225     const sqrt2: c_double = 0x1.6a09e667f3bcdp+0_f64;
226     const div_1_sqrt2: c_double = 0x1.6a09e667f3bcdp-1_f64;
227 }
228
229 mod c_float_targ_consts {
230     const radix: uint = 2u;
231     const mantissa_digits: uint = 24u;
232     const digits: uint = 6u;
233     const min_exp: int = -125;
234     const max_exp: int = 128;
235     const min_10_exp: int = -37;
236     const max_10_exp: int = 38;
237     const min_value: c_float = 0x1p-126_f32;
238     const max_value: c_float = 0x1.fffffep+127_f32;
239     const epsilon: c_float = 0x1p-23_f32;
240 }
241
242 mod c_double_targ_consts {
243     const radix: uint = 2u;
244     const mantissa_digits: uint = 53u;
245     const digits: uint = 15u;
246     const min_exp: int = -1021;
247     const max_exp: int = 1024;
248     const min_10_exp: int = -307;
249     const max_10_exp: int = 308;
250     const min_value: c_double = 0x1p-1022_f64;
251     const max_value: c_double = 0x1.fffffffffffffp+1023_f64;
252     const epsilon: c_double = 0x1p-52_f64;
253 }
254
255 */
256
257 //
258 // Local Variables:
259 // mode: rust
260 // fill-column: 78;
261 // indent-tabs-mode: nil
262 // c-basic-offset: 4
263 // buffer-file-coding-system: utf-8-unix
264 // End:
265 //
266