Skip to content

Commit 4c0ffc0

Browse files
committed
Auto merge of #27823 - eefriedman:float-dep-core, r=alexcrichton
There wasn't any particular reason the functions needed to be there anyway, so just get rid of them, and adjust libstd to compensate. With this change, libcore depends on exactly two floating-point functions: fmod and fmodf. They are implicitly referenced because they are used to implement "%". Dependencies of libcore on Linux x86-x64 with this patch: ``` 0000000000000000 *UND* 0000000000000000 __powidf2 0000000000000000 *UND* 0000000000000000 __powisf2 0000000000000000 *UND* 0000000000000000 fmod 0000000000000000 *UND* 0000000000000000 fmodf 0000000000000000 *UND* 0000000000000000 memcmp 0000000000000000 *UND* 0000000000000000 memcpy 0000000000000000 *UND* 0000000000000000 memset 0000000000000000 *UND* 0000000000000000 rust_begin_unwind 0000000000000000 *UND* 0000000000000000 rust_eh_personality ```
2 parents de67d62 + 1ddee80 commit 4c0ffc0

File tree

15 files changed

+194
-318
lines changed

15 files changed

+194
-318
lines changed

src/libcore/num/f32.rs

-140
Original file line numberDiff line numberDiff line change
@@ -216,63 +216,6 @@ impl Float for f32 {
216216
(mantissa as u64, exponent, sign)
217217
}
218218

219-
/// Rounds towards minus infinity.
220-
#[inline]
221-
fn floor(self) -> f32 {
222-
return floorf(self);
223-
224-
// On MSVC LLVM will lower many math intrinsics to a call to the
225-
// corresponding function. On MSVC, however, many of these functions
226-
// aren't actually available as symbols to call, but rather they are all
227-
// `static inline` functions in header files. This means that from a C
228-
// perspective it's "compatible", but not so much from an ABI
229-
// perspective (which we're worried about).
230-
//
231-
// The inline header functions always just cast to a f64 and do their
232-
// operation, so we do that here as well, but only for MSVC targets.
233-
//
234-
// Note that there are many MSVC-specific float operations which
235-
// redirect to this comment, so `floorf` is just one case of a missing
236-
// function on MSVC, but there are many others elsewhere.
237-
#[cfg(target_env = "msvc")]
238-
fn floorf(f: f32) -> f32 { (f as f64).floor() as f32 }
239-
#[cfg(not(target_env = "msvc"))]
240-
fn floorf(f: f32) -> f32 { unsafe { intrinsics::floorf32(f) } }
241-
}
242-
243-
/// Rounds towards plus infinity.
244-
#[inline]
245-
fn ceil(self) -> f32 {
246-
return ceilf(self);
247-
248-
// see notes above in `floor`
249-
#[cfg(target_env = "msvc")]
250-
fn ceilf(f: f32) -> f32 { (f as f64).ceil() as f32 }
251-
#[cfg(not(target_env = "msvc"))]
252-
fn ceilf(f: f32) -> f32 { unsafe { intrinsics::ceilf32(f) } }
253-
}
254-
255-
/// Rounds to nearest integer. Rounds half-way cases away from zero.
256-
#[inline]
257-
fn round(self) -> f32 {
258-
unsafe { intrinsics::roundf32(self) }
259-
}
260-
261-
/// Returns the integer part of the number (rounds towards zero).
262-
#[inline]
263-
fn trunc(self) -> f32 {
264-
unsafe { intrinsics::truncf32(self) }
265-
}
266-
267-
/// The fractional part of the number, satisfying:
268-
///
269-
/// ```
270-
/// let x = 1.65f32;
271-
/// assert!(x == x.trunc() + x.fract())
272-
/// ```
273-
#[inline]
274-
fn fract(self) -> f32 { self - self.trunc() }
275-
276219
/// Computes the absolute value of `self`. Returns `Float::nan()` if the
277220
/// number is `Float::nan()`.
278221
#[inline]
@@ -308,14 +251,6 @@ impl Float for f32 {
308251
self < 0.0 || (1.0 / self) == Float::neg_infinity()
309252
}
310253

311-
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
312-
/// error. This produces a more accurate result with better performance than
313-
/// a separate multiplication operation followed by an add.
314-
#[inline]
315-
fn mul_add(self, a: f32, b: f32) -> f32 {
316-
unsafe { intrinsics::fmaf32(self, a, b) }
317-
}
318-
319254
/// Returns the reciprocal (multiplicative inverse) of the number.
320255
#[inline]
321256
fn recip(self) -> f32 { 1.0 / self }
@@ -325,81 +260,6 @@ impl Float for f32 {
325260
unsafe { intrinsics::powif32(self, n) }
326261
}
327262

328-
#[inline]
329-
fn powf(self, n: f32) -> f32 {
330-
return powf(self, n);
331-
332-
// see notes above in `floor`
333-
#[cfg(target_env = "msvc")]
334-
fn powf(f: f32, n: f32) -> f32 { (f as f64).powf(n as f64) as f32 }
335-
#[cfg(not(target_env = "msvc"))]
336-
fn powf(f: f32, n: f32) -> f32 { unsafe { intrinsics::powf32(f, n) } }
337-
}
338-
339-
#[inline]
340-
fn sqrt(self) -> f32 {
341-
if self < 0.0 {
342-
NAN
343-
} else {
344-
unsafe { intrinsics::sqrtf32(self) }
345-
}
346-
}
347-
348-
#[inline]
349-
fn rsqrt(self) -> f32 { self.sqrt().recip() }
350-
351-
/// Returns the exponential of the number.
352-
#[inline]
353-
fn exp(self) -> f32 {
354-
return expf(self);
355-
356-
// see notes above in `floor`
357-
#[cfg(target_env = "msvc")]
358-
fn expf(f: f32) -> f32 { (f as f64).exp() as f32 }
359-
#[cfg(not(target_env = "msvc"))]
360-
fn expf(f: f32) -> f32 { unsafe { intrinsics::expf32(f) } }
361-
}
362-
363-
/// Returns 2 raised to the power of the number.
364-
#[inline]
365-
fn exp2(self) -> f32 {
366-
unsafe { intrinsics::exp2f32(self) }
367-
}
368-
369-
/// Returns the natural logarithm of the number.
370-
#[inline]
371-
fn ln(self) -> f32 {
372-
return logf(self);
373-
374-
// see notes above in `floor`
375-
#[cfg(target_env = "msvc")]
376-
fn logf(f: f32) -> f32 { (f as f64).ln() as f32 }
377-
#[cfg(not(target_env = "msvc"))]
378-
fn logf(f: f32) -> f32 { unsafe { intrinsics::logf32(f) } }
379-
}
380-
381-
/// Returns the logarithm of the number with respect to an arbitrary base.
382-
#[inline]
383-
fn log(self, base: f32) -> f32 { self.ln() / base.ln() }
384-
385-
/// Returns the base 2 logarithm of the number.
386-
#[inline]
387-
fn log2(self) -> f32 {
388-
unsafe { intrinsics::log2f32(self) }
389-
}
390-
391-
/// Returns the base 10 logarithm of the number.
392-
#[inline]
393-
fn log10(self) -> f32 {
394-
return log10f(self);
395-
396-
// see notes above in `floor`
397-
#[cfg(target_env = "msvc")]
398-
fn log10f(f: f32) -> f32 { (f as f64).log10() as f32 }
399-
#[cfg(not(target_env = "msvc"))]
400-
fn log10f(f: f32) -> f32 { unsafe { intrinsics::log10f32(f) } }
401-
}
402-
403263
/// Converts to degrees, assuming the number is in radians.
404264
#[inline]
405265
fn to_degrees(self) -> f32 { self * (180.0f32 / consts::PI) }

src/libcore/num/f64.rs

-92
Original file line numberDiff line numberDiff line change
@@ -216,39 +216,6 @@ impl Float for f64 {
216216
(mantissa, exponent, sign)
217217
}
218218

219-
/// Rounds towards minus infinity.
220-
#[inline]
221-
fn floor(self) -> f64 {
222-
unsafe { intrinsics::floorf64(self) }
223-
}
224-
225-
/// Rounds towards plus infinity.
226-
#[inline]
227-
fn ceil(self) -> f64 {
228-
unsafe { intrinsics::ceilf64(self) }
229-
}
230-
231-
/// Rounds to nearest integer. Rounds half-way cases away from zero.
232-
#[inline]
233-
fn round(self) -> f64 {
234-
unsafe { intrinsics::roundf64(self) }
235-
}
236-
237-
/// Returns the integer part of the number (rounds towards zero).
238-
#[inline]
239-
fn trunc(self) -> f64 {
240-
unsafe { intrinsics::truncf64(self) }
241-
}
242-
243-
/// The fractional part of the number, satisfying:
244-
///
245-
/// ```
246-
/// let x = 1.65f64;
247-
/// assert!(x == x.trunc() + x.fract())
248-
/// ```
249-
#[inline]
250-
fn fract(self) -> f64 { self - self.trunc() }
251-
252219
/// Computes the absolute value of `self`. Returns `Float::nan()` if the
253220
/// number is `Float::nan()`.
254221
#[inline]
@@ -284,74 +251,15 @@ impl Float for f64 {
284251
self < 0.0 || (1.0 / self) == Float::neg_infinity()
285252
}
286253

287-
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
288-
/// error. This produces a more accurate result with better performance than
289-
/// a separate multiplication operation followed by an add.
290-
#[inline]
291-
fn mul_add(self, a: f64, b: f64) -> f64 {
292-
unsafe { intrinsics::fmaf64(self, a, b) }
293-
}
294-
295254
/// Returns the reciprocal (multiplicative inverse) of the number.
296255
#[inline]
297256
fn recip(self) -> f64 { 1.0 / self }
298257

299-
#[inline]
300-
fn powf(self, n: f64) -> f64 {
301-
unsafe { intrinsics::powf64(self, n) }
302-
}
303-
304258
#[inline]
305259
fn powi(self, n: i32) -> f64 {
306260
unsafe { intrinsics::powif64(self, n) }
307261
}
308262

309-
#[inline]
310-
fn sqrt(self) -> f64 {
311-
if self < 0.0 {
312-
NAN
313-
} else {
314-
unsafe { intrinsics::sqrtf64(self) }
315-
}
316-
}
317-
318-
#[inline]
319-
fn rsqrt(self) -> f64 { self.sqrt().recip() }
320-
321-
/// Returns the exponential of the number.
322-
#[inline]
323-
fn exp(self) -> f64 {
324-
unsafe { intrinsics::expf64(self) }
325-
}
326-
327-
/// Returns 2 raised to the power of the number.
328-
#[inline]
329-
fn exp2(self) -> f64 {
330-
unsafe { intrinsics::exp2f64(self) }
331-
}
332-
333-
/// Returns the natural logarithm of the number.
334-
#[inline]
335-
fn ln(self) -> f64 {
336-
unsafe { intrinsics::logf64(self) }
337-
}
338-
339-
/// Returns the logarithm of the number with respect to an arbitrary base.
340-
#[inline]
341-
fn log(self, base: f64) -> f64 { self.ln() / base.ln() }
342-
343-
/// Returns the base 2 logarithm of the number.
344-
#[inline]
345-
fn log2(self) -> f64 {
346-
unsafe { intrinsics::log2f64(self) }
347-
}
348-
349-
/// Returns the base 10 logarithm of the number.
350-
#[inline]
351-
fn log10(self) -> f64 {
352-
unsafe { intrinsics::log10f64(self) }
353-
}
354-
355263
/// Converts to degrees, assuming the number is in radians.
356264
#[inline]
357265
fn to_degrees(self) -> f64 { self * (180.0f64 / consts::PI) }

src/libcore/num/flt2dec/decoder.rs

-5
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,15 @@ pub enum FullDecoded {
5353

5454
/// A floating point type which can be `decode`d.
5555
pub trait DecodableFloat: Float + Copy {
56-
/// Returns `x * 2^exp`. Almost same to `std::{f32,f64}::ldexp`.
57-
/// This is used for testing.
58-
fn ldexpi(f: i64, exp: isize) -> Self;
5956
/// The minimum positive normalized value.
6057
fn min_pos_norm_value() -> Self;
6158
}
6259

6360
impl DecodableFloat for f32 {
64-
fn ldexpi(f: i64, exp: isize) -> Self { f as Self * (exp as Self).exp2() }
6561
fn min_pos_norm_value() -> Self { f32::MIN_POSITIVE }
6662
}
6763

6864
impl DecodableFloat for f64 {
69-
fn ldexpi(f: i64, exp: isize) -> Self { f as Self * (exp as Self).exp2() }
7065
fn min_pos_norm_value() -> Self { f64::MIN_POSITIVE }
7166
}
7267

src/libcore/num/flt2dec/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ functions.
132132

133133
use prelude::v1::*;
134134
use i16;
135-
use num::Float;
136135
use slice::bytes;
137136
pub use self::decoder::{decode, DecodableFloat, FullDecoded, Decoded};
138137

src/libcore/num/flt2dec/strategy/dragon.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Almost direct (but slightly optimized) Rust translation of Figure 3 of [1].
1717

1818
use prelude::v1::*;
1919

20-
use num::Float;
2120
use cmp::Ordering;
2221

2322
use num::flt2dec::{Decoded, MAX_SIG_DIGITS, round_up};

src/libcore/num/flt2dec/strategy/grisu.rs

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ Rust adaptation of Grisu3 algorithm described in [1]. It uses about
1818

1919
use prelude::v1::*;
2020

21-
use num::Float;
22-
2321
use num::flt2dec::{Decoded, MAX_SIG_DIGITS, round_up};
2422

2523
/// A custom 64-bit floating point type, representing `f * 2^e`.

src/libcore/num/mod.rs

-38
Original file line numberDiff line numberDiff line change
@@ -1297,18 +1297,6 @@ pub trait Float: Sized {
12971297
/// Returns the mantissa, exponent and sign as integers, respectively.
12981298
fn integer_decode(self) -> (u64, i16, i8);
12991299

1300-
/// Return the largest integer less than or equal to a number.
1301-
fn floor(self) -> Self;
1302-
/// Return the smallest integer greater than or equal to a number.
1303-
fn ceil(self) -> Self;
1304-
/// Return the nearest integer to a number. Round half-way cases away from
1305-
/// `0.0`.
1306-
fn round(self) -> Self;
1307-
/// Return the integer part of a number.
1308-
fn trunc(self) -> Self;
1309-
/// Return the fractional part of a number.
1310-
fn fract(self) -> Self;
1311-
13121300
/// Computes the absolute value of `self`. Returns `Float::nan()` if the
13131301
/// number is `Float::nan()`.
13141302
fn abs(self) -> Self;
@@ -1325,39 +1313,13 @@ pub trait Float: Sized {
13251313
/// `Float::neg_infinity()`.
13261314
fn is_negative(self) -> bool;
13271315

1328-
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
1329-
/// error. This produces a more accurate result with better performance than
1330-
/// a separate multiplication operation followed by an add.
1331-
fn mul_add(self, a: Self, b: Self) -> Self;
13321316
/// Take the reciprocal (inverse) of a number, `1/x`.
13331317
fn recip(self) -> Self;
13341318

13351319
/// Raise a number to an integer power.
13361320
///
13371321
/// Using this function is generally faster than using `powf`
13381322
fn powi(self, n: i32) -> Self;
1339-
/// Raise a number to a floating point power.
1340-
fn powf(self, n: Self) -> Self;
1341-
1342-
/// Take the square root of a number.
1343-
///
1344-
/// Returns NaN if `self` is a negative number.
1345-
fn sqrt(self) -> Self;
1346-
/// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`.
1347-
fn rsqrt(self) -> Self;
1348-
1349-
/// Returns `e^(self)`, (the exponential function).
1350-
fn exp(self) -> Self;
1351-
/// Returns 2 raised to the power of the number, `2^(self)`.
1352-
fn exp2(self) -> Self;
1353-
/// Returns the natural logarithm of the number.
1354-
fn ln(self) -> Self;
1355-
/// Returns the logarithm of the number with respect to an arbitrary base.
1356-
fn log(self, base: Self) -> Self;
1357-
/// Returns the base 2 logarithm of the number.
1358-
fn log2(self) -> Self;
1359-
/// Returns the base 10 logarithm of the number.
1360-
fn log10(self) -> Self;
13611323

13621324
/// Convert radians to degrees.
13631325
fn to_degrees(self) -> Self;

src/libcore/ops.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,9 @@ rem_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
445445
impl Rem for f32 {
446446
type Output = f32;
447447

448-
// see notes in `core::f32::Float::floor`
448+
// The builtin f32 rem operator is broken when targeting
449+
// MSVC; see comment in std::f32::floor.
450+
// FIXME: See also #27859.
449451
#[inline]
450452
#[cfg(target_env = "msvc")]
451453
fn rem(self, other: f32) -> f32 {

0 commit comments

Comments
 (0)