Skip to content

Add primitive numeric traits #124243

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

Closed
wants to merge 3 commits into from
Closed
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
67 changes: 0 additions & 67 deletions library/core/src/primitive.rs

This file was deleted.

44 changes: 44 additions & 0 deletions library/core/src/primitive/float_macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Note: currently limiting this to what f16/f128 already support (which isn't much).
// f32/f64 share essentially their whole API which should be added here eventually.

macro_rules! float_decl {
() => {
/// Returns `true` if this value is NaN.
fn is_nan(self) -> bool;

/// Returns `true` if `self` has a positive sign, including `+0.0`, NaNs with
/// positive sign bit and positive infinity. Note that IEEE 754 doesn't assign any
/// meaning to the sign bit in case of a NaN, and as Rust doesn't guarantee that
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
/// `is_sign_positive` on a NaN might produce an unexpected result in some cases.
/// See [explanation of NaN as a special value](f32) for more info.
fn is_sign_positive(self) -> bool;

/// Returns `true` if `self` has a negative sign, including `-0.0`, NaNs with
/// negative sign bit and negative infinity. Note that IEEE 754 doesn't assign any
/// meaning to the sign bit in case of a NaN, and as Rust doesn't guarantee that
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
/// `is_sign_negative` on a NaN might produce an unexpected result in some cases.
/// See [explanation of NaN as a special value](f32) for more info.
fn is_sign_negative(self) -> bool;
};
}

macro_rules! float_impl {
() => {
#[inline]
fn is_nan(self) -> bool {
Self::is_nan(self)
}

#[inline]
fn is_sign_positive(self) -> bool {
Self::is_sign_positive(self)
}

#[inline]
fn is_sign_negative(self) -> bool {
Self::is_sign_negative(self)
}
};
}
Loading
Loading