Display quiet NaNs as 'NaN'.
This is recommended by IEEE 754-2008. We still distinguish signaling NaNs with 'sNaN'.
This commit is contained in:
@@ -247,6 +247,9 @@ Normal numbers
|
|||||||
necessary for :type:`ieee64` which has 52 trailing significand bits
|
necessary for :type:`ieee64` which has 52 trailing significand bits
|
||||||
forming 13 hexadecimal digits with no padding.
|
forming 13 hexadecimal digits with no padding.
|
||||||
|
|
||||||
|
Zeros
|
||||||
|
Positive and negative zero are displayed as ``0.0`` and ``-0.0`` respectively.
|
||||||
|
|
||||||
Subnormal numbers
|
Subnormal numbers
|
||||||
Compatible with C99: ``-0x0.Tpemin`` where ``T`` are the trailing
|
Compatible with C99: ``-0x0.Tpemin`` where ``T`` are the trailing
|
||||||
significand bits encoded as hexadecimal, and ``emin`` is the minimum exponent
|
significand bits encoded as hexadecimal, and ``emin`` is the minimum exponent
|
||||||
@@ -258,8 +261,8 @@ Infinities
|
|||||||
Quiet NaNs
|
Quiet NaNs
|
||||||
Quiet NaNs have the MSB of the trailing significand set. If the remaining
|
Quiet NaNs have the MSB of the trailing significand set. If the remaining
|
||||||
bits of the trailing significand are all zero, the value is displayed as
|
bits of the trailing significand are all zero, the value is displayed as
|
||||||
``-qNaN`` or ``qNaN``. Otherwise, ``-qNaN:0xT`` where ``T`` are the
|
``-NaN`` or ``NaN``. Otherwise, ``-NaN:0xT`` where ``T`` are the trailing
|
||||||
trailing significand bits encoded as hexadecimal.
|
significand bits encoded as hexadecimal.
|
||||||
|
|
||||||
Signaling NaNs
|
Signaling NaNs
|
||||||
Displayed as ``-sNaN:0xT``.
|
Displayed as ``-sNaN:0xT``.
|
||||||
|
|||||||
@@ -99,9 +99,9 @@ fn format_float(bits: u64, w: u8, t: u8, f: &mut Formatter) -> fmt::Result {
|
|||||||
if t_bits & (1 << (t - 1)) != 0 {
|
if t_bits & (1 << (t - 1)) != 0 {
|
||||||
// Quiet NaN.
|
// Quiet NaN.
|
||||||
if payload != 0 {
|
if payload != 0 {
|
||||||
write!(f, "qNaN:0x{:x}", payload)
|
write!(f, "NaN:0x{:x}", payload)
|
||||||
} else {
|
} else {
|
||||||
write!(f, "qNaN")
|
write!(f, "NaN")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Signaling NaN.
|
// Signaling NaN.
|
||||||
@@ -186,12 +186,12 @@ mod tests {
|
|||||||
"0x0.000002p-126");
|
"0x0.000002p-126");
|
||||||
assert_eq!(format!("{}", Ieee32::new(f32::INFINITY)), "Inf");
|
assert_eq!(format!("{}", Ieee32::new(f32::INFINITY)), "Inf");
|
||||||
assert_eq!(format!("{}", Ieee32::new(f32::NEG_INFINITY)), "-Inf");
|
assert_eq!(format!("{}", Ieee32::new(f32::NEG_INFINITY)), "-Inf");
|
||||||
assert_eq!(format!("{}", Ieee32::new(f32::NAN)), "qNaN");
|
assert_eq!(format!("{}", Ieee32::new(f32::NAN)), "NaN");
|
||||||
assert_eq!(format!("{}", Ieee32::new(-f32::NAN)), "-qNaN");
|
assert_eq!(format!("{}", Ieee32::new(-f32::NAN)), "-NaN");
|
||||||
// Construct some qNaNs with payloads.
|
// Construct some qNaNs with payloads.
|
||||||
assert_eq!(format!("{}", Ieee32::new_from_bits(0x7fc00001)), "qNaN:0x1");
|
assert_eq!(format!("{}", Ieee32::new_from_bits(0x7fc00001)), "NaN:0x1");
|
||||||
assert_eq!(format!("{}", Ieee32::new_from_bits(0x7ff00001)),
|
assert_eq!(format!("{}", Ieee32::new_from_bits(0x7ff00001)),
|
||||||
"qNaN:0x300001");
|
"NaN:0x300001");
|
||||||
// Signaling NaNs.
|
// Signaling NaNs.
|
||||||
assert_eq!(format!("{}", Ieee32::new_from_bits(0x7f800001)), "sNaN:0x1");
|
assert_eq!(format!("{}", Ieee32::new_from_bits(0x7f800001)), "sNaN:0x1");
|
||||||
assert_eq!(format!("{}", Ieee32::new_from_bits(0x7fa00001)),
|
assert_eq!(format!("{}", Ieee32::new_from_bits(0x7fa00001)),
|
||||||
@@ -221,13 +221,13 @@ mod tests {
|
|||||||
"0x0.0000000000001p-1022");
|
"0x0.0000000000001p-1022");
|
||||||
assert_eq!(format!("{}", Ieee64::new(f64::INFINITY)), "Inf");
|
assert_eq!(format!("{}", Ieee64::new(f64::INFINITY)), "Inf");
|
||||||
assert_eq!(format!("{}", Ieee64::new(f64::NEG_INFINITY)), "-Inf");
|
assert_eq!(format!("{}", Ieee64::new(f64::NEG_INFINITY)), "-Inf");
|
||||||
assert_eq!(format!("{}", Ieee64::new(f64::NAN)), "qNaN");
|
assert_eq!(format!("{}", Ieee64::new(f64::NAN)), "NaN");
|
||||||
assert_eq!(format!("{}", Ieee64::new(-f64::NAN)), "-qNaN");
|
assert_eq!(format!("{}", Ieee64::new(-f64::NAN)), "-NaN");
|
||||||
// Construct some qNaNs with payloads.
|
// Construct some qNaNs with payloads.
|
||||||
assert_eq!(format!("{}", Ieee64::new_from_bits(0x7ff8000000000001)),
|
assert_eq!(format!("{}", Ieee64::new_from_bits(0x7ff8000000000001)),
|
||||||
"qNaN:0x1");
|
"NaN:0x1");
|
||||||
assert_eq!(format!("{}", Ieee64::new_from_bits(0x7ffc000000000001)),
|
assert_eq!(format!("{}", Ieee64::new_from_bits(0x7ffc000000000001)),
|
||||||
"qNaN:0x4000000000001");
|
"NaN:0x4000000000001");
|
||||||
// Signaling NaNs.
|
// Signaling NaNs.
|
||||||
assert_eq!(format!("{}", Ieee64::new_from_bits(0x7ff0000000000001)),
|
assert_eq!(format!("{}", Ieee64::new_from_bits(0x7ff0000000000001)),
|
||||||
"sNaN:0x1");
|
"sNaN:0x1");
|
||||||
|
|||||||
Reference in New Issue
Block a user