summaryrefslogtreecommitdiff
path: root/asl
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-02-25 23:30:03 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-02-25 23:30:03 +0100
commit8b112960586fce4aad791f9cf52c94a70b476ce0 (patch)
tree7e64603b18242885e6b3d6de933707a624329e18 /asl
parentf165706505c214903f1743082d8ba1063c4fcfd3 (diff)
Fix float comparison with 0 warning
Diffstat (limited to 'asl')
-rw-r--r--asl/formatting/format_float.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/asl/formatting/format_float.cpp b/asl/formatting/format_float.cpp
index eca1d92..fb37064 100644
--- a/asl/formatting/format_float.cpp
+++ b/asl/formatting/format_float.cpp
@@ -19,6 +19,16 @@ static constexpr char kZeros[kZeroCount] = {
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
};
+static constexpr bool is_zero(float x)
+{
+ return (asl::bit_cast<uint32_t>(x) & 0x7fff'ffff) == 0;
+}
+
+static constexpr bool is_zero(double x)
+{
+ return (asl::bit_cast<uint64_t>(x) & 0x7fff'ffff'ffff'ffff) == 0;
+}
+
template<asl::is_floating_point T>
static void format_float(asl::Formatter& f, T value)
{
@@ -35,7 +45,7 @@ static void format_float(asl::Formatter& f, T value)
return;
}
- if (value == static_cast<T>(0))
+ if (is_zero(value))
{
f.write("0"_sv);
return;