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

Maybe Float::{is_positive, is_negative} should return false for 0's? #22985

Closed
huonw opened this issue Mar 3, 2015 · 5 comments · Fixed by #23549
Closed

Maybe Float::{is_positive, is_negative} should return false for 0's? #22985

huonw opened this issue Mar 3, 2015 · 5 comments · Fixed by #23549
Assignees
Labels
I-needs-decision Issue: In need of a decision.
Milestone

Comments

@huonw
Copy link
Member

huonw commented Mar 3, 2015

Over the real numbers, one doesn't usually consider zero to be explicitly positive or negative (one has to qualify as "non-negative" or "non-positive" respectively to get those classes including zero), so it is a little strange to me that we include 0.0 in the former and -0.0 in the latter.

However, floats are special (signed zero), so maybe the current behaviour is OK. I suppose the "real number" behaviour can be replicated with just > 0.0 and >= 0.0, while these functions are checking the IEEE-754 sign bit.

@huonw
Copy link
Member Author

huonw commented Mar 3, 2015

Nominating, as we may wish to change these functions slightly. (E.g. C/C++ calls this functionality signbit, effectively, although the handling of NaN is different.)

@Manishearth
Copy link
Member

Sounds like a gotcha that might happen, people could write code like:

if if is_positive(foo) {

} else if is_negative(foo) {


} else {
 // case 0
}

I agree that renaming may be a solution here, something explicitly about the sign bit could avoid misuse.

If you needed this feature in a random language, what string would you search for in the docs?

@nagisa
Copy link
Member

nagisa commented Mar 3, 2015

― boolean isSignMinus(source)
isSignMinus(x) is true if and only if x has negative sign. isSignMinus applies to zeros and NaNs
as well.

– IEEE 754

To me it sounds like at least the behaviour of is_negative wrt signed zero is correct.

@huonw
Copy link
Member Author

huonw commented Mar 4, 2015

The names of the functions in the standard are explicitly talking about "sign", i.e. the sign bit, whereas our method names are just referring to the less technical "negative" and "positive" concepts.

@pnkfelix
Copy link
Member

pnkfelix commented Mar 5, 2015

P-backcompat-libs, I-needsdecision, 1.0 beta.

@pnkfelix pnkfelix added this to the 1.0 beta milestone Mar 5, 2015
@pnkfelix pnkfelix added I-needs-decision Issue: In need of a decision. P-backcompat-libs and removed I-nominated labels Mar 5, 2015
aturon added a commit to aturon/rust that referenced this issue Mar 31, 2015
This commit stabilizes the `std::num` module:

* The `Int` and `Float` traits are deprecated in favor of (1) the
  newly-added inherent methods and (2) the generic traits available in
  rust-lang/num.

* The `Zero` and `One` traits are reintroduced in `std::num`, which
  together with various other traits allow you to recover the most
  common forms of generic programming.

* The `FromStrRadix` trait, and associated free function, is deprecated
  in favor of inherent implementations.

* A wide range of methods and constants for both integers and floating
  point numbers are now `#[stable]`, having been adjusted for integer
  guidelines.

* `is_positive` and `is_negative` are renamed to `is_sign_positive` and
  `is_sign_negative`, in order to address rust-lang#22985

* The `Wrapping` type is moved to `std::num` and stabilized;
  `WrappingOps` is deprecated in favor of inherent methods on the
  integer types, and direct implementation of operations on
  `Wrapping<X>` for each concrete integer type `X`.

Closes rust-lang#22985
Closes rust-lang#21069

[breaking-change]
Manishearth added a commit to Manishearth/rust that referenced this issue Mar 31, 2015
This commit stabilizes the `std::num` module:

* The `Int` and `Float` traits are deprecated in favor of (1) the
  newly-added inherent methods and (2) the generic traits available in
  rust-lang/num.

* The `Zero` and `One` traits are reintroduced in `std::num`, which
  together with various other traits allow you to recover the most
  common forms of generic programming.

* The `FromStrRadix` trait, and associated free function, is deprecated
  in favor of inherent implementations.

* A wide range of methods and constants for both integers and floating
  point numbers are now `#[stable]`, having been adjusted for integer
  guidelines.

* `is_positive` and `is_negative` are renamed to `is_sign_positive` and
  `is_sign_negative`, in order to address rust-lang#22985

* The `Wrapping` type is moved to `std::num` and stabilized;
  `WrappingOps` is deprecated in favor of inherent methods on the
  integer types, and direct implementation of operations on
  `Wrapping<X>` for each concrete integer type `X`.

Closes rust-lang#22985
Closes rust-lang#21069

[breaking-change]

r? @alexcrichton
aturon added a commit to aturon/rust that referenced this issue Mar 31, 2015
This commit stabilizes the `std::num` module:

* The `Int` and `Float` traits are deprecated in favor of (1) the
  newly-added inherent methods and (2) the generic traits available in
  rust-lang/num.

* The `Zero` and `One` traits are reintroduced in `std::num`, which
  together with various other traits allow you to recover the most
  common forms of generic programming.

* The `FromStrRadix` trait, and associated free function, is deprecated
  in favor of inherent implementations.

* A wide range of methods and constants for both integers and floating
  point numbers are now `#[stable]`, having been adjusted for integer
  guidelines.

* `is_positive` and `is_negative` are renamed to `is_sign_positive` and
  `is_sign_negative`, in order to address rust-lang#22985

* The `Wrapping` type is moved to `std::num` and stabilized;
  `WrappingOps` is deprecated in favor of inherent methods on the
  integer types, and direct implementation of operations on
  `Wrapping<X>` for each concrete integer type `X`.

Closes rust-lang#22985
Closes rust-lang#21069

[breaking-change]
bors added a commit that referenced this issue Mar 31, 2015
This commit stabilizes the `std::num` module:

* The `Int` and `Float` traits are deprecated in favor of (1) the
  newly-added inherent methods and (2) the generic traits available in
  rust-lang/num.

* The `Zero` and `One` traits are reintroduced in `std::num`, which
  together with various other traits allow you to recover the most
  common forms of generic programming.

* The `FromStrRadix` trait, and associated free function, is deprecated
  in favor of inherent implementations.

* A wide range of methods and constants for both integers and floating
  point numbers are now `#[stable]`, having been adjusted for integer
  guidelines.

* `is_positive` and `is_negative` are renamed to `is_sign_positive` and
  `is_sign_negative`, in order to address #22985

* The `Wrapping` type is moved to `std::num` and stabilized;
  `WrappingOps` is deprecated in favor of inherent methods on the
  integer types, and direct implementation of operations on
  `Wrapping<X>` for each concrete integer type `X`.

Closes #22985
Closes #21069

[breaking-change]

r? @alexcrichton
alexcrichton added a commit to alexcrichton/rust that referenced this issue Mar 31, 2015
This commit stabilizes the `std::num` module:

* The `Int` and `Float` traits are deprecated in favor of (1) the
  newly-added inherent methods and (2) the generic traits available in
  rust-lang/num.

* The `Zero` and `One` traits are reintroduced in `std::num`, which
  together with various other traits allow you to recover the most
  common forms of generic programming.

* The `FromStrRadix` trait, and associated free function, is deprecated
  in favor of inherent implementations.

* A wide range of methods and constants for both integers and floating
  point numbers are now `#[stable]`, having been adjusted for integer
  guidelines.

* `is_positive` and `is_negative` are renamed to `is_sign_positive` and
  `is_sign_negative`, in order to address rust-lang#22985

* The `Wrapping` type is moved to `std::num` and stabilized;
  `WrappingOps` is deprecated in favor of inherent methods on the
  integer types, and direct implementation of operations on
  `Wrapping<X>` for each concrete integer type `X`.

Closes rust-lang#22985
Closes rust-lang#21069

[breaking-change]

r? @alexcrichton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-needs-decision Issue: In need of a decision.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants