Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = ["fuzz"]

[workspace.package]
version = "0.2.3+llvm-462a31f5a5ab"
version = "0.2.3+llvm-038f7debfda0"
edition = "2021"
license = "Apache-2.0 WITH LLVM-exception"

Expand Down
2 changes: 1 addition & 1 deletion src/ieee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
let max_change = S::MAX_EXP as i32 - (S::MIN_EXP as i32 - sig_bits) + 1;

// Clamp to one past the range ends to let normalize handle overflow.
let exp_change = cmp::min(cmp::max(exp as i32, -max_change - 1), max_change);
let exp_change = (exp as i32).clamp(-max_change - 1, max_change);
self.exp = self.exp.saturating_add(exp_change as ExpInt);
self = self.normalize(round, Loss::ExactlyZero).value;
if self.is_nan() {
Expand Down
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Port of LLVM's APFloat software floating-point implementation from the
//! following C++ sources (please update commit hash when backporting):
//! <https://github.com/llvm/llvm-project/commit/462a31f5a5abb905869ea93cc49b096079b11aa4>
//! <https://github.com/llvm/llvm-project/commit/038f7debfda01471ce0d4eb1fed20da61e5c8b32>
//! * `llvm/include/llvm/ADT/APFloat.h` -> `Float` and `FloatConvert` traits
//! * `llvm/lib/Support/APFloat.cpp` -> `ieee` and `ppc` modules
//! * `llvm/unittests/ADT/APFloatTest.cpp` -> `tests` directory
Expand Down Expand Up @@ -275,6 +275,16 @@ pub trait Float:
// FIXME(eddyb) provide a default when qnan becomes const fn.
const NAN: Self;

/// Number of bits needed to represent the largest integer that
/// the floating point type can hold.
// FIXME should be const fn.
fn max_int_bits(signed: bool) -> usize {
// The max FP value is pow(2, MaxExponent) * (1 + MaxFraction), so we need
// at least one more bit than the MaxExponent to hold the max FP value.
// Another extra sign bit is needed for signed integers.
Self::MAX_EXP as usize + 1 + (signed as usize)
}

/// Factory for QNaN values.
// FIXME(eddyb) should be const fn.
fn qnan(payload: Option<u128>) -> Self;
Expand Down
Loading