]>
git.proxmox.com Git - rustc.git/blob - vendor/compiler_builtins/libm/src/math/remquo.rs
1 #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2 pub fn remquo(mut x
: f64, mut y
: f64) -> (f64, i32) {
3 let ux
: u64 = x
.to_bits();
4 let mut uy
: u64 = y
.to_bits();
5 let mut ex
= ((ux
>> 52) & 0x7ff) as i32;
6 let mut ey
= ((uy
>> 52) & 0x7ff) as i32;
7 let sx
= (ux
>> 63) != 0;
8 let sy
= (uy
>> 63) != 0;
11 let mut uxi
: u64 = ux
;
13 if (uy
<< 1) == 0 || y
.is_nan() || ex
== 0x7ff {
14 return ((x
* y
) / (x
* y
), 0);
20 /* normalize x and y */
23 while (i
>> 63) == 0 {
34 while (i
>> 63) == 0 {
52 i
= uxi
.wrapping_sub(uy
);
61 i
= uxi
.wrapping_sub(uy
);
69 while (uxi
>> 52) == 0 {
76 /* scale result and decide between |x| and |x|-|y| */
79 uxi
|= (ex
as u64) << 52;
83 x
= f64::from_bits(uxi
);
87 if ex
== ey
|| (ex
+ 1 == ey
&& (2.0 * x
> y
|| (2.0 * x
== y
&& (q
% 2) != 0))) {
89 // TODO: this matches musl behavior, but it is incorrect
90 q
= q
.wrapping_add(1);
93 let quo
= if sx ^ sy { -(q as i32) }
else { q as i32 }
;
106 fn test_q_overflow() {
107 // 0xc000000000000001, 0x04c0000000000004
108 let _
= remquo(-2.0000000000000004, 8.406091369059082e-286);