Skip to content

Commit 5b44b47

Browse files
authored
remove uses of Ord::clamp in scalbn (#1047)
Avoid using `Ord::clamp` in the `f16`-specific part of the generic `scalbn`. It turned out to be redundant anyway, as both callsites follow a pattern like ``` if n < negative_val { let foo = (n + positive_val).clamp(negative_val, positive_val); } ``` and `n < negative_val < 0` implies `n + positive_val < positive_val`. Fixes: #1046
1 parent 13f972f commit 5b44b47

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

libm/src/math/generic/scalbn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ where
9696
// Work aroudn this by using a different algorithm that calculates the prescale
9797
// dynamically based on the maximum possible value. This adds more operations per round
9898
// since it needs to construct the scale, but works better in the general case.
99-
let add = -(n + sig_total_bits as i32).clamp(exp_min, sig_total_bits as i32);
99+
let add = -(n + sig_total_bits as i32).max(exp_min);
100100
let mul = F::from_parts(false, (F::EXP_BIAS as i32 - add) as u32, zero);
101101

102102
x *= mul;
103103
n += add;
104104

105105
if n < exp_min {
106-
let add = -(n + sig_total_bits as i32).clamp(exp_min, sig_total_bits as i32);
106+
let add = -(n + sig_total_bits as i32).max(exp_min);
107107
let mul = F::from_parts(false, (F::EXP_BIAS as i32 - add) as u32, zero);
108108

109109
x *= mul;

0 commit comments

Comments
 (0)