Rename CoreFloat to FloatCore

This commit is contained in:
Vinzent Steinberg 2018-02-07 12:32:53 +01:00
parent 8a7f383eb1
commit efad5329b4
4 changed files with 21 additions and 21 deletions

View File

@ -4,7 +4,7 @@ use core::num::Wrapping;
use identities::Zero;
use bounds::Bounded;
use float::CoreFloat;
use float::FloatCore;
/// A generic trait for converting a value to a number.
pub trait ToPrimitive {
@ -229,7 +229,7 @@ macro_rules! impl_to_primitive_float_to_float {
// NaN and +-inf are cast as they are.
let n = $slf as f64;
let max_value: $DstT = ::core::$DstT::MAX;
if !CoreFloat::is_finite(n) || (-max_value as f64 <= n && n <= max_value as f64)
if !FloatCore::is_finite(n) || (-max_value as f64 <= n && n <= max_value as f64)
{
Some($slf as $DstT)
} else {

View File

@ -13,7 +13,7 @@ use NumCast;
/// Generic trait for floating point numbers that works with `no_std`.
///
/// This trait implements a subset of the `Float` trait.
pub trait CoreFloat: Num + Neg<Output = Self> + PartialOrd + Copy {
pub trait FloatCore: Num + Neg<Output = Self> + PartialOrd + Copy {
/// Returns positive infinity.
#[inline]
fn infinity() -> Self;
@ -56,8 +56,8 @@ pub trait CoreFloat: Num + Neg<Output = Self> + PartialOrd + Copy {
#[inline]
fn classify(self) -> FpCategory;
/// Computes the absolute value of `self`. Returns `CoreFloat::nan()` if the
/// number is `CoreFloat::nan()`.
/// Computes the absolute value of `self`. Returns `FloatCore::nan()` if the
/// number is `FloatCore::nan()`.
#[inline]
fn abs(self) -> Self {
if self.is_sign_positive() {
@ -71,9 +71,9 @@ pub trait CoreFloat: Num + Neg<Output = Self> + PartialOrd + Copy {
/// Returns a number that represents the sign of `self`.
///
/// - `1.0` if the number is positive, `+0.0` or `CoreFloat::infinity()`
/// - `-1.0` if the number is negative, `-0.0` or `CoreFloat::neg_infinity()`
/// - `CoreFloat::nan()` if the number is `CoreFloat::nan()`
/// - `1.0` if the number is positive, `+0.0` or `FloatCore::infinity()`
/// - `-1.0` if the number is negative, `-0.0` or `FloatCore::neg_infinity()`
/// - `FloatCore::nan()` if the number is `FloatCore::nan()`
#[inline]
fn signum(self) -> Self {
if self.is_sign_positive() {
@ -86,14 +86,14 @@ pub trait CoreFloat: Num + Neg<Output = Self> + PartialOrd + Copy {
}
/// Returns `true` if `self` is positive, including `+0.0` and
/// `CoreFloat::infinity()`.
/// `FloatCore::infinity()`.
#[inline]
fn is_sign_positive(self) -> bool {
self > Self::zero() || (Self::one() / self) == Self::infinity()
}
/// Returns `true` if `self` is negative, including `-0.0` and
/// `CoreFloat::neg_infinity()`.
/// `FloatCore::neg_infinity()`.
#[inline]
fn is_sign_negative(self) -> bool {
self < Self::zero() || (Self::one() / self) == Self::neg_infinity()
@ -155,7 +155,7 @@ pub trait CoreFloat: Num + Neg<Output = Self> + PartialOrd + Copy {
fn to_radians(self) -> Self;
}
impl CoreFloat for f32 {
impl FloatCore for f32 {
fn infinity() -> Self {
::core::f32::INFINITY
}
@ -186,7 +186,7 @@ impl CoreFloat for f32 {
}
}
impl CoreFloat for f64 {
impl FloatCore for f64 {
fn infinity() -> Self {
::core::f64::INFINITY
}
@ -1549,15 +1549,15 @@ mod tests {
#[test]
fn convert_deg_rad() {
use CoreFloat;
use FloatCore;
for &(deg, rad) in &DEG_RAD_PAIRS {
assert!((CoreFloat::to_degrees(rad) - deg).abs() < 1e-6);
assert!((CoreFloat::to_radians(deg) - rad).abs() < 1e-6);
assert!((FloatCore::to_degrees(rad) - deg).abs() < 1e-6);
assert!((FloatCore::to_radians(deg) - rad).abs() < 1e-6);
let (deg, rad) = (deg as f32, rad as f32);
assert!((CoreFloat::to_degrees(rad) - deg).abs() < 1e-6);
assert!((CoreFloat::to_radians(deg) - rad).abs() < 1e-6);
assert!((FloatCore::to_degrees(rad) - deg).abs() < 1e-6);
assert!((FloatCore::to_radians(deg) - rad).abs() < 1e-6);
}
}

View File

@ -26,7 +26,7 @@ use core::fmt;
pub use bounds::Bounded;
#[cfg(feature = "std")]
pub use float::Float;
pub use float::{CoreFloat, FloatConst};
pub use float::{FloatCore, FloatConst};
// pub use real::Real; // NOTE: Don't do this, it breaks `use num_traits::*;`.
pub use identities::{Zero, One, zero, one};
pub use ops::checked::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv, CheckedShl, CheckedShr};

View File

@ -4,7 +4,7 @@ use core::num::Wrapping;
use Num;
#[cfg(not(feature = "std"))]
use float::CoreFloat;
use float::FloatCore;
/// Useful functions for signed numbers (i.e. numbers that can be negative).
pub trait Signed: Sized + Num + Neg<Output = Self> {
@ -124,8 +124,8 @@ macro_rules! signed_float_impl {
/// - `NAN` if the number is NaN
#[inline]
fn signum(&self) -> $t {
use CoreFloat;
CoreFloat::signum(*self)
use FloatCore;
FloatCore::signum(*self)
}
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`