Skip to content

Commit

Permalink
auto merge of #20573 : huonw/rust/num-stab-2, r=alexcrichton
Browse files Browse the repository at this point in the history
cc #19260 

Open questions:

- I still feel weird about marking functions like `exp` as `#[stable]` in `core` since they're highly likely to call into libm which is theoretically something core is designed to avoid and so we may be forced/want to move it at some point in the future, and so it feels like a lie to call it `#[stable]` (I know `core` is `#[experimental]`, but still...)
- `abs_sub` is a horrible name IMO: it feels like it is `(a - b).abs()`, but it is actually `(a - b).max(0.)`. maybe something along the lines of `pos_diff` ("positive difference") is better.
- the associated-function nature of `Int::from_be` and `Int::from_le` feel strange to me, it feels like they should be methods, but I cannot think of a good name.

I'm also not hugely in favour of `ldexp` and `frexp` but the precedent from C is large. (e.g. AFAICT,  `ldexp` must mean "load exponent" which is essentially what it does... but only for a subset of its inputs.)
  • Loading branch information
bors committed Jan 6, 2015
2 parents 340ac04 + f3a80ab commit 8efd990
Show file tree
Hide file tree
Showing 10 changed files with 570 additions and 83 deletions.
24 changes: 17 additions & 7 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ use num::Float;
use num::FpCategory as Fp;
use option::Option;

#[stable]
#[unstable = "pending integer conventions"]
pub const RADIX: uint = 2u;

#[stable]
#[unstable = "pending integer conventions"]
pub const MANTISSA_DIGITS: uint = 24u;
#[stable]
#[unstable = "pending integer conventions"]
pub const DIGITS: uint = 6u;

#[stable]
Expand All @@ -43,14 +43,14 @@ pub const MIN_POS_VALUE: f32 = 1.17549435e-38_f32;
#[stable]
pub const MAX_VALUE: f32 = 3.40282347e+38_f32;

#[stable]
#[unstable = "pending integer conventions"]
pub const MIN_EXP: int = -125;
#[stable]
#[unstable = "pending integer conventions"]
pub const MAX_EXP: int = 128;

#[stable]
#[unstable = "pending integer conventions"]
pub const MIN_10_EXP: int = -37;
#[stable]
#[unstable = "pending integer conventions"]
pub const MAX_10_EXP: int = 38;

#[stable]
Expand Down Expand Up @@ -177,33 +177,43 @@ impl Float for f32 {
}

#[inline]
#[deprecated]
fn mantissa_digits(_: Option<f32>) -> uint { MANTISSA_DIGITS }

#[inline]
#[deprecated]
fn digits(_: Option<f32>) -> uint { DIGITS }

#[inline]
#[deprecated]
fn epsilon() -> f32 { EPSILON }

#[inline]
#[deprecated]
fn min_exp(_: Option<f32>) -> int { MIN_EXP }

#[inline]
#[deprecated]
fn max_exp(_: Option<f32>) -> int { MAX_EXP }

#[inline]
#[deprecated]
fn min_10_exp(_: Option<f32>) -> int { MIN_10_EXP }

#[inline]
#[deprecated]
fn max_10_exp(_: Option<f32>) -> int { MAX_10_EXP }

#[inline]
#[deprecated]
fn min_value() -> f32 { MIN_VALUE }

#[inline]
#[deprecated]
fn min_pos_value(_: Option<f32>) -> f32 { MIN_POS_VALUE }

#[inline]
#[deprecated]
fn max_value() -> f32 { MAX_VALUE }

/// Returns the mantissa, exponent and sign as integers.
Expand Down
23 changes: 16 additions & 7 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ use option::Option;
// constants are implemented in favour of referencing the respective
// members of `Bounded` and `Float`.

#[stable]
#[unstable = "pending integer conventions"]
pub const RADIX: uint = 2u;

#[stable]
pub const MANTISSA_DIGITS: uint = 53u;
#[stable]
#[unstable = "pending integer conventions"]
pub const DIGITS: uint = 15u;

#[stable]
Expand All @@ -47,14 +46,14 @@ pub const MIN_POS_VALUE: f64 = 2.2250738585072014e-308_f64;
#[stable]
pub const MAX_VALUE: f64 = 1.7976931348623157e+308_f64;

#[stable]
#[unstable = "pending integer conventions"]
pub const MIN_EXP: int = -1021;
#[stable]
#[unstable = "pending integer conventions"]
pub const MAX_EXP: int = 1024;

#[stable]
#[unstable = "pending integer conventions"]
pub const MIN_10_EXP: int = -307;
#[stable]
#[unstable = "pending integer conventions"]
pub const MAX_10_EXP: int = 308;

#[stable]
Expand Down Expand Up @@ -185,33 +184,43 @@ impl Float for f64 {
}

#[inline]
#[deprecated]
fn mantissa_digits(_: Option<f64>) -> uint { MANTISSA_DIGITS }

#[inline]
#[deprecated]
fn digits(_: Option<f64>) -> uint { DIGITS }

#[inline]
#[deprecated]
fn epsilon() -> f64 { EPSILON }

#[inline]
#[deprecated]
fn min_exp(_: Option<f64>) -> int { MIN_EXP }

#[inline]
#[deprecated]
fn max_exp(_: Option<f64>) -> int { MAX_EXP }

#[inline]
#[deprecated]
fn min_10_exp(_: Option<f64>) -> int { MIN_10_EXP }

#[inline]
#[deprecated]
fn max_10_exp(_: Option<f64>) -> int { MAX_10_EXP }

#[inline]
#[deprecated]
fn min_value() -> f64 { MIN_VALUE }

#[inline]
#[deprecated]
fn min_pos_value(_: Option<f64>) -> f64 { MIN_POS_VALUE }

#[inline]
#[deprecated]
fn max_value() -> f64 { MAX_VALUE }

/// Returns the mantissa, exponent and sign as integers.
Expand Down
Loading

0 comments on commit 8efd990

Please sign in to comment.