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

Second stabilisation pass of *::num #20573

Merged
merged 7 commits into from
Jan 6, 2015
Merged

Second stabilisation pass of *::num #20573

merged 7 commits into from
Jan 6, 2015

Conversation

huonw
Copy link
Member

@huonw huonw commented Jan 5, 2015

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.)

@rust-highfive
Copy link
Collaborator

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@huonw
Copy link
Member Author

huonw commented Jan 5, 2015

r? @aturon

/// Returns the mantissa, exponent and sign as integers, respectively.
#[stable]
fn integer_decode(self) -> (u64, i16, i8);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nagisa on IRC points out that these types are insufficient for e.g. f128, maybe they could become associated types. (Also allows choosing less wasteful ones for f32 compared to f64, but maybe having differing types is just more annoying than its worth.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions like this are somewhat obscure, and I'd be fine leaving it unstable for now.

@alexcrichton
Copy link
Member

I would also be fine being much more conservative here and avoid stabilizing more flavorful functions like integer_decode, mul_add, to_{radians,degrees}, next_after, exp_m1, ln_1p, etc. I also don't think it's a huge commitment either way!

@aturon
Copy link
Member

aturon commented Jan 5, 2015

Left a few comments. I basically agree with @alexcrichton, although presumably things like exp_m1 exist because there's some extra speedy support for them? (But in all of those cases the names could be improved.) I don't think we need to necessarily follow the C naming tradition here; we certainly haven't elsewhere! (But for now things with questionable names can be left #[unstable] for another cycle.)

re: from_be, in the long run you'll be able to type i32::from_be(some_i32) which seems pretty good to me.

@huonw
Copy link
Member Author

huonw commented Jan 6, 2015

although presumably things like exp_m1 exist because there's some extra speedy support for them?

It's actually extra accuracy (e.g. 1e-7_f32.exp() - 1.0 is about 1.2e-7 but the real answer is almost exactly 1e-7), but yes, they exist for a concrete reason.

@huonw
Copy link
Member Author

huonw commented Jan 6, 2015

Ok, I think I've address comments; re-r?

@alexcrichton
Copy link
Member

r=me with the tidy failure fixed

huonw added 7 commits January 6, 2015 23:21
These are replaced by the equivalent constants in `std::f32` and
`std::f64` respectively.

[breaking-change]
`FloatMath` no longer exists and all functionality from both traits is
available under `Float`. Change from

    use std::num::{Float, FloatMath};

to

    use std::num::Float;

[breaking-change]
bors added a commit that referenced this pull request Jan 6, 2015
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.)
@bors bors merged commit f3a80ab into rust-lang:master Jan 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants