Skip to content

Commit eb79bbc

Browse files
eduardosmtgross35
authored andcommitted
Add Float::max_int_bits
Returns the number of bits needed to represent the largest integer that a floating point type can hold. Bumps LLVM commit to llvm/llvm-project@038f7de, where this was added upstream.
1 parent c9d7071 commit eb79bbc

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
members = ["fuzz"]
33

44
[workspace.package]
5-
version = "0.2.3+llvm-4dc08de9d2f6"
5+
version = "0.2.3+llvm-038f7debfda0"
66
edition = "2021"
77
license = "Apache-2.0 WITH LLVM-exception"
88

src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Port of LLVM's APFloat software floating-point implementation from the
22
//! following C++ sources (please update commit hash when backporting):
3-
//! <https://github.com/llvm/llvm-project/commit/4dc08de9d2f680309cdd639169d3b8802c76ae9a>
3+
//! <https://github.com/llvm/llvm-project/commit/038f7debfda01471ce0d4eb1fed20da61e5c8b32>
44
//! * `llvm/include/llvm/ADT/APFloat.h` -> `Float` and `FloatConvert` traits
55
//! * `llvm/lib/Support/APFloat.cpp` -> `ieee` and `ppc` modules
66
//! * `llvm/unittests/ADT/APFloatTest.cpp` -> `tests` directory
@@ -275,6 +275,16 @@ pub trait Float:
275275
// FIXME(eddyb) provide a default when qnan becomes const fn.
276276
const NAN: Self;
277277

278+
/// Number of bits needed to represent the largest integer that
279+
/// the floating point type can hold.
280+
// FIXME should be const fn.
281+
fn max_int_bits(signed: bool) -> usize {
282+
// The max FP value is pow(2, MaxExponent) * (1 + MaxFraction), so we need
283+
// at least one more bit than the MaxExponent to hold the max FP value.
284+
// Another extra sign bit is needed for signed integers.
285+
Self::MAX_EXP as usize + 1 + (signed as usize)
286+
}
287+
278288
/// Factory for QNaN values.
279289
// FIXME(eddyb) should be const fn.
280290
fn qnan(payload: Option<u128>) -> Self;

0 commit comments

Comments
 (0)