Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libs: stabilize most numerics after RFC changes #18999

Merged
merged 2 commits into from
Nov 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,57 @@
// FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353
#![allow(overflowing_literals)]

#![stable]

use intrinsics;
use mem;
use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
use num::from_str_radix;
use option::Option;

#[stable]
pub const RADIX: uint = 2u;

#[stable]
pub const MANTISSA_DIGITS: uint = 24u;
#[stable]
pub const DIGITS: uint = 6u;

#[stable]
pub const EPSILON: f32 = 1.19209290e-07_f32;

/// Smallest finite f32 value
#[stable]
pub const MIN_VALUE: f32 = -3.40282347e+38_f32;
/// Smallest positive, normalized f32 value
#[stable]
pub const MIN_POS_VALUE: f32 = 1.17549435e-38_f32;
/// Largest finite f32 value
#[stable]
pub const MAX_VALUE: f32 = 3.40282347e+38_f32;

#[stable]
pub const MIN_EXP: int = -125;
#[stable]
pub const MAX_EXP: int = 128;

#[stable]
pub const MIN_10_EXP: int = -37;
#[stable]
pub const MAX_10_EXP: int = 38;

#[stable]
pub const NAN: f32 = 0.0_f32/0.0_f32;
#[stable]
pub const INFINITY: f32 = 1.0_f32/0.0_f32;
#[stable]
pub const NEG_INFINITY: f32 = -1.0_f32/0.0_f32;

/// Various useful constants.
#[unstable = "naming scheme needs to be revisited"]
pub mod consts {
// FIXME: replace with mathematical constants from cmath.

// FIXME(#5527): These constants should be deprecated once associated
// constants are implemented in favour of referencing the respective members
// of `Float`.

/// Archimedes' constant
pub const PI: f32 = 3.14159265358979323846264338327950288_f32;

Expand Down Expand Up @@ -104,6 +117,7 @@ pub mod consts {
pub const LN_10: f32 = 2.30258509299404568401799145468436421_f32;
}

#[unstable = "trait is unstable"]
impl Float for f32 {
#[inline]
fn nan() -> f32 { NAN }
Expand Down Expand Up @@ -415,12 +429,12 @@ impl Float for f32 {

/// Converts to degrees, assuming the number is in radians.
#[inline]
fn to_degrees(self) -> f32 { self * (180.0f32 / Float::pi()) }
fn to_degrees(self) -> f32 { self * (180.0f32 / consts::PI) }

/// Converts to radians, assuming the number is in degrees.
#[inline]
fn to_radians(self) -> f32 {
let value: f32 = Float::pi();
let value: f32 = consts::PI;
self * (value / 180.0f32)
}
}
Expand Down
24 changes: 20 additions & 4 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353
#![allow(overflowing_literals)]

#![stable]

use intrinsics;
use mem;
use num::{Float, FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
Expand All @@ -24,33 +26,46 @@ use option::Option;
// constants are implemented in favour of referencing the respective
// members of `Bounded` and `Float`.

#[stable]
pub const RADIX: uint = 2u;

#[stable]
pub const MANTISSA_DIGITS: uint = 53u;
#[stable]
pub const DIGITS: uint = 15u;

#[stable]
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;

/// Smallest finite f64 value
#[stable]
pub const MIN_VALUE: f64 = -1.7976931348623157e+308_f64;
/// Smallest positive, normalized f64 value
#[stable]
pub const MIN_POS_VALUE: f64 = 2.2250738585072014e-308_f64;
/// Largest finite f64 value
#[stable]
pub const MAX_VALUE: f64 = 1.7976931348623157e+308_f64;

#[stable]
pub const MIN_EXP: int = -1021;
#[stable]
pub const MAX_EXP: int = 1024;

#[stable]
pub const MIN_10_EXP: int = -307;
#[stable]
pub const MAX_10_EXP: int = 308;

#[stable]
pub const NAN: f64 = 0.0_f64/0.0_f64;

#[stable]
pub const INFINITY: f64 = 1.0_f64/0.0_f64;

#[stable]
pub const NEG_INFINITY: f64 = -1.0_f64/0.0_f64;

/// Various useful constants.
#[unstable = "naming scheme needs to be revisited"]
pub mod consts {
// FIXME: replace with mathematical constants from cmath.

Expand Down Expand Up @@ -110,6 +125,7 @@ pub mod consts {
pub const LN_10: f64 = 2.30258509299404568401799145468436421_f64;
}

#[unstable = "trait is unstable"]
impl Float for f64 {
#[inline]
fn nan() -> f64 { NAN }
Expand Down Expand Up @@ -421,12 +437,12 @@ impl Float for f64 {

/// Converts to degrees, assuming the number is in radians.
#[inline]
fn to_degrees(self) -> f64 { self * (180.0f64 / Float::pi()) }
fn to_degrees(self) -> f64 { self * (180.0f64 / consts::PI) }

/// Converts to radians, assuming the number is in degrees.
#[inline]
fn to_radians(self) -> f64 {
let value: f64 = Float::pi();
let value: f64 = consts::PI;
self * (value / 180.0)
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/libcore/num/i16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

//! Operations and constants for signed 16-bits integers (`i16` type)

#![unstable]
#![stable]
#![doc(primitive = "i16")]

int_module!(i16, 16)

3 changes: 1 addition & 2 deletions src/libcore/num/i32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

//! Operations and constants for signed 32-bits integers (`i32` type)

#![unstable]
#![stable]
#![doc(primitive = "i32")]

int_module!(i32, 32)

3 changes: 1 addition & 2 deletions src/libcore/num/i64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

//! Operations and constants for signed 64-bits integers (`i64` type)

#![unstable]
#![stable]
#![doc(primitive = "i64")]

int_module!(i64, 64)

3 changes: 1 addition & 2 deletions src/libcore/num/i8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

//! Operations and constants for signed 8-bits integers (`i8` type)

#![unstable]
#![stable]
#![doc(primitive = "i8")]

int_module!(i8, 8)

Loading