Skip to content

Commit 080f6f2

Browse files
committed
Comment the i32::MIN case for FloatCore::powi
1 parent aa9ceba commit 080f6f2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/float.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::num::FpCategory;
55
use core::f32;
66
use core::f64;
77

8-
use {Num, NumCast};
8+
use {Num, NumCast, ToPrimitive};
99

1010
/// Generic trait for floating point numbers that works with `no_std`.
1111
///
@@ -668,7 +668,9 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
668668
self = self.recip();
669669
}
670670
// It should always be possible to convert a positive `i32` to a `usize`.
671-
super::pow(self, exp as u32 as usize)
671+
// Note, `i32::MIN` will wrap and still be negative, so we need to convert
672+
// to `u32` without sign-extension before growing to `usize`.
673+
super::pow(self, (exp as u32).to_usize().unwrap())
672674
}
673675

674676
/// Converts to degrees, assuming the number is in radians.

0 commit comments

Comments
 (0)