Repository: fmtlib/fmt
File: include/fmt/format.h (C/C++)

Code before:
  using floaty =
      std::conditional_t<std::is_same<T, long double>::value, double, T>;
  using uint = typename dragonbox::float_info<floaty>::carrier_uint;
  auto bits = std::bit_cast<uint>(value);
  return (bits & exponent_mask<floaty>()) != exponent_mask<floaty>();
}
#endif

template <typename Char, typename OutputIt, typename T,
          FMT_ENABLE_IF(std::is_floating_point<T>::value)>
FMT_CONSTEXPR20 auto write(OutputIt out, T value,
                           basic_format_specs<Char> specs, locale_ref loc = {})
    -> OutputIt {
  if (const_check(!is_supported_floating_point(value))) return out;
  float_specs fspecs = parse_float_type_spec(specs);
  fspecs.sign = specs.sign;
  bool is_negative;
#ifdef __cpp_if_constexpr
  if (is_constant_evaluated()) {
    // bit check below is valid only for "fast float" types
    if constexpr (is_fast_float<T>::value) {
      using floaty =
          conditional_t<std::is_same<T, long double>::value, double, T>;
      using uint = typename dragonbox::float_info<floaty>::carrier_uint;
      auto bits = bit_cast<uint>(value);
      is_negative = (bits & (uint(1) << (num_bits<uint>() - 1))) != 0;
    } else {
      FMT_ASSERT(false, "floating point type is not supported");
    }
  } else
#endif
  {
    // value < 0 is false for NaN so use signbit.
    is_negative = std::signbit(value);
  }
  if (is_negative) {
    fspecs.sign = sign::minus;
    value = -value;
  } else if (fspecs.sign == sign::minus) {
    fspecs.sign = sign::none;
  }

#if defined(__cpp_lib_bit_cast) && defined(__cpp_if_constexpr)
  if (is_constant_evaluated()) {
    if constexpr (is_fast_float<T>::value) {
      if (!is_finite_fast_float(value))
        return write_nonfinite(out, is_infinite_fast_float(value), specs,
                               fspecs);
    }
  } else
#endif

Review comment (suggestion):
I think this can be simplified by bit casting into `char[sizeof(T)]` and checking the most-significant bit (using `is_big_endian` to determine it). Then `is_fast_float` can be replaced with `std::numeric_limits<T>::is_iec559`.

Also I suggest moving the sign check into a separate function, `fmt::detail::signbit`.

Code after:
#ifdef FMT_FUZZ
    if (num_zeros > 5000)
      throw std::runtime_error("fuzz mode - avoiding excessive cpu use");
#endif
    if (fspecs.showpoint) {
      if (num_zeros <= 0 && fspecs.format != float_format::fixed) num_zeros = 1;
      if (num_zeros > 0) size += to_unsigned(num_zeros) + 1;
    }
    auto grouping = Grouping(loc, fspecs.locale);
    size += to_unsigned(grouping.count_separators(significand_size));
    return write_padded<align::right>(out, specs, size, [&](iterator it) {
      if (sign) *it++ = detail::sign<Char>(sign);
      it = write_significand<Char>(it, significand, significand_size,
                                   fp.exponent, grouping);
      if (!fspecs.showpoint) return it;
      *it++ = decimal_point;
      return num_zeros > 0 ? detail::fill_n(it, num_zeros, zero) : it;
    });
  } else if (exp > 0) {
    // 1234e-2 -> 12.34[0+]
    int num_zeros = fspecs.showpoint ? fspecs.precision - significand_size : 0;
    size += 1 + to_unsigned(num_zeros > 0 ? num_zeros : 0);
    auto grouping = Grouping(loc, fspecs.locale);
    size += to_unsigned(grouping.count_separators(significand_size));
    return write_padded<align::right>(out, specs, size, [&](iterator it) {
      if (sign) *it++ = detail::sign<Char>(sign);
      it = write_significand(it, significand, significand_size, exp,
                             decimal_point, grouping);
      return num_zeros > 0 ? detail::fill_n(it, num_zeros, zero) : it;
    });
  }
  // 1234e-6 -> 0.001234
  int num_zeros = -exp;
  if (significand_size == 0 && fspecs.precision >= 0 &&
      fspecs.precision < num_zeros) {
    num_zeros = fspecs.precision;
  }
  bool pointy = num_zeros != 0 || significand_size != 0 || fspecs.showpoint;
  size += 1 + (pointy ? 1 : 0) + to_unsigned(num_zeros);
  return write_padded<align::right>(out, specs, size, [&](iterator it) {
    if (sign) *it++ = detail::sign<Char>(sign);
    *it++ = zero;
    if (!pointy) return it;
    *it++ = decimal_point;
    it = detail::fill_n(it, num_zeros, zero);
    return write_significand<Char>(it, significand, significand_size);
  });
}

template <typename Char> class fallback_digit_grouping {
 public: