1#[no_mangle]
12pub fn rint(x: f64) -> f64 {
13 let u = asuint64(x);
14 let e = ((u >> 52) & 0x7ff) as i32;
15 let s = u >> 63;
16
17 if e >= 0x3ff + 52 {
19 return x;
20 }
21
22 let toint = 4503599627370496.0f64;
24 let y = if s != 0 {
25 x - toint + toint
26 } else {
27 x + toint - toint
28 };
29
30 if y == 0.0 {
31 if s != 0 { -0.0 } else { 0.0 }
32 } else {
33 y
34 }
35}
36
37#[no_mangle]
39pub fn rintf(x: f32) -> f32 {
40 let u = asuint(x);
41 let e = ((u >> 23) & 0xff) as i32;
42 let s = u >> 31;
43
44 if e >= 0x7f + 23 {
46 return x;
47 }
48
49 let toint = 8388608.0f32;
51 let y = if s != 0 {
52 x - toint + toint
53 } else {
54 x + toint - toint
55 };
56
57 if y == 0.0 {
58 if s != 0 { -0.0f32 } else { 0.0f32 }
59 } else {
60 y
61 }
62}
63
64#[no_mangle]
71pub extern "C" fn lrint(x: f64) -> c_long {
72 rint(x) as c_long
73}
74
75#[no_mangle]
76pub extern "C" fn llrint(x: f64) -> c_longlong {
77 rint(x) as c_longlong
78}
79
80#[no_mangle]
81pub extern "C" fn lrintf(x: f32) -> c_long {
82 rintf(x) as c_long
83}
84
85#[no_mangle]
86pub extern "C" fn llrintf(x: f32) -> c_longlong {
87 rintf(x) as c_longlong
88}
89
90#[cfg(target_arch = "x86_64")]
93#[no_mangle]
94pub extern "C" fn lrintl(x: f64) -> c_long {
95 lrint(x)
96}
97
98#[cfg(target_arch = "x86_64")]
99#[no_mangle]
100pub extern "C" fn llrintl(x: f64) -> c_longlong {
101 llrint(x)
102}
103
104#[cfg(target_arch = "aarch64")]
105#[no_mangle]
106pub extern "C" fn lrintl(x: f128) -> c_long {
107 lrint(x as f64)
108}
109
110#[cfg(target_arch = "aarch64")]
111#[no_mangle]
112pub extern "C" fn llrintl(x: f128) -> c_longlong {
113 llrint(x as f64)
114}
115
116#[cfg(target_arch = "riscv64")]
117#[no_mangle]
118pub extern "C" fn lrintl(x: f128) -> c_long {
119 lrint(x as f64)
120}
121
122#[cfg(target_arch = "riscv64")]
123#[no_mangle]
124pub extern "C" fn llrintl(x: f128) -> c_longlong {
125 llrint(x as f64)
126}