[llvm-branch-commits] [libc] [libc] Add Operator Overloads for Float80 (PR #214493)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Aug 20 09:55:06 PDT 2026
https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/214493
>From fb0ab67ac7030455035d792fc53a2290073f3eb9 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 23 Jul 2026 00:10:21 +0530
Subject: [PATCH 01/15] initial temp skeleton
---
.../CPP/type_traits/is_floating_point.h | 4 +-
libc/src/__support/FPUtil/CMakeLists.txt | 18 ++
libc/src/__support/FPUtil/FPBits.h | 2 +
libc/src/__support/FPUtil/float80.h | 161 ++++++++++++++++++
libc/src/__support/macros/properties/types.h | 9 +
libc/test/src/__support/FPUtil/CMakeLists.txt | 12 ++
.../src/__support/FPUtil/float80_test.cpp | 19 +++
7 files changed, 224 insertions(+), 1 deletion(-)
create mode 100644 libc/src/__support/FPUtil/float80.h
create mode 100644 libc/test/src/__support/FPUtil/float80_test.cpp
diff --git a/libc/src/__support/CPP/type_traits/is_floating_point.h b/libc/src/__support/CPP/type_traits/is_floating_point.h
index b8c3bf05b4ebb..82a4ede7124c6 100644
--- a/libc/src/__support/CPP/type_traits/is_floating_point.h
+++ b/libc/src/__support/CPP/type_traits/is_floating_point.h
@@ -44,7 +44,9 @@ template <typename T> struct is_floating_point {
bfloat16
,
- fputil::Float128>();
+ fputil::Float128,
+
+ fputil::Float80>();
};
template <typename T>
LIBC_INLINE_VAR constexpr bool is_floating_point_v =
diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index 4673ef794c80b..96fbb6d80a669 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -313,4 +313,22 @@ add_header_library(
libc.src.__support.uint128
)
+add_header_library(
+ float80
+ HDRS
+ float80.h
+ DEPENDS
+ .cast
+ .comparison_operations
+ .dyadic_float
+ libc.hdr.stdint_proxy
+ libc.src.__support.CPP.type_traits
+ libc.src.__support.FPUtil.generic.add_sub
+ libc.src.__support.FPUtil.generic.div
+ libc.src.__support.FPUtil.generic.mul
+ libc.src.__support.macros.attributes
+ libc.src.__support.macros.config
+ libc.src.__support.uint128
+)
+
add_subdirectory(generic)
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index 58222f1a7ae15..a93a1dd563e9a 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -815,6 +815,8 @@ template <typename T> LIBC_INLINE static constexpr FPType get_fp_type() {
return FPType::BFloat16;
else if constexpr (cpp::is_same_v<UnqualT, Float128>)
return FPType::IEEE754_Binary128;
+ else if constexpr (cpp::is_same_v<UnqualT, Float80>)
+ return FPType::IEEE754_Binary128;
else
static_assert(cpp::always_false<UnqualT>, "Unsupported type");
}
diff --git a/libc/src/__support/FPUtil/float80.h b/libc/src/__support/FPUtil/float80.h
new file mode 100644
index 0000000000000..edd63aab47ba7
--- /dev/null
+++ b/libc/src/__support/FPUtil/float80.h
@@ -0,0 +1,161 @@
+//===-- Definition for Float80 data type -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT80_H
+#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT80_H
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/CPP/type_traits.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/comparison_operations.h"
+#include "src/__support/FPUtil/dyadic_float.h"
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/uint128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace fputil {
+
+struct Float80 {
+ UInt128 bits;
+
+ LIBC_INLINE Float80() = default;
+ LIBC_INLINE constexpr Float80(const Float80 &) = default;
+ LIBC_INLINE constexpr Float80(Float80 &&) = default;
+ LIBC_INLINE constexpr Float80 &operator=(const Float80 &) = default;
+ LIBC_INLINE constexpr Float80 &operator=(Float80 &&) = default;
+
+ // Floating point type and integer type
+ template <typename T>
+ LIBC_INLINE constexpr explicit Float80(T value) : bits(0U) {
+ if constexpr (cpp::is_floating_point_v<T>) {
+ bits = fputil::cast<Float80>(value).bits;
+ } else if constexpr (cpp::is_integral_v<T>) {
+ Sign sign = Sign::POS;
+ auto unsigned_value = static_cast<cpp::make_unsigned_t<T>>(value);
+
+ if constexpr (cpp::is_signed_v<T>) {
+ if (value < 0) {
+ sign = Sign::NEG;
+ unsigned_value = -unsigned_value;
+ }
+ }
+
+ fputil::DyadicFloat<FPBits<Float80>::STORAGE_LEN> xd(sign, 0,
+ unsigned_value);
+ bits = xd.template as<Float80, /*ShouldSignalExceptions=*/true>().bits;
+
+ } else if constexpr (cpp::is_convertible_v<T, Float80>) {
+ bits = value.operator Float80().bits;
+ } else {
+ bits = fputil::cast<Float80>(static_cast<float>(value)).bits;
+ }
+ }
+
+ template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T> &&
+ !cpp::is_same_v<T, Float80>,
+ int> = 0>
+ LIBC_INLINE LIBC_CONSTEXPR_DEFAULT operator T() const {
+ return fputil::cast<T>(*this);
+ }
+
+ template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
+ LIBC_INLINE constexpr explicit operator T() const {
+ FPBits<Float80> x_bits(*this);
+ // Raise FE_INVALID for inf and NaN
+ if (x_bits.is_inf_or_nan()) {
+ raise_except_if_required(FE_INVALID);
+ }
+ int x_bits_exp =
+ x_bits.get_explicit_exponent() - FPBits<Float80>::FRACTION_LEN;
+ // sign * 2^(exp-bias) * mantissa
+ DyadicFloat<FPBits<Float80>::STORAGE_LEN> xd(
+ x_bits.sign(), x_bits_exp, x_bits.get_explicit_mantissa());
+ return static_cast<T>(xd.as_mantissa_type());
+ }
+
+ // unary
+ LIBC_INLINE LIBC_BIT_CAST_CONSTEXPR Float80 operator-() const {
+ fputil::FPBits<Float80> result(*this);
+ result.set_sign(result.is_pos() ? Sign::NEG : Sign::POS);
+ return result.get_val();
+ }
+ // operator overloads
+ LIBC_INLINE constexpr Float80 operator+(const Float80 &other) const {
+ return fputil::generic::add<Float80>(*this, other);
+ }
+
+ LIBC_INLINE constexpr Float80 operator-(const Float80 &other) const {
+ return fputil::generic::sub<Float80>(*this, other);
+ }
+
+ LIBC_INLINE constexpr Float80 operator*(const Float80 &other) const {
+ return fputil::generic::mul<Float80>(*this, other);
+ }
+
+ LIBC_INLINE constexpr Float80 operator/(const Float80 &other) const {
+ return fputil::generic::div<Float80>(*this, other);
+ }
+
+ LIBC_INLINE constexpr Float80 &operator*=(const Float80 &other) {
+ *this = *this * other;
+ return *this;
+ }
+
+ LIBC_INLINE constexpr Float80 &operator+=(const Float80 &other) {
+ *this = *this + other;
+ return *this;
+ }
+
+ LIBC_INLINE constexpr Float80 &operator-=(const Float80 &other) {
+ *this = *this - other;
+ return *this;
+ }
+
+ LIBC_INLINE constexpr Float80 &operator/=(const Float80 &other) {
+ *this = *this / other;
+ return *this;
+ }
+
+ LIBC_INLINE constexpr bool operator==(const Float80 &other) const {
+ return fputil::equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator!=(const Float80 &other) const {
+ return !fputil::equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator<(const Float80 &other) const {
+ return fputil::less_than(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator<=(const Float80 &other) const {
+ return fputil::less_than_or_equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator>(const Float80 &other) const {
+ return fputil::greater_than(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator>=(const Float80 &other) const {
+ return fputil::greater_than_or_equals(*this, other);
+ }
+};
+
+static_assert(LIBC_NAMESPACE::cpp::is_trivially_constructible<
+ LIBC_NAMESPACE::fputil::Float80>::value);
+static_assert(LIBC_NAMESPACE::cpp::is_trivially_copyable<
+ LIBC_NAMESPACE::fputil::Float80>::value);
+
+} // namespace fputil
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_Float80_H
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index 083b05164ae64..1b0a971efcd62 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -73,6 +73,15 @@ struct Float128;
// TODO: Commented till we modify all required functions to support emulated
// Float128.
+// -- Emulated float80 support ------------------------------------------------
+
+namespace LIBC_NAMESPACE_DECL {
+namespace fputil {
+struct Float80;
+}
+} // namespace LIBC_NAMESPACE_DECL
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+
// -- bfloat16 support ---------------------------------------------------------
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/test/src/__support/FPUtil/CMakeLists.txt b/libc/test/src/__support/FPUtil/CMakeLists.txt
index 87fd10aaacd90..b5d9ca2331697 100644
--- a/libc/test/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/test/src/__support/FPUtil/CMakeLists.txt
@@ -52,6 +52,18 @@ add_fp_unittest(
libc.src.__support.macros.properties.types
)
+add_fp_unittest(
+ float80_test
+ SUITE
+ libc-fputil-tests
+ SRCS
+ float80_test.cpp
+ DEPENDS
+ libc.hdr.limits_macros
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.float80
+)
+
# TODO: Temporally disable bfloat16 test until MPCommon target is updated
# https://github.com/llvm/llvm-project/pull/149678
if(LLVM_LIBC_FULL_BUILD)
diff --git a/libc/test/src/__support/FPUtil/float80_test.cpp b/libc/test/src/__support/FPUtil/float80_test.cpp
new file mode 100644
index 0000000000000..c7245fa45cd1a
--- /dev/null
+++ b/libc/test/src/__support/FPUtil/float80_test.cpp
@@ -0,0 +1,19 @@
+//===-- Unittests for Float80 emulated type ------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "hdr/limits_macros.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/float80.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+using LIBC_NAMESPACE::Sign;
+using LIBC_NAMESPACE::fputil::Float80;
+using FPBits = LIBC_NAMESPACE::fputil::FPBits<Float80>;
+
+TEST(LlvmLibcFloat80Test, temp) { Float80 a(1.0f); }
>From 06843f9acb5afdf67ba21665b70c5594727f2245 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 23 Jul 2026 00:15:36 +0530
Subject: [PATCH 02/15] nit
---
libc/src/__support/macros/properties/types.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index 1b0a971efcd62..2e715e0714cbb 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -80,7 +80,7 @@ namespace fputil {
struct Float80;
}
} // namespace LIBC_NAMESPACE_DECL
-using float128 = LIBC_NAMESPACE::fputil::Float128;
+using float80 = LIBC_NAMESPACE::fputil::Float80;
// -- bfloat16 support ---------------------------------------------------------
>From 3dd0c2d27bdbcff657184cffa8d605ab8b07de60 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 30 Jul 2026 20:30:14 +0530
Subject: [PATCH 03/15] Removed temporarliy for 128bit container only
---
libc/src/__support/FPUtil/FPBits.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index a93a1dd563e9a..29b815ba79a2b 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -127,11 +127,11 @@ template <> struct FPLayout<FPType::IEEE754_Binary128> {
};
template <> struct FPLayout<FPType::X86_Binary80> {
-#if __SIZEOF_LONG_DOUBLE__ == 12
- using StorageType = UInt<__SIZEOF_LONG_DOUBLE__ * CHAR_BIT>;
-#else
+// #if __SIZEOF_LONG_DOUBLE__ == 12
+// using StorageType = UInt<__SIZEOF_LONG_DOUBLE__ * CHAR_BIT>;
+// #else
using StorageType = UInt128;
-#endif
+// #endif
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
LIBC_INLINE_VAR static constexpr int SIG_LEN = 64;
>From ae7f91297ade563a2f86883df72f6e22bb0aedcf Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 30 Jul 2026 20:36:32 +0530
Subject: [PATCH 04/15] test
---
libc/src/__support/FPUtil/FPBits.h | 8 ++++----
libc/src/__support/FPUtil/dyadic_float.h | 3 ++-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index 29b815ba79a2b..46dcb0da29cd2 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -127,11 +127,11 @@ template <> struct FPLayout<FPType::IEEE754_Binary128> {
};
template <> struct FPLayout<FPType::X86_Binary80> {
-// #if __SIZEOF_LONG_DOUBLE__ == 12
-// using StorageType = UInt<__SIZEOF_LONG_DOUBLE__ * CHAR_BIT>;
-// #else
+ // #if __SIZEOF_LONG_DOUBLE__ == 12
+ // using StorageType = UInt<__SIZEOF_LONG_DOUBLE__ * CHAR_BIT>;
+ // #else
using StorageType = UInt128;
-// #endif
+ // #endif
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
LIBC_INLINE_VAR static constexpr int SIG_LEN = 64;
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index 2effcfcb4a34d..12a2753c796d5 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -438,7 +438,8 @@ template <size_t Bits> struct DyadicFloat {
(FPBits<T>::FRACTION_LEN < Bits),
void>>
LIBC_INLINE LIBC_CONSTEXPR_DEFAULT T as() const {
- if constexpr (cpp::is_same_v<T, bfloat16> || cpp::is_same_v<T, Float128>
+ if constexpr (cpp::is_same_v<T, bfloat16> || cpp::is_same_v<T, Float128> ||
+ cpp::is_same_v<T, Float80>
#if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
|| cpp::is_same_v<T, float16>
#endif
>From 8145315c6aefaa259ef118d2acc22fd5a461700b Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 6 Aug 2026 13:10:13 +0530
Subject: [PATCH 05/15] nit
---
libc/src/__support/FPUtil/FPBits.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index 46dcb0da29cd2..5f6a7b43c60e2 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -127,11 +127,11 @@ template <> struct FPLayout<FPType::IEEE754_Binary128> {
};
template <> struct FPLayout<FPType::X86_Binary80> {
- // #if __SIZEOF_LONG_DOUBLE__ == 12
- // using StorageType = UInt<__SIZEOF_LONG_DOUBLE__ * CHAR_BIT>;
- // #else
+ #if __SIZEOF_LONG_DOUBLE__ == 12
+ using StorageType = UInt<__SIZEOF_LONG_DOUBLE__ * CHAR_BIT>;
+ #else
using StorageType = UInt128;
- // #endif
+ #endif
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
LIBC_INLINE_VAR static constexpr int SIG_LEN = 64;
@@ -816,7 +816,7 @@ template <typename T> LIBC_INLINE static constexpr FPType get_fp_type() {
else if constexpr (cpp::is_same_v<UnqualT, Float128>)
return FPType::IEEE754_Binary128;
else if constexpr (cpp::is_same_v<UnqualT, Float80>)
- return FPType::IEEE754_Binary128;
+ return FPType::IEEE754_Binary80;
else
static_assert(cpp::always_false<UnqualT>, "Unsupported type");
}
>From 168dd1535bc38239e132df7d90245750514274fd Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 6 Aug 2026 13:15:10 +0530
Subject: [PATCH 06/15] formatting
---
libc/src/__support/FPUtil/FPBits.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index 5f6a7b43c60e2..4e4b3480d0a06 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -127,11 +127,11 @@ template <> struct FPLayout<FPType::IEEE754_Binary128> {
};
template <> struct FPLayout<FPType::X86_Binary80> {
- #if __SIZEOF_LONG_DOUBLE__ == 12
- using StorageType = UInt<__SIZEOF_LONG_DOUBLE__ * CHAR_BIT>;
- #else
+#if __SIZEOF_LONG_DOUBLE__ == 12
+ using StorageType = UInt<__SIZEOF_LONG_DOUBLE__ * CHAR_BIT>;
+#else
using StorageType = UInt128;
- #endif
+#endif
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
LIBC_INLINE_VAR static constexpr int SIG_LEN = 64;
@@ -816,7 +816,7 @@ template <typename T> LIBC_INLINE static constexpr FPType get_fp_type() {
else if constexpr (cpp::is_same_v<UnqualT, Float128>)
return FPType::IEEE754_Binary128;
else if constexpr (cpp::is_same_v<UnqualT, Float80>)
- return FPType::IEEE754_Binary80;
+ return FPType::X86_Binary80;
else
static_assert(cpp::always_false<UnqualT>, "Unsupported type");
}
>From 2a8946afe0e2acefd313895c5b96e5a9de01910d Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 6 Aug 2026 13:24:45 +0530
Subject: [PATCH 07/15] add fputiL::cast support
---
libc/src/__support/FPUtil/cast.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libc/src/__support/FPUtil/cast.h b/libc/src/__support/FPUtil/cast.h
index 4fc5ea0893ebe..2a9bfd5a9f62e 100644
--- a/libc/src/__support/FPUtil/cast.h
+++ b/libc/src/__support/FPUtil/cast.h
@@ -33,7 +33,9 @@ cast(InType x) {
if constexpr (cpp::is_same_v<OutType, bfloat16> ||
cpp::is_same_v<InType, bfloat16> ||
cpp::is_same_v<OutType, Float128> ||
- cpp::is_same_v<InType, Float128>
+ cpp::is_same_v<InType, Float128> ||
+ cpp::is_same_v<OutType, Float80> ||
+ cpp::is_same_v<InType, Float80>
#if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
|| cpp::is_same_v<OutType, float16> ||
cpp::is_same_v<InType, float16>
>From 850b3f458cc29c52df0205f80a70f27b1d75af1d Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 6 Aug 2026 15:50:02 +0530
Subject: [PATCH 08/15] feat: add tests
---
libc/src/__support/FPUtil/float80.h | 85 ++++---------------
.../src/__support/FPUtil/float80_test.cpp | 59 +++++++++++++
2 files changed, 75 insertions(+), 69 deletions(-)
diff --git a/libc/src/__support/FPUtil/float80.h b/libc/src/__support/FPUtil/float80.h
index edd63aab47ba7..d6823f7bedb76 100644
--- a/libc/src/__support/FPUtil/float80.h
+++ b/libc/src/__support/FPUtil/float80.h
@@ -69,85 +69,32 @@ struct Float80 {
template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
LIBC_INLINE constexpr explicit operator T() const {
+ constexpr T MIN_T = cpp::numeric_limits<T>::min();
+ constexpr T MAX_T = cpp::numeric_limits<T>::max();
FPBits<Float80> x_bits(*this);
// Raise FE_INVALID for inf and NaN
if (x_bits.is_inf_or_nan()) {
raise_except_if_required(FE_INVALID);
+ return x_bits.is_neg() ? MIN_T : MAX_T;
}
- int x_bits_exp =
- x_bits.get_explicit_exponent() - FPBits<Float80>::FRACTION_LEN;
+ int exponent = x_bits.get_explicit_exponent();
+ constexpr int EXPONENT_LIMIT = cpp::numeric_limits<T>::digits;
+ if (exponent > EXPONENT_LIMIT) {
+ raise_except_if_required(FE_INVALID);
+ return x_bits.is_neg() ? MIN_T : MAX_T;
+ } else if (exponent == EXPONENT_LIMIT) {
+ if (x_bits.is_pos() || x_bits.get_mantissa() != 0) {
+ raise_except_if_required(FE_INVALID);
+ return x_bits.is_neg() ? MIN_T : MAX_T;
+ }
+ }
+
+ int x_bits_exp = exponent - FPBits<Float80>::FRACTION_LEN;
// sign * 2^(exp-bias) * mantissa
DyadicFloat<FPBits<Float80>::STORAGE_LEN> xd(
x_bits.sign(), x_bits_exp, x_bits.get_explicit_mantissa());
return static_cast<T>(xd.as_mantissa_type());
}
-
- // unary
- LIBC_INLINE LIBC_BIT_CAST_CONSTEXPR Float80 operator-() const {
- fputil::FPBits<Float80> result(*this);
- result.set_sign(result.is_pos() ? Sign::NEG : Sign::POS);
- return result.get_val();
- }
- // operator overloads
- LIBC_INLINE constexpr Float80 operator+(const Float80 &other) const {
- return fputil::generic::add<Float80>(*this, other);
- }
-
- LIBC_INLINE constexpr Float80 operator-(const Float80 &other) const {
- return fputil::generic::sub<Float80>(*this, other);
- }
-
- LIBC_INLINE constexpr Float80 operator*(const Float80 &other) const {
- return fputil::generic::mul<Float80>(*this, other);
- }
-
- LIBC_INLINE constexpr Float80 operator/(const Float80 &other) const {
- return fputil::generic::div<Float80>(*this, other);
- }
-
- LIBC_INLINE constexpr Float80 &operator*=(const Float80 &other) {
- *this = *this * other;
- return *this;
- }
-
- LIBC_INLINE constexpr Float80 &operator+=(const Float80 &other) {
- *this = *this + other;
- return *this;
- }
-
- LIBC_INLINE constexpr Float80 &operator-=(const Float80 &other) {
- *this = *this - other;
- return *this;
- }
-
- LIBC_INLINE constexpr Float80 &operator/=(const Float80 &other) {
- *this = *this / other;
- return *this;
- }
-
- LIBC_INLINE constexpr bool operator==(const Float80 &other) const {
- return fputil::equals(*this, other);
- }
-
- LIBC_INLINE constexpr bool operator!=(const Float80 &other) const {
- return !fputil::equals(*this, other);
- }
-
- LIBC_INLINE constexpr bool operator<(const Float80 &other) const {
- return fputil::less_than(*this, other);
- }
-
- LIBC_INLINE constexpr bool operator<=(const Float80 &other) const {
- return fputil::less_than_or_equals(*this, other);
- }
-
- LIBC_INLINE constexpr bool operator>(const Float80 &other) const {
- return fputil::greater_than(*this, other);
- }
-
- LIBC_INLINE constexpr bool operator>=(const Float80 &other) const {
- return fputil::greater_than_or_equals(*this, other);
- }
};
static_assert(LIBC_NAMESPACE::cpp::is_trivially_constructible<
diff --git a/libc/test/src/__support/FPUtil/float80_test.cpp b/libc/test/src/__support/FPUtil/float80_test.cpp
index c7245fa45cd1a..68b38a63c23b4 100644
--- a/libc/test/src/__support/FPUtil/float80_test.cpp
+++ b/libc/test/src/__support/FPUtil/float80_test.cpp
@@ -17,3 +17,62 @@ using LIBC_NAMESPACE::fputil::Float80;
using FPBits = LIBC_NAMESPACE::fputil::FPBits<Float80>;
TEST(LlvmLibcFloat80Test, temp) { Float80 a(1.0f); }
+
+TEST(LlvmLibcFloat80Test, IntegerConversion) {
+ // Float80 to Integer conversion test
+ ASSERT_EQ(static_cast<int>(Float80(0.0f)), 0);
+ ASSERT_EQ(static_cast<int>(Float80(1.0f)), 1);
+ ASSERT_EQ(static_cast<long long>(Float80(1000000000.0)),
+ static_cast<long long>(1000000000));
+ ASSERT_EQ(static_cast<unsigned>(Float80(7.0f)), 7U);
+ ASSERT_EQ(static_cast<int>(Float80(1.9f)), 1);
+
+ // Border values
+ LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
+ ASSERT_EQ(static_cast<int>(Float80(INT_MAX)), INT_MAX);
+ ASSERT_EQ(static_cast<long long>(Float80(LLONG_MAX)), LLONG_MAX);
+ ASSERT_EQ(static_cast<unsigned>(Float80(UINT_MAX)), UINT_MAX);
+ EXPECT_EQ(LIBC_NAMESPACE::fputil::test_except(FE_INVALID), 0);
+
+ // FP exceptions
+ LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
+ ASSERT_EQ(static_cast<int>(FPBits::quiet_nan().get_val()), INT_MAX);
+ EXPECT_FP_EXCEPTION(FE_INVALID);
+
+ LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
+ ASSERT_EQ(static_cast<int>(FPBits::inf().get_val()), INT_MAX);
+ EXPECT_FP_EXCEPTION(FE_INVALID);
+
+ // Extreme values
+ LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
+ ASSERT_EQ(static_cast<int>(Float80(1e300)), INT_MAX);
+ EXPECT_FP_EXCEPTION(FE_INVALID);
+
+ LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
+ ASSERT_EQ(static_cast<int>(FPBits::inf(Sign::POS).get_val()), INT_MAX);
+ EXPECT_FP_EXCEPTION(FE_INVALID);
+
+ // Small values
+ LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
+ ASSERT_EQ(static_cast<int>(Float80(1e-300)), 0);
+ ASSERT_EQ(static_cast<int>(Float80(0.5)), 0);
+ EXPECT_EQ(LIBC_NAMESPACE::fputil::test_except(FE_INVALID), 0);
+}
+
+TEST(LlvmLibcFloat80Test, FromIntegralTypes) {
+ // Integer to Float80 conversion test
+ ASSERT_EQ(FPBits(Float80(42)).uintval(), FPBits(Float80(42.0f)).uintval());
+ ASSERT_EQ(FPBits(Float80(0)).uintval(), FPBits(Float80(0.0f)).uintval());
+ ASSERT_EQ(FPBits(Float80(7U)).uintval(), FPBits(Float80(7.0f)).uintval());
+ ASSERT_EQ(FPBits(Float80(123456789LL)).uintval(),
+ FPBits(Float80(123456789.0)).uintval());
+
+ // 2147483648.0 or 2^31 is out of bound in signed and not in unsigned
+ LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
+ ASSERT_EQ(static_cast<int>(Float80(2147483648.0)), INT_MAX);
+ EXPECT_FP_EXCEPTION(FE_INVALID);
+
+ LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
+ ASSERT_EQ(static_cast<unsigned>(Float80(2147483648.0)), 2147483648U);
+ EXPECT_EQ(LIBC_NAMESPACE::fputil::test_except(FE_INVALID), 0);
+}
>From de753bb681388dbd8a0d73c7c9d48a444e672a21 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 6 Aug 2026 16:56:36 +0530
Subject: [PATCH 09/15] add explicit bit handling for dyadic_float as per
FPBits
---
libc/src/__support/FPUtil/dyadic_float.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index 12a2753c796d5..353f1b56b014d 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -262,6 +262,8 @@ template <size_t Bits> struct DyadicFloat {
sticky = (mantissa & sticky_mask) != 0;
out_mantissa = static_cast<StorageType>(mantissa >> extra_fraction_len);
+ if constexpr (get_fp_type<T>() == FPType::X86_Binary80)
+ out_mantissa |= FPBits::EXPLICIT_BIT_MASK;
}
bool lsb = (out_mantissa & 1) != 0;
>From 8ddcc2ac028947937ec92dae6821b146f8b0684a Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 6 Aug 2026 16:58:38 +0530
Subject: [PATCH 10/15] nit
---
libc/src/__support/FPUtil/dyadic_float.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index 353f1b56b014d..12102ef0b4acd 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -262,6 +262,7 @@ template <size_t Bits> struct DyadicFloat {
sticky = (mantissa & sticky_mask) != 0;
out_mantissa = static_cast<StorageType>(mantissa >> extra_fraction_len);
+ // Takes into consideration the explicit bit for number for types like float 80
if constexpr (get_fp_type<T>() == FPType::X86_Binary80)
out_mantissa |= FPBits::EXPLICIT_BIT_MASK;
}
>From 7d144c1109ef1c55c2007b31c503337f4a7297f8 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 6 Aug 2026 17:03:13 +0530
Subject: [PATCH 11/15] nit
---
libc/src/__support/FPUtil/dyadic_float.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index 12102ef0b4acd..10cf0369dc819 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -262,7 +262,8 @@ template <size_t Bits> struct DyadicFloat {
sticky = (mantissa & sticky_mask) != 0;
out_mantissa = static_cast<StorageType>(mantissa >> extra_fraction_len);
- // Takes into consideration the explicit bit for number for types like float 80
+ // Takes into consideration the explicit bit for number for types like
+ // float 80
if constexpr (get_fp_type<T>() == FPType::X86_Binary80)
out_mantissa |= FPBits::EXPLICIT_BIT_MASK;
}
>From f5291c78a645c660b6810f979c670950b5c943b7 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 6 Aug 2026 17:25:32 +0530
Subject: [PATCH 12/15] test: limit EXTRA_FRAC_LEN to be non-negative
test
test
nit
revert
revert
only add >0 condition
format
---
libc/src/__support/FPUtil/dyadic_float.h | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index 10cf0369dc819..e32906e3cf9cf 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -256,16 +256,14 @@ template <size_t Bits> struct DyadicFloat {
static_cast<StorageType>(unbiased_exp + FPBits::EXP_BIAS);
}
- MantissaType round_mask = MantissaType(1) << (extra_fraction_len - 1);
- round = (mantissa & round_mask) != 0;
- MantissaType sticky_mask = round_mask - 1;
- sticky = (mantissa & sticky_mask) != 0;
+ if (extra_fraction_len > 0) {
+ MantissaType round_mask = MantissaType(1) << (extra_fraction_len - 1);
+ round = (mantissa & round_mask) != 0;
+ MantissaType sticky_mask = round_mask - 1;
+ sticky = (mantissa & sticky_mask) != 0;
+ }
out_mantissa = static_cast<StorageType>(mantissa >> extra_fraction_len);
- // Takes into consideration the explicit bit for number for types like
- // float 80
- if constexpr (get_fp_type<T>() == FPType::X86_Binary80)
- out_mantissa |= FPBits::EXPLICIT_BIT_MASK;
}
bool lsb = (out_mantissa & 1) != 0;
>From 8c0a5ae4f6104e15bfe92194310b65a28517d9df Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 6 Aug 2026 19:11:47 +0530
Subject: [PATCH 13/15] feat: add negation and a test for it
---
libc/src/__support/FPUtil/float80.h | 7 +++++++
libc/test/src/__support/FPUtil/float80_test.cpp | 2 ++
2 files changed, 9 insertions(+)
diff --git a/libc/src/__support/FPUtil/float80.h b/libc/src/__support/FPUtil/float80.h
index d6823f7bedb76..98d2a579c4f3d 100644
--- a/libc/src/__support/FPUtil/float80.h
+++ b/libc/src/__support/FPUtil/float80.h
@@ -95,6 +95,13 @@ struct Float80 {
x_bits.sign(), x_bits_exp, x_bits.get_explicit_mantissa());
return static_cast<T>(xd.as_mantissa_type());
}
+
+ // unary operators
+ LIBC_INLINE LIBC_BIT_CAST_CONSTEXPR Float80 operator-() const {
+ fputil::FPBits<Float80> result(*this);
+ result.set_sign(result.is_pos() ? Sign::NEG : Sign::POS);
+ return result.get_val();
+ }
};
static_assert(LIBC_NAMESPACE::cpp::is_trivially_constructible<
diff --git a/libc/test/src/__support/FPUtil/float80_test.cpp b/libc/test/src/__support/FPUtil/float80_test.cpp
index 68b38a63c23b4..ef0b34df8044d 100644
--- a/libc/test/src/__support/FPUtil/float80_test.cpp
+++ b/libc/test/src/__support/FPUtil/float80_test.cpp
@@ -21,7 +21,9 @@ TEST(LlvmLibcFloat80Test, temp) { Float80 a(1.0f); }
TEST(LlvmLibcFloat80Test, IntegerConversion) {
// Float80 to Integer conversion test
ASSERT_EQ(static_cast<int>(Float80(0.0f)), 0);
+ ASSERT_EQ(static_cast<int>(Float80(-0.0f)), 0);
ASSERT_EQ(static_cast<int>(Float80(1.0f)), 1);
+ ASSERT_EQ(static_cast<int>(Float80(-1.0f)), -1);
ASSERT_EQ(static_cast<long long>(Float80(1000000000.0)),
static_cast<long long>(1000000000));
ASSERT_EQ(static_cast<unsigned>(Float80(7.0f)), 7U);
>From 5d608eb2be0682b73e6f9d221e47cbe264df83cb Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 6 Aug 2026 21:03:12 +0530
Subject: [PATCH 14/15] add tests
---
libc/src/__support/FPUtil/float80.h | 21 +++++++++++++++++++
.../src/__support/FPUtil/float80_test.cpp | 13 ++++++++++++
2 files changed, 34 insertions(+)
diff --git a/libc/src/__support/FPUtil/float80.h b/libc/src/__support/FPUtil/float80.h
index 98d2a579c4f3d..726f15a06520a 100644
--- a/libc/src/__support/FPUtil/float80.h
+++ b/libc/src/__support/FPUtil/float80.h
@@ -101,6 +101,27 @@ struct Float80 {
fputil::FPBits<Float80> result(*this);
result.set_sign(result.is_pos() ? Sign::NEG : Sign::POS);
return result.get_val();
+
+ // operator overloads
+ LIBC_INLINE constexpr Float80 operator+(const Float80 &other) const {
+ return fputil::generic::add<Float80>(*this, other);
+ }
+
+ LIBC_INLINE constexpr Float80 operator-(const Float80 &other) const {
+ return fputil::generic::sub<Float80>(*this, other);
+ }
+
+ LIBC_INLINE constexpr Float80 operator*(const Float80 &other) const {
+ return fputil::generic::mul<Float80>(*this, other);
+ }
+
+ LIBC_INLINE constexpr Float80 operator/(const Float80 &other) const {
+ return fputil::generic::div<Float80>(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator==(const Float128 &other) const {
+ return fputil::equals(*this, other);
+ }
}
};
diff --git a/libc/test/src/__support/FPUtil/float80_test.cpp b/libc/test/src/__support/FPUtil/float80_test.cpp
index ef0b34df8044d..ae5623bf2b759 100644
--- a/libc/test/src/__support/FPUtil/float80_test.cpp
+++ b/libc/test/src/__support/FPUtil/float80_test.cpp
@@ -18,6 +18,19 @@ using FPBits = LIBC_NAMESPACE::fputil::FPBits<Float80>;
TEST(LlvmLibcFloat80Test, temp) { Float80 a(1.0f); }
+TEST(LlvmLibcFloat80Test, Operators) {
+ Float80 a(1.0f), b(1.0f), c(2.0f), d(3.0f), pa(1.0f), na(-1.0f);
+
+ // Unary operators
+ ASSERT_TRUE(FPBits(-pa) == FPBits(na));
+
+ // Binary operators
+ ASSERT_TRUE(a + b == c);
+ ASSERT_TRUE(a - b == Float128(0.0));
+ ASSERT_TRUE(c * d == Float128(6.0));
+ ASSERT_TRUE(Float80(6.0f) / d) == Float80(2.0f);
+}
+
TEST(LlvmLibcFloat80Test, IntegerConversion) {
// Float80 to Integer conversion test
ASSERT_EQ(static_cast<int>(Float80(0.0f)), 0);
>From 00f7178d11dc173341601c04a57b20a20015a704 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 13 Aug 2026 20:25:20 +0530
Subject: [PATCH 15/15] suggestions and add more operators
---
libc/src/__support/FPUtil/float80.h | 56 +++++++++++++------
.../src/__support/FPUtil/float80_test.cpp | 39 +++++++++++--
2 files changed, 74 insertions(+), 21 deletions(-)
diff --git a/libc/src/__support/FPUtil/float80.h b/libc/src/__support/FPUtil/float80.h
index 726f15a06520a..cb8dc618c9280 100644
--- a/libc/src/__support/FPUtil/float80.h
+++ b/libc/src/__support/FPUtil/float80.h
@@ -14,6 +14,7 @@
#include "src/__support/FPUtil/cast.h"
#include "src/__support/FPUtil/comparison_operations.h"
#include "src/__support/FPUtil/dyadic_float.h"
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/FPUtil/generic/div.h"
#include "src/__support/FPUtil/generic/mul.h"
@@ -101,27 +102,50 @@ struct Float80 {
fputil::FPBits<Float80> result(*this);
result.set_sign(result.is_pos() ? Sign::NEG : Sign::POS);
return result.get_val();
+ }
+ LIBC_INLINE constexpr Float80 operator+(const Float80 &other) const {
+ return fputil::generic::add<Float80>(fputil::cast<Float128>(*this),
+ fputil::cast<Float128>(other));
+ }
- // operator overloads
- LIBC_INLINE constexpr Float80 operator+(const Float80 &other) const {
- return fputil::generic::add<Float80>(*this, other);
- }
+ LIBC_INLINE constexpr Float80 operator-(const Float80 &other) const {
+ return fputil::generic::sub<Float80>(fputil::cast<Float128>(*this),
+ fputil::cast<Float128>(other));
+ }
- LIBC_INLINE constexpr Float80 operator-(const Float80 &other) const {
- return fputil::generic::sub<Float80>(*this, other);
- }
+ LIBC_INLINE constexpr Float80 operator*(const Float80 &other) const {
+ return fputil::generic::mul<Float80>(fputil::cast<Float128>(*this),
+ fputil::cast<Float128>(other));
+ }
- LIBC_INLINE constexpr Float80 operator*(const Float80 &other) const {
- return fputil::generic::mul<Float80>(*this, other);
- }
+ LIBC_INLINE constexpr Float80 operator/(const Float80 &other) const {
+ return fputil::generic::div<Float80>(fputil::cast<Float128>(*this),
+ fputil::cast<Float128>(other));
+ }
- LIBC_INLINE constexpr Float80 operator/(const Float80 &other) const {
- return fputil::generic::div<Float80>(*this, other);
- }
+ // Comparison operators
+ LIBC_INLINE constexpr bool operator==(const Float80 &other) const {
+ return fputil::equals(*this, other);
+ }
- LIBC_INLINE constexpr bool operator==(const Float128 &other) const {
- return fputil::equals(*this, other);
- }
+ LIBC_INLINE constexpr bool operator!=(const Float80 &other) const {
+ return !fputil::equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator<(const Float80 &other) const {
+ return fputil::less_than(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator<=(const Float80 &other) const {
+ return fputil::less_than_or_equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator>(const Float80 &other) const {
+ return fputil::greater_than(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator>=(const Float80 &other) const {
+ return fputil::greater_than_or_equals(*this, other);
}
};
diff --git a/libc/test/src/__support/FPUtil/float80_test.cpp b/libc/test/src/__support/FPUtil/float80_test.cpp
index ae5623bf2b759..86312b2f1440e 100644
--- a/libc/test/src/__support/FPUtil/float80_test.cpp
+++ b/libc/test/src/__support/FPUtil/float80_test.cpp
@@ -16,19 +16,48 @@ using LIBC_NAMESPACE::Sign;
using LIBC_NAMESPACE::fputil::Float80;
using FPBits = LIBC_NAMESPACE::fputil::FPBits<Float80>;
+// will be removed
TEST(LlvmLibcFloat80Test, temp) { Float80 a(1.0f); }
TEST(LlvmLibcFloat80Test, Operators) {
Float80 a(1.0f), b(1.0f), c(2.0f), d(3.0f), pa(1.0f), na(-1.0f);
+ // comparison operators
+ ASSERT_TRUE(a == b);
+ ASSERT_TRUE(a == Float80(1.0));
+ ASSERT_TRUE(a != c);
+ ASSERT_TRUE(b != c);
+ ASSERT_TRUE(c > b);
+ ASSERT_TRUE(a >= b);
+ ASSERT_TRUE(b <= c);
+ ASSERT_TRUE(a < c);
+
// Unary operators
- ASSERT_TRUE(FPBits(-pa) == FPBits(na));
+ ASSERT_TRUE(-pa == na);
+ ASSERT_TRUE(-(-pa) == pa);
// Binary operators
- ASSERT_TRUE(a + b == c);
- ASSERT_TRUE(a - b == Float128(0.0));
- ASSERT_TRUE(c * d == Float128(6.0));
- ASSERT_TRUE(Float80(6.0f) / d) == Float80(2.0f);
+ ASSERT_TRUE((a + b) == c);
+ ASSERT_TRUE((a - b) == Float80(0.0f));
+ ASSERT_TRUE((c * d) == Float80(6.0f));
+ ASSERT_TRUE((Float80(6.0f) / d) == Float80(2.0f));
+}
+
+TEST(LlvmLibcFloat80Test, SpecialValues) {
+ Float80 inf = FPBits::inf(Sign::POS).get_val();
+ Float80 neg_inf = FPBits::inf(Sign::NEG).get_val();
+ Float80 nan = FPBits::quiet_nan().get_val();
+
+ // checking operators with special values
+ ASSERT_TRUE(Float80(0.0f) == Float80(-0.0f)); // +0.0 == -0.0 is true
+ ASSERT_TRUE(Float80(0.0f) == Float80(0.0f));
+ ASSERT_TRUE(inf == inf);
+ ASSERT_TRUE(-inf == neg_inf);
+ ASSERT_TRUE((inf + Float80(1.0f)) == inf);
+ ASSERT_TRUE(inf + inf == inf);
+ ASSERT_TRUE(nan != nan);
+ ASSERT_TRUE(!(nan == nan));
+ ASSERT_TRUE(nan != Float80(0.0f));
}
TEST(LlvmLibcFloat80Test, IntegerConversion) {
More information about the llvm-branch-commits
mailing list