|
| 1 | +export c_double; |
| 2 | +export c_float; |
| 3 | + |
1 | 4 | import ctypes::c_int;
|
| 5 | +import ctypes::c_float; |
| 6 | +import ctypes::c_double; |
| 7 | + |
| 8 | +// function names are almost identical to C's libmath, a few have been |
| 9 | +// renamed, grep for "rename:" |
2 | 10 |
|
3 | 11 | #[link_name = "m"]
|
4 | 12 | #[abi = "cdecl"]
|
5 |
| -native mod f64 { |
| 13 | +native mod c_double { |
6 | 14 |
|
7 | 15 | // Alpabetically sorted by link_name
|
8 | 16 |
|
9 |
| - pure fn acos(n: f64) -> f64; |
10 |
| - pure fn asin(n: f64) -> f64; |
11 |
| - pure fn atan(n: f64) -> f64; |
12 |
| - pure fn atan2(a: f64, b: f64) -> f64; |
13 |
| - pure fn ceil(n: f64) -> f64; |
14 |
| - pure fn cos(n: f64) -> f64; |
15 |
| - pure fn cosh(n: f64) -> f64; |
16 |
| - pure fn exp(n: f64) -> f64; |
17 |
| - #[link_name="fabs"] pure fn abs(n: f64) -> f64; |
18 |
| - pure fn floor(n: f64) -> f64; |
19 |
| - pure fn fmod(x: f64, y: f64) -> f64; |
20 |
| - pure fn frexp(n: f64, &value: c_int) -> f64; |
21 |
| - pure fn ldexp(x: f64, n: c_int) -> f64; |
22 |
| - #[link_name="log"] pure fn ln(n: f64) -> f64; |
23 |
| - #[link_name="log1p"] pure fn ln1p(n: f64) -> f64; |
24 |
| - pure fn log10(n: f64) -> f64; |
| 17 | + pure fn acos(n: c_double) -> c_double; |
| 18 | + pure fn asin(n: c_double) -> c_double; |
| 19 | + pure fn atan(n: c_double) -> c_double; |
| 20 | + pure fn atan2(a: c_double, b: c_double) -> c_double; |
| 21 | + pure fn cbrt(n: c_double) -> c_double; |
| 22 | + pure fn ceil(n: c_double) -> c_double; |
| 23 | + pure fn copysign(x: c_double, y: c_double) -> c_double; |
| 24 | + pure fn cos(n: c_double) -> c_double; |
| 25 | + pure fn cosh(n: c_double) -> c_double; |
| 26 | + pure fn erf(n: c_double) -> c_double; |
| 27 | + pure fn erfc(n: c_double) -> c_double; |
| 28 | + pure fn exp(n: c_double) -> c_double; |
| 29 | + pure fn expm1(n: c_double) -> c_double; |
| 30 | + pure fn exp2(n: c_double) -> c_double; |
| 31 | + #[link_name="fabs"] pure fn abs(n: c_double) -> c_double; |
| 32 | + // rename: for clarity and consistency with add/sub/mul/div |
| 33 | + #[link_name="fdim"] pure fn abs_sub(a: c_double, b: c_double) -> c_double; |
| 34 | + pure fn floor(n: c_double) -> c_double; |
| 35 | + // rename: for clarity and consistency with add/sub/mul/div |
| 36 | + #[link_name="fma"] pure fn mul_add(a: c_double, b: c_double, |
| 37 | + c: c_double) -> c_double; |
| 38 | + #[link_name="fmax"] pure fn fmax(a: c_double, b: c_double) -> c_double; |
| 39 | + #[link_name="fmin"] pure fn fmin(a: c_double, b: c_double) -> c_double; |
| 40 | + pure fn nextafter(x: c_double, y: c_double) -> c_double; |
| 41 | + pure fn frexp(n: c_double, &value: c_int) -> c_double; |
| 42 | + pure fn hypot(x: c_double, y: c_double) -> c_double; |
| 43 | + pure fn ldexp(x: c_double, n: c_int) -> c_double; |
| 44 | + #[link_name="lgamma_r"] pure fn lgamma(n: c_double, |
| 45 | + &sign: c_int) -> c_double; |
| 46 | + // renamed: log is a reserved keyword; ln seems more natural, too |
| 47 | + #[link_name="log"] pure fn ln(n: c_double) -> c_double; |
| 48 | + // renamed: "logb" /often/ is confused for log2 by beginners |
| 49 | + #[link_name="logb"] pure fn log_radix(n: c_double) -> c_double; |
| 50 | + // renamed: to be consitent with log as ln |
| 51 | + #[link_name="log1p"] pure fn ln1p(n: c_double) -> c_double; |
| 52 | + pure fn log10(n: c_double) -> c_double; |
25 | 53 | #[cfg(target_os="linux")]
|
26 | 54 | #[cfg(target_os="macos")]
|
27 | 55 | #[cfg(target_os="win32")]
|
28 |
| - pure fn log2(n: f64) -> f64; |
29 |
| - pure fn modf(n: f64, iptr: *f64) -> f64; |
30 |
| - pure fn pow(n: f64, e: f64) -> f64; |
31 |
| - pure fn rint(n: f64) -> f64; |
32 |
| - pure fn round(n: f64) -> f64; |
33 |
| - pure fn sin(n: f64) -> f64; |
34 |
| - pure fn sinh(n: f64) -> f64; |
35 |
| - pure fn sqrt(n: f64) -> f64; |
36 |
| - pure fn tan(n: f64) -> f64; |
37 |
| - pure fn tanh(n: f64) -> f64; |
38 |
| - pure fn trunc(n: f64) -> f64; |
| 56 | + pure fn log2(n: c_double) -> c_double; |
| 57 | + #[link_name="ilogb"] pure fn ilogradix(n: c_double) -> c_int; |
| 58 | + pure fn modf(n: c_double, &iptr: c_double) -> c_double; |
| 59 | + pure fn pow(n: c_double, e: c_double) -> c_double; |
| 60 | +// FIXME enable when rounding modes become available |
| 61 | +// pure fn rint(n: c_double) -> c_double; |
| 62 | + pure fn round(n: c_double) -> c_double; |
| 63 | + // rename: for consistency with logradix |
| 64 | + #[link_name="scalbn"] pure fn ldexp_radix(n: c_double, i: c_int) -> |
| 65 | + c_double; |
| 66 | + pure fn sin(n: c_double) -> c_double; |
| 67 | + pure fn sinh(n: c_double) -> c_double; |
| 68 | + pure fn sqrt(n: c_double) -> c_double; |
| 69 | + pure fn tan(n: c_double) -> c_double; |
| 70 | + pure fn tanh(n: c_double) -> c_double; |
| 71 | + pure fn tgamma(n: c_double) -> c_double; |
| 72 | + pure fn trunc(n: c_double) -> c_double; |
| 73 | + |
| 74 | + // These are commonly only available for doubles |
| 75 | + |
| 76 | + pure fn j0(n: c_double) -> c_double; |
| 77 | + pure fn j1(n: c_double) -> c_double; |
| 78 | + pure fn jn(i: c_int, n: c_double) -> c_double; |
| 79 | + |
| 80 | + pure fn y0(n: c_double) -> c_double; |
| 81 | + pure fn y1(n: c_double) -> c_double; |
| 82 | + pure fn yn(i: c_int, n: c_double) -> c_double; |
39 | 83 | }
|
40 | 84 |
|
41 | 85 | #[link_name = "m"]
|
42 | 86 | #[abi = "cdecl"]
|
43 |
| -native mod f32 { |
| 87 | +native mod c_float { |
44 | 88 |
|
45 | 89 | // Alpabetically sorted by link_name
|
46 | 90 |
|
47 |
| - #[link_name="acosf"] pure fn acos(n: f32) -> f32; |
48 |
| - #[link_name="asinf"] pure fn asin(n: f32) -> f32; |
49 |
| - #[link_name="atanf"] pure fn atan(n: f32) -> f32; |
50 |
| - #[link_name="atan2f"] pure fn atan2(a: f32, b: f32) -> f32; |
51 |
| - #[link_name="ceilf"] pure fn ceil(n: f32) -> f32; |
52 |
| - #[link_name="cosf"] pure fn cos(n: f32) -> f32; |
53 |
| - #[link_name="coshf"] pure fn cosh(n: f32) -> f32; |
54 |
| - #[link_name="expf"] pure fn exp(n: f32) -> f32; |
55 |
| - #[link_name="fabsf"] pure fn abs(n: f32) -> f32; |
56 |
| - #[link_name="floorf"] pure fn floor(n: f32) -> f32; |
57 |
| - #[link_name="frexpf"] pure fn frexp(n: f64, &value: c_int) -> f32; |
58 |
| - #[link_name="fmodf"] pure fn fmod(x: f32, y: f32) -> f32; |
59 |
| - #[link_name="ldexpf"] pure fn ldexp(x: f32, n: c_int) -> f32; |
60 |
| - #[link_name="logf"] pure fn ln(n: f32) -> f32; |
61 |
| - #[link_name="log1p"] pure fn ln1p(n: f64) -> f64; |
| 91 | + #[link_name="acosf"] pure fn acos(n: c_float) -> c_float; |
| 92 | + #[link_name="asinf"] pure fn asin(n: c_float) -> c_float; |
| 93 | + #[link_name="atanf"] pure fn atan(n: c_float) -> c_float; |
| 94 | + #[link_name="atan2f"] pure fn atan2(a: c_float, b: c_float) -> c_float; |
| 95 | + #[link_name="cbrtf"] pure fn cbrt(n: c_float) -> c_float; |
| 96 | + #[link_name="ceilf"] pure fn ceil(n: c_float) -> c_float; |
| 97 | + #[link_name="copysignf"] pure fn copysign(x: c_float, |
| 98 | + y: c_float) -> c_float; |
| 99 | + #[link_name="cosf"] pure fn cos(n: c_float) -> c_float; |
| 100 | + #[link_name="coshf"] pure fn cosh(n: c_float) -> c_float; |
| 101 | + #[link_name="erff"] pure fn erf(n: c_float) -> c_float; |
| 102 | + #[link_name="erfcf"] pure fn erfc(n: c_float) -> c_float; |
| 103 | + #[link_name="expf"] pure fn exp(n: c_float) -> c_float; |
| 104 | + #[link_name="expm1f"]pure fn expm1(n: c_float) -> c_float; |
| 105 | + #[link_name="exp2f"] pure fn exp2(n: c_float) -> c_float; |
| 106 | + #[link_name="fabsf"] pure fn abs(n: c_float) -> c_float; |
| 107 | + #[link_name="fdimf"] pure fn abs_sub(a: c_float, b: c_float) -> c_float; |
| 108 | + #[link_name="floorf"] pure fn floor(n: c_float) -> c_float; |
| 109 | + #[link_name="frexpf"] pure fn frexp(n: c_float, |
| 110 | + &value: c_int) -> c_float; |
| 111 | + #[link_name="fmaf"] pure fn mul_add(a: c_float, |
| 112 | + b: c_float, c: c_float) -> c_float; |
| 113 | + #[link_name="fmaxf"] pure fn fmax(a: c_float, b: c_float) -> c_float; |
| 114 | + #[link_name="fminf"] pure fn fmin(a: c_float, b: c_float) -> c_float; |
| 115 | + #[link_name="nextafterf"] pure fn nextafter(x: c_float, |
| 116 | + y: c_float) -> c_float; |
| 117 | + #[link_name="hypotf"] pure fn hypot(x: c_float, y: c_float) -> c_float; |
| 118 | + #[link_name="ldexpf"] pure fn ldexp(x: c_float, n: c_int) -> c_float; |
| 119 | + #[link_name="lgammaf_r"] pure fn lgamma(n: c_float, |
| 120 | + &sign: c_int) -> c_float; |
| 121 | + #[link_name="logf"] pure fn ln(n: c_float) -> c_float; |
| 122 | + #[link_name="logbf"] pure fn log_radix(n: c_float) -> c_float; |
| 123 | + #[link_name="log1pf"] pure fn ln1p(n: c_float) -> c_float; |
62 | 124 | #[cfg(target_os="linux")]
|
63 | 125 | #[cfg(target_os="macos")]
|
64 | 126 | #[cfg(target_os="win32")]
|
65 |
| - #[link_name="log2f"] pure fn log2(n: f32) -> f32; |
66 |
| - #[link_name="log10f"] pure fn log10(n: f32) -> f32; |
67 |
| - #[link_name="modff"] pure fn modf(n: f32, iptr: *f32) -> f32; |
68 |
| - #[link_name="powf"] pure fn pow(n: f32, e: f32) -> f32; |
69 |
| - #[link_name="rintf"] pure fn rint(n: f32) -> f32; |
70 |
| - #[link_name="roundf"] pure fn round(n: f32) -> f32; |
71 |
| - #[link_name="sinf"] pure fn sin(n: f32) -> f32; |
72 |
| - #[link_name="sinhf"] pure fn sinh(n: f32) -> f32; |
73 |
| - #[link_name="sqrtf"] pure fn sqrt(n: f32) -> f32; |
74 |
| - #[link_name="tanf"] pure fn tan(n: f32) -> f32; |
75 |
| - #[link_name="tanhf"] pure fn tanh(n: f32) -> f32; |
76 |
| - #[link_name="truncf"] pure fn trunc(n: f32) -> f32; |
| 127 | + #[link_name="log2f"] pure fn log2(n: c_float) -> c_float; |
| 128 | + #[link_name="log10f"] pure fn log10(n: c_float) -> c_float; |
| 129 | + #[link_name="ilogbf"] pure fn ilog_radix(n: c_float) -> c_int; |
| 130 | + #[link_name="modff"] pure fn modf(n: c_float, |
| 131 | + &iptr: c_float) -> c_float; |
| 132 | + #[link_name="powf"] pure fn pow(n: c_float, e: c_float) -> c_float; |
| 133 | +// FIXME enable when rounding modes become available |
| 134 | +// #[link_name="rintf"] pure fn rint(n: c_float) -> c_float; |
| 135 | + #[link_name="roundf"] pure fn round(n: c_float) -> c_float; |
| 136 | + #[link_name="scalbnf"] pure fn ldexp_radix(n: c_float, i: c_int) -> c_float; |
| 137 | + #[link_name="sinf"] pure fn sin(n: c_float) -> c_float; |
| 138 | + #[link_name="sinhf"] pure fn sinh(n: c_float) -> c_float; |
| 139 | + #[link_name="sqrtf"] pure fn sqrt(n: c_float) -> c_float; |
| 140 | + #[link_name="tanf"] pure fn tan(n: c_float) -> c_float; |
| 141 | + #[link_name="tanhf"] pure fn tanh(n: c_float) -> c_float; |
| 142 | + #[link_name="tgammaf"] pure fn tgamma(n: c_float) -> c_float; |
| 143 | + #[link_name="truncf"] pure fn trunc(n: c_float) -> c_float; |
77 | 144 | }
|
78 | 145 |
|
79 | 146 | //
|
|
0 commit comments