Skip to content

Commit 2b347e7

Browse files
committed
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 038f7debfda01471ce0d4eb1fed20da61e5c8b32, where this was added upstream.
1 parent 1fca86c commit 2b347e7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
members = ["fuzz"]
33

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

src/lib.rs

+11-1
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
@@ -263,6 +263,16 @@ pub trait Float:
263263
// FIXME(eddyb) provide a default when qnan becomes const fn.
264264
const NAN: Self;
265265

266+
/// Number of bits needed to represent the largest integer that
267+
/// the floating point type can hold.
268+
// FIXME should be const fn.
269+
fn max_int_bits(signed: bool) -> usize {
270+
// The max FP value is pow(2, MaxExponent) * (1 + MaxFraction), so we need
271+
// at least one more bit than the MaxExponent to hold the max FP value.
272+
// Another extra sign bit is needed for signed integers.
273+
Self::MAX_EXP as usize + 1 + (signed as usize)
274+
}
275+
266276
/// Factory for QNaN values.
267277
// FIXME(eddyb) should be const fn.
268278
fn qnan(payload: Option<u128>) -> Self;

0 commit comments

Comments
 (0)