Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 62b685c

Browse files
authored
Implement rounding for the hex float parsing and prepare to improve error handling
Parsing errors are now bubbled up part of the way, but that needs some more work. Rounding should be correct, and the `Status` returned by `parse_any` should have the correct bits set. These are used for the current (unchanged) behavior of the surface level functions like `hf64`: panic on invalid inputs, or values that aren't exactly representable.
1 parent 56fdec7 commit 62b685c

File tree

3 files changed

+405
-111
lines changed

3 files changed

+405
-111
lines changed

libm/crates/libm-test/src/f8_impl.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
use std::cmp::{self, Ordering};
44
use std::{fmt, ops};
55

6-
use libm::support::hex_float::parse_any;
7-
86
use crate::Float;
97

108
/// Sometimes verifying float logic is easiest when all values can quickly be checked exhaustively
@@ -499,5 +497,6 @@ impl fmt::LowerHex for f8 {
499497
}
500498

501499
pub const fn hf8(s: &str) -> f8 {
502-
f8(parse_any(s, 8, 3) as u8)
500+
let Ok(bits) = libm::support::hex_float::parse_hex_exact(s, 8, 3) else { panic!() };
501+
f8(bits as u8)
503502
}

libm/src/math/support/env.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub enum Round {
4646
}
4747

4848
/// IEEE 754 exception status flags.
49-
#[derive(Clone, Copy, Debug, PartialEq)]
49+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5050
pub struct Status(u8);
5151

5252
impl Status {
@@ -90,16 +90,22 @@ impl Status {
9090

9191
/// True if `UNDERFLOW` is set.
9292
#[cfg_attr(not(feature = "unstable-public-internals"), allow(dead_code))]
93-
pub fn underflow(self) -> bool {
93+
pub const fn underflow(self) -> bool {
9494
self.0 & Self::UNDERFLOW.0 != 0
9595
}
9696

97+
/// True if `OVERFLOW` is set.
98+
#[cfg_attr(not(feature = "unstable-public-internals"), allow(dead_code))]
99+
pub const fn overflow(self) -> bool {
100+
self.0 & Self::OVERFLOW.0 != 0
101+
}
102+
97103
pub fn set_underflow(&mut self, val: bool) {
98104
self.set_flag(val, Self::UNDERFLOW);
99105
}
100106

101107
/// True if `INEXACT` is set.
102-
pub fn inexact(self) -> bool {
108+
pub const fn inexact(self) -> bool {
103109
self.0 & Self::INEXACT.0 != 0
104110
}
105111

@@ -114,4 +120,8 @@ impl Status {
114120
self.0 &= !mask.0;
115121
}
116122
}
123+
124+
pub(crate) const fn with(self, rhs: Self) -> Self {
125+
Self(self.0 | rhs.0)
126+
}
117127
}

0 commit comments

Comments
 (0)