Unverified Commit f506192c authored by Guillaume Chatelet's avatar Guillaume Chatelet Committed by GitHub
Browse files

[libc][NFC] Small `abs` related simplifications (#79858)

parent 8c6e96d9
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -19,9 +19,7 @@ namespace fputil {

template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
LIBC_INLINE T abs(T x) {
  FPBits<T> bits(x);
  bits.set_sign(Sign::POS);
  return bits.get_val();
  return FPBits<T>(x).abs().get_val();
}

template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
+1 −5
Original line number Diff line number Diff line
@@ -33,12 +33,8 @@ LLVM_LIBC_FUNCTION(float, acoshf, (float x)) {
  }

  if (LIBC_UNLIKELY(x_u >= 0x4f8ffb03)) {
    // Check for exceptional values.
    uint32_t x_abs = xbits.abs().uintval();
    if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
      // x is +inf or NaN.
    if (LIBC_UNLIKELY(xbits.is_inf_or_nan()))
      return x;
    }

    // Helper functions to set results for exceptional cases.
    auto round_result_slightly_down = [](float r) -> float {
+1 −3
Original line number Diff line number Diff line
@@ -59,10 +59,8 @@ LLVM_LIBC_FUNCTION(float, asinhf, (float x)) {
  };

  if (LIBC_UNLIKELY(x_abs >= 0x4bdd'65a5U)) {
    if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
      // x is +-inf or nan
    if (LIBC_UNLIKELY(xbits.is_inf_or_nan()))
      return x;
    }

    // Exceptional cases when x > 2^24.
    switch (x_abs) {