1#[inline]
9fn p2d(e: i32) -> f64 {
10 f64::from_bits(((0x3ff + e) as u64) << 52)
11}
12
13#[inline]
14fn p2f(e: i32) -> f32 {
15 f32::from_bits(((0x7f + e) as u32) << 23)
16}
17
18#[no_mangle]
19pub extern "C" fn fabs(x: f64) -> f64 {
20 libm::fabs(x)
21}
22
23#[no_mangle]
24pub extern "C" fn fabsf(x: f32) -> f32 {
25 libm::fabsf(x)
26}
27
28#[no_mangle]
29pub extern "C" fn copysign(x: f64, y: f64) -> f64 {
30 libm::copysign(x, y)
31}
32
33#[no_mangle]
34pub extern "C" fn copysignf(x: f32, y: f32) -> f32 {
35 libm::copysignf(x, y)
36}
37
38#[no_mangle]
39pub extern "C" fn trunc(x: f64) -> f64 {
40 libm::trunc(x)
41}
42
43#[no_mangle]
44pub extern "C" fn truncf(x: f32) -> f32 {
45 libm::truncf(x)
46}
47
48#[no_mangle]
49pub extern "C" fn floor(x: f64) -> f64 {
50 libm::floor(x)
51}
52
53#[no_mangle]
54pub extern "C" fn floorf(x: f32) -> f32 {
55 libm::floorf(x)
56}
57
58#[no_mangle]
59pub extern "C" fn ceil(x: f64) -> f64 {
60 libm::ceil(x)
61}
62
63#[no_mangle]
64pub extern "C" fn ceilf(x: f32) -> f32 {
65 libm::ceilf(x)
66}
67
68#[no_mangle]
69pub extern "C" fn round(x: f64) -> f64 {
70 let ix = x.to_bits();
71 let e = ((ix >> 52) & F64_EXP_MASK) as i32;
72 let mut ax = x;
73
74 if e >= F64_EXP_BIAS + 52 {
75 return x;
76 }
77 let neg = ix >> 63 != 0;
78 if neg {
79 ax = -ax;
80 }
81 if e < F64_EXP_BIAS - 1 {
82 force_eval(ax + p2d(52));
83 return 0.0 * x;
84 }
85 let y = ax + p2d(52) - p2d(52) - ax;
86 let y = if y > 0.5 {
87 y + ax - 1.0
88 } else if y <= -0.5 {
89 y + ax + 1.0
90 } else {
91 y + ax
92 };
93 if neg { -y } else { y }
94}
95
96#[no_mangle]
97pub extern "C" fn roundf(x: f32) -> f32 {
98 let ix = x.to_bits();
99 let e = ((ix >> 23) & F32_EXP_MASK as u32) as i32;
100 let mut ax = x;
101
102 if e >= F32_EXP_BIAS + 23 {
103 return x;
104 }
105 let neg = ix >> 31 != 0;
106 if neg {
107 ax = -ax;
108 }
109 if e < F32_EXP_BIAS - 1 {
110 force_eval(ax + p2f(23));
111 return 0.0f32 * x;
112 }
113 let y = ax + p2f(23) - p2f(23) - ax;
114 let y = if y > 0.5f32 {
115 y + ax - 1.0f32
116 } else if y <= -0.5f32 {
117 y + ax + 1.0f32
118 } else {
119 y + ax
120 };
121 if neg { -y } else { y }
122}
123
124#[no_mangle]
125pub extern "C" fn scalbn(x: f64, n: core::ffi::c_int) -> f64 {
126 libm::scalbn(x, n)
127}
128
129#[no_mangle]
130pub extern "C" fn scalbnf(x: f32, n: core::ffi::c_int) -> f32 {
131 libm::scalbnf(x, n)
132}
133
134#[no_mangle]
135pub extern "C" fn scalbln(x: f64, n: core::ffi::c_long) -> f64 {
136 let n = if n > core::ffi::c_int::MAX as core::ffi::c_long {
137 core::ffi::c_int::MAX
138 } else if n < core::ffi::c_int::MIN as core::ffi::c_long {
139 core::ffi::c_int::MIN
140 } else {
141 n as core::ffi::c_int
142 };
143 libm::scalbn(x, n)
144}
145
146#[no_mangle]
147pub extern "C" fn scalblnf(x: f32, n: core::ffi::c_long) -> f32 {
148 let n = if n > core::ffi::c_int::MAX as core::ffi::c_long {
149 core::ffi::c_int::MAX
150 } else if n < core::ffi::c_int::MIN as core::ffi::c_long {
151 core::ffi::c_int::MIN
152 } else {
153 n as core::ffi::c_int
154 };
155 libm::scalbnf(x, n)
156}
157
158#[no_mangle]
159pub extern "C" fn ldexp(x: f64, n: core::ffi::c_int) -> f64 {
160 libm::scalbn(x, n)
161}
162
163#[no_mangle]
164pub extern "C" fn ldexpf(x: f32, n: core::ffi::c_int) -> f32 {
165 libm::scalbnf(x, n)
166}
167
168#[no_mangle]
169pub unsafe extern "C" fn frexp(x: f64, e: *mut core::ffi::c_int) -> f64 {
170 let (r, exp) = libm::frexp(x);
171 if !e.is_null() { *e = exp; }
172 r
173}
174
175#[no_mangle]
176pub unsafe extern "C" fn frexpf(x: f32, e: *mut core::ffi::c_int) -> f32 {
177 let (r, exp) = libm::frexpf(x);
178 if !e.is_null() { *e = exp; }
179 r
180}
181
182#[no_mangle]
183pub unsafe extern "C" fn modf(x: f64, iptr: *mut f64) -> f64 {
184 let (frac, int) = libm::modf(x);
185 if !iptr.is_null() { *iptr = int; }
186 frac
187}
188
189#[no_mangle]
190pub unsafe extern "C" fn modff(x: f32, iptr: *mut f32) -> f32 {
191 let (frac, int) = libm::modff(x);
192 if !iptr.is_null() { *iptr = int; }
193 frac
194}