Skip to content

Commit f995d93

Browse files
committed
Add IeeeFloat::is_representable_as_normal_in
Upstream LLVM commit: 69668590592fcca2c2b22ba2257be57f0319fc9c The following commits are skipped: * 9395cf063a013003704118deccf7633533170a5b: reverted by next commit * 69668590592fcca2c2b22ba2257be57f0319fc9c: reverts previous commit
1 parent e1e14d6 commit f995d93

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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.1+llvm-3d11652bbee4"
5+
version = "0.2.1+llvm-69668590592f"
66
edition = "2021"
77
license = "Apache-2.0 WITH LLVM-exception"
88

src/ieee.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,24 @@ impl<S: Semantics> Neg for IeeeFloat<S> {
576576
}
577577
}
578578

579+
impl<Src: Semantics> IeeeFloat<Src> {
580+
/// Returns true if any number described by `Self` can be precisely represented
581+
/// by a normal (not subnormal) value in `IeeeFloat<Dst>`.
582+
pub const fn is_representable_as_normal_in<Dst: Semantics>() -> bool {
583+
// Exponent range must be larger.
584+
if Src::MAX_EXP >= Dst::MAX_EXP || Src::MIN_EXP <= Dst::MIN_EXP {
585+
return false;
586+
}
587+
588+
// If the mantissa is long enough, the result value could still be denormal
589+
// with a larger exponent range.
590+
//
591+
// FIXME: This condition is probably not accurate but also shouldn't be a
592+
// practical concern with existing types.
593+
return Dst::PRECISION >= Src::PRECISION;
594+
}
595+
}
596+
579597
/// Prints this value as a decimal string.
580598
///
581599
/// \param precision The maximum number of digits of

src/lib.rs

Lines changed: 1 addition & 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/3d11652bbee4cd6782c474e28cb2ab58fc93f245>
3+
//! <https://github.com/llvm/llvm-project/commit/69668590592fcca2c2b22ba2257be57f0319fc9c>
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

0 commit comments

Comments
 (0)