[libc-commits] [libc] [libc] Float128 Emulation in LLVM libc (PR #200565)

via libc-commits libc-commits at lists.llvm.org
Sat Jul 11 12:02:15 PDT 2026


================
@@ -0,0 +1,91 @@
+//===-- Unittests for Float128 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 "src/__support/FPUtil/float128.h"
+#include "test/UnitTest/Test.h"
+
+using LIBC_NAMESPACE::Sign;
+using LIBC_NAMESPACE::fputil::Float128;
+
+TEST(LlvmLibcFloat128Test, Operators) {
+  Float128 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 == Float128(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(-pa == na);
+  ASSERT_TRUE(-(-pa) == pa);
+
+  // Binary operators
+  ASSERT_TRUE((a + b) == c);
+  ASSERT_TRUE((a - b) == Float128(0.0f));
+  ASSERT_TRUE((c * d) == Float128(6.0f));
+  ASSERT_TRUE((Float128(6.0f) / d) == Float128(2.0f));
+
+  // Compound assignment operators
+  a += Float128(1.0f);
+  ASSERT_TRUE(a == c);
+  b -= Float128(1.0f);
+  ASSERT_TRUE(b == Float128(0.0f));
+  c *= Float128(2.0f);
+  ASSERT_TRUE(c == Float128(4.0f));
+  d /= Float128(3.0f);
+  ASSERT_TRUE(d == Float128(1.0f));
+}
+
+TEST(LlvmLibcFloat128Test, SpecialValues) {
+  using FPBits = LIBC_NAMESPACE::fputil::FPBits<Float128>;
+
+  Float128 zero = FPBits::zero(Sign::POS).get_val();
+  Float128 neg_zero = FPBits::zero(Sign::NEG).get_val();
+  Float128 inf = FPBits::inf(Sign::POS).get_val();
+  Float128 neg_inf = FPBits::inf(Sign::NEG).get_val();
+  Float128 nan = FPBits::quiet_nan().get_val();
+
+  // checking operators with special values
+  ASSERT_TRUE(zero == neg_zero); // +0.0 == -0.0 is true
+  ASSERT_TRUE(zero == Float128(0.0f));
+  ASSERT_TRUE(inf == inf);
+  ASSERT_TRUE(-inf == neg_inf);
+  ASSERT_TRUE((inf + Float128(1.0f)) == inf);
+  ASSERT_TRUE(inf + inf == inf);
+  ASSERT_TRUE(nan != nan);
+  ASSERT_TRUE(!(nan == nan));
+  ASSERT_TRUE(nan != zero);
+}
+
+TEST(LlvmLibcFloat128Test, IntegerConversion) {
----------------
Sukumarsawant wrote:

added in [48274cf](https://github.com/llvm/llvm-project/pull/200565/commits/48274cfca18cd15f0a29593c45fc9c3822bb4a0a)
, [7d4b3b7](https://github.com/llvm/llvm-project/pull/200565/commits/7d4b3b735c6379022c4f34a589bfe78743b79db6)

https://github.com/llvm/llvm-project/pull/200565


More information about the libc-commits mailing list