Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 67f2865

Browse files
committed
Cleanup
1 parent 1d98742 commit 67f2865

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/math/generic/fma.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
11
use super::super::fenv::{FE_TONEAREST, fegetround};
2-
use super::super::{CastFrom, CastInto, DFloat, Float, HFloat, Int, IntTy, MinInt};
2+
use super::super::{CastFrom, CastInto, DFloat, Float, HFloat, IntTy, MinInt};
33

44
/// FMA implementation when a hardware-backed larger float type is available.
55
pub fn fma_big<F, B>(x: F, y: F, z: F) -> F
66
where
77
F: Float + HFloat<D = B>,
88
B: Float + DFloat<H = F>,
9-
// F: Float + CastInto<B>,
10-
// B: Float + CastInto<F> + CastFrom<F>,
119
B::Int: CastInto<i32>,
1210
i32: CastFrom<i32>,
1311
{
1412
let one = IntTy::<B>::ONE;
1513

16-
let xy: B;
17-
let result: B;
18-
let mut ui: B::Int;
19-
let e: i32;
20-
21-
xy = x.widen() * y.widen();
22-
result = xy + z.widen();
23-
ui = result.to_bits();
24-
e = result.exp().signed();
14+
let xy: B = x.widen() * y.widen();
15+
let result: B = xy + z.widen();
16+
let mut ui: B::Int = result.to_bits();
17+
let re = result.exp();
2518
let zb: B = z.widen();
2619

2720
let prec_diff = B::SIG_BITS - F::SIG_BITS;
2821
let excess_prec = ui & ((one << prec_diff) - one);
29-
let x = one << (prec_diff - 1);
30-
31-
// Common case: the larger precision is fine
32-
if excess_prec != x
33-
|| e == i32::cast_from(F::EXP_MAX)
22+
let halfway = one << (prec_diff - 1);
23+
24+
// Common case: the larger precision is fine if...
25+
// This is not a halfway case
26+
if excess_prec != halfway
27+
// Or the result is NaN
28+
|| re == B::EXP_MAX
29+
// Or the result is exact
3430
|| (result - xy == zb && result - zb == xy)
31+
// Or the mode is something other than round to nearest
3532
|| fegetround() != FE_TONEAREST
3633
{
3734
// TODO: feclearexcept

0 commit comments

Comments
 (0)