Skip to content

Commit 5bfb5ba

Browse files
committed
Allow Float::ldexp to be called as a method
Fixes #22098.
1 parent 46f649c commit 5bfb5ba

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/libstd/num/f32.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ impl Float for f32 {
191191
/// Constructs a floating point number by multiplying `x` by 2 raised to the
192192
/// power of `exp`
193193
#[inline]
194-
fn ldexp(x: f32, exp: int) -> f32 {
195-
unsafe { cmath::ldexpf(x, exp as c_int) }
194+
fn ldexp(self, exp: isize) -> f32 {
195+
unsafe { cmath::ldexpf(self, exp as c_int) }
196196
}
197197

198198
/// Breaks the number into a normalized fraction and a base-2 exponent,
@@ -2208,8 +2208,8 @@ mod tests {
22082208
let f1: f32 = FromStrRadix::from_str_radix("1p-123", 16).unwrap();
22092209
let f2: f32 = FromStrRadix::from_str_radix("1p-111", 16).unwrap();
22102210
let f3: f32 = FromStrRadix::from_str_radix("1.Cp-12", 16).unwrap();
2211-
assert_eq!(Float::ldexp(1f32, -123), f1);
2212-
assert_eq!(Float::ldexp(1f32, -111), f2);
2211+
assert_eq!(1f32.ldexp(-123), f1);
2212+
assert_eq!(1f32.ldexp(-111), f2);
22132213
assert_eq!(Float::ldexp(1.75f32, -12), f3);
22142214

22152215
assert_eq!(Float::ldexp(0f32, -123), 0f32);

src/libstd/num/f64.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ impl Float for f64 {
200200
fn to_radians(self) -> f64 { num::Float::to_radians(self) }
201201

202202
#[inline]
203-
fn ldexp(x: f64, exp: int) -> f64 {
204-
unsafe { cmath::ldexp(x, exp as c_int) }
203+
fn ldexp(self, exp: isize) -> f64 {
204+
unsafe { cmath::ldexp(self, exp as c_int) }
205205
}
206206

207207
/// Breaks the number into a normalized fraction and a base-2 exponent,
@@ -2215,8 +2215,8 @@ mod tests {
22152215
let f1: f64 = FromStrRadix::from_str_radix("1p-123", 16).unwrap();
22162216
let f2: f64 = FromStrRadix::from_str_radix("1p-111", 16).unwrap();
22172217
let f3: f64 = FromStrRadix::from_str_radix("1.Cp-12", 16).unwrap();
2218-
assert_eq!(Float::ldexp(1f64, -123), f1);
2219-
assert_eq!(Float::ldexp(1f64, -111), f2);
2218+
assert_eq!(1f64.ldexp(-123), f1);
2219+
assert_eq!(1f64.ldexp(-111), f2);
22202220
assert_eq!(Float::ldexp(1.75f64, -12), f3);
22212221

22222222
assert_eq!(Float::ldexp(0f64, -123), 0f64);

src/libstd/num/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ pub trait Float
702702
/// ```
703703
#[unstable(feature = "std_misc",
704704
reason = "pending integer conventions")]
705-
fn ldexp(x: Self, exp: isize) -> Self;
705+
fn ldexp(self, exp: isize) -> Self;
706706
/// Breaks the number into a normalized fraction and a base-2 exponent,
707707
/// satisfying:
708708
///

0 commit comments

Comments
 (0)