diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-04-08 15:39:46 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-04-08 15:39:46 -0700 |
| commit | 1563ea9f278e1e1cd0d21fe8c4fc761805b71964 (patch) | |
| tree | fcbaf8041e5416abcecd878ccbb5970d7acb0f60 /src/libstd | |
| parent | 02f51211eddbbaf6c6e02cecc78957ce1d5b4600 (diff) | |
| download | rust-1563ea9f278e1e1cd0d21fe8c4fc761805b71964.tar.gz rust-1563ea9f278e1e1cd0d21fe8c4fc761805b71964.zip | |
rustc: Remove f{32,64} % from the language
This commit removes the compiler support for floating point modulus operations, as well as from the language. An implementation for this operator is now required to be provided by libraries. Floating point modulus is rarely used, doesn't exist in C, and is always lowered to an fmod library call by LLVM, and LLVM is considering removing support entirely. Closes #12278
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/num/f32.rs | 5 | ||||
| -rw-r--r-- | src/libstd/num/f64.rs | 5 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 7c5fe4ff274..cf457763513 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -41,6 +41,7 @@ mod cmath { pub fn frexpf(n: c_float, value: &mut c_int) -> c_float; pub fn fmaxf(a: c_float, b: c_float) -> c_float; pub fn fminf(a: c_float, b: c_float) -> c_float; + pub fn fmodf(a: c_float, b: c_float) -> c_float; pub fn nextafterf(x: c_float, y: c_float) -> c_float; pub fn hypotf(x: c_float, y: c_float) -> c_float; pub fn ldexpf(x: c_float, n: c_int) -> c_float; @@ -201,7 +202,9 @@ impl Div<f32,f32> for f32 { #[cfg(not(test))] impl Rem<f32,f32> for f32 { #[inline] - fn rem(&self, other: &f32) -> f32 { *self % *other } + fn rem(&self, other: &f32) -> f32 { + unsafe { cmath::fmodf(*self, *other) } + } } #[cfg(not(test))] diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 69328a5ecdc..4a751988d36 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -40,6 +40,7 @@ mod cmath { pub fn fdim(a: c_double, b: c_double) -> c_double; pub fn fmax(a: c_double, b: c_double) -> c_double; pub fn fmin(a: c_double, b: c_double) -> c_double; + pub fn fmod(a: c_double, b: c_double) -> c_double; pub fn nextafter(x: c_double, y: c_double) -> c_double; pub fn frexp(n: c_double, value: &mut c_int) -> c_double; pub fn hypot(x: c_double, y: c_double) -> c_double; @@ -210,7 +211,9 @@ impl Div<f64,f64> for f64 { #[cfg(not(test))] impl Rem<f64,f64> for f64 { #[inline] - fn rem(&self, other: &f64) -> f64 { *self % *other } + fn rem(&self, other: &f64) -> f64 { + unsafe { cmath::fmod(*self, *other) } + } } #[cfg(not(test))] impl Neg<f64> for f64 { |
