[libc-commits] [libc] [libc][math][c23] Implement canonicalize functions (PR #85940)

Shourya Goel via libc-commits libc-commits at lists.llvm.org
Sat Mar 23 12:19:00 PDT 2024


================
@@ -73,6 +76,56 @@ LIBC_INLINE T fdim(T x, T y) {
   return (x > y ? x - y : 0);
 }
 
+template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
+LIBC_INLINE int canonicalize(T &cx, const T &x) {
+  FPBits<T> sx(x);
+  if constexpr (get_fp_type<T>() == FPType::X86_Binary80) {
+    // All the pseudo and unnormal numbers are not canonical.
----------------
Sh0g0-1758 wrote:

I am not sure how to add those test cases, can you give me an example for this : 

```
    //            |   Bit 63   | Bits 62-0 |
    // All zeroes |   One      | Anything  | Pseudo Denormal, Value =
    //            |            |           | (−1)**s × m × 2**−16382
```

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


More information about the libc-commits mailing list