Skip to content

Commit 2cd0a21

Browse files
committed
add trait primitive::{Integer, Float}
1 parent 7e3ba5b commit 2cd0a21

File tree

4 files changed

+1291
-67
lines changed

4 files changed

+1291
-67
lines changed

library/core/src/primitive.rs

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Note: currently limiting this to what f16/f128 already support (which isn't much).
2+
// f32/f64 share essentially their whole API which should be added here eventually.
3+
4+
macro_rules! float_decl {
5+
() => {
6+
/// Returns `true` if this value is NaN.
7+
fn is_nan(self) -> bool;
8+
9+
/// Returns `true` if `self` has a positive sign, including `+0.0`, NaNs with
10+
/// positive sign bit and positive infinity. Note that IEEE 754 doesn't assign any
11+
/// meaning to the sign bit in case of a NaN, and as Rust doesn't guarantee that
12+
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
13+
/// `is_sign_positive` on a NaN might produce an unexpected result in some cases.
14+
/// See [explanation of NaN as a special value](f32) for more info.
15+
fn is_sign_positive(self) -> bool;
16+
17+
/// Returns `true` if `self` has a negative sign, including `-0.0`, NaNs with
18+
/// negative sign bit and negative infinity. Note that IEEE 754 doesn't assign any
19+
/// meaning to the sign bit in case of a NaN, and as Rust doesn't guarantee that
20+
/// the bit pattern of NaNs are conserved over arithmetic operations, the result of
21+
/// `is_sign_negative` on a NaN might produce an unexpected result in some cases.
22+
/// See [explanation of NaN as a special value](f32) for more info.
23+
fn is_sign_negative(self) -> bool;
24+
};
25+
}
26+
27+
macro_rules! float_impl {
28+
() => {
29+
#[inline]
30+
fn is_nan(self) -> bool {
31+
Self::is_nan(self)
32+
}
33+
34+
#[inline]
35+
fn is_sign_positive(self) -> bool {
36+
Self::is_sign_positive(self)
37+
}
38+
39+
#[inline]
40+
fn is_sign_negative(self) -> bool {
41+
Self::is_sign_negative(self)
42+
}
43+
};
44+
}

0 commit comments

Comments
 (0)