[libc-commits] [libc] 056b404 - [libc][NFC] refactor fmin and fmax (#86718)

via libc-commits libc-commits at lists.llvm.org
Wed Mar 27 20:55:16 PDT 2024


Author: Job Henandez Lara
Date: 2024-03-27T23:55:12-04:00
New Revision: 056b4043543cbc9e4ecad183db185bd26324b5b1

URL: https://github.com/llvm/llvm-project/commit/056b4043543cbc9e4ecad183db185bd26324b5b1
DIFF: https://github.com/llvm/llvm-project/commit/056b4043543cbc9e4ecad183db185bd26324b5b1.diff

LOG: [libc][NFC] refactor fmin and fmax (#86718)

Hello,

So, I worked on the fmaximum and fminimum functions recently and the
reviewers suggested the structure:

```
if (bitsx ...)
  return ...;
if (bitsy ..)
  return 
...
return ...;
```
So I went ahead and did the same for fmin and fmax. I hope this isnt an
issue for you all. thanks.

---------

Co-authored-by: Job Hernandez <h93 at protonmail.com>

Added: 
    

Modified: 
    libc/src/__support/FPUtil/BasicOperations.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index f746d7ac6ad41f..a47931bb33900a 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -30,36 +30,32 @@ template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
 LIBC_INLINE T fmin(T x, T y) {
   const FPBits<T> bitx(x), bity(y);
 
-  if (bitx.is_nan()) {
+  if (bitx.is_nan())
     return y;
-  } else if (bity.is_nan()) {
+  if (bity.is_nan())
     return x;
-  } else if (bitx.sign() != bity.sign()) {
+  if (bitx.sign() != bity.sign())
     // To make sure that fmin(+0, -0) == -0 == fmin(-0, +0), whenever x and
     // y has 
diff erent signs and both are not NaNs, we return the number
     // with negative sign.
-    return (bitx.is_neg()) ? x : y;
-  } else {
-    return (x < y ? x : y);
-  }
+    return bitx.is_neg() ? x : y;
+  return x < y ? x : y;
 }
 
 template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
 LIBC_INLINE T fmax(T x, T y) {
   FPBits<T> bitx(x), bity(y);
 
-  if (bitx.is_nan()) {
+  if (bitx.is_nan())
     return y;
-  } else if (bity.is_nan()) {
+  if (bity.is_nan())
     return x;
-  } else if (bitx.sign() != bity.sign()) {
+  if (bitx.sign() != bity.sign())
     // To make sure that fmax(+0, -0) == +0 == fmax(-0, +0), whenever x and
     // y has 
diff erent signs and both are not NaNs, we return the number
     // with positive sign.
-    return (bitx.is_neg() ? y : x);
-  } else {
-    return (x > y ? x : y);
-  }
+    return bitx.is_neg() ? y : x;
+  return x > y ? x : y;
 }
 
 template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>


        


More information about the libc-commits mailing list