[libc-commits] [libc] [libc] Fix strfromf handling inf/nan. (PR #225805)
via libc-commits
libc-commits at lists.llvm.org
Fri Sep 25 08:01:10 PDT 2026
================
@@ -26,30 +26,53 @@ namespace LIBC_NAMESPACE_DECL {
namespace printf_core {
struct FloatHexExpFPBitsProperties {
- bool is_negative;
- int exponent;
AnyFloatStorageType mantissa;
- bool is_inf_or_nan;
+ int exponent;
uint32_t fraction_bits;
+ bool is_negative;
+ bool is_inf_or_nan;
+ bool mantissa_is_zero;
};
template <typename T>
-FloatHexExpFPBitsProperties
-get_float_hex_exp_fp_bits_properties(AnyFloatStorageType float_raw) {
- fputil::FPBits<T> float_bits(
- static_cast<typename fputil::FPBits<T>::StorageType>(float_raw));
+LIBC_INLINE FloatHexExpFPBitsProperties
+get_float_hex_exp_fp_bits_properties_typed(fputil::FPBits<T> float_bits) {
return {
- .is_negative = float_bits.is_neg(),
- .exponent = float_bits.get_explicit_exponent(),
.mantissa = float_bits.get_explicit_mantissa(),
- .is_inf_or_nan = float_bits.is_inf_or_nan(),
+ .exponent = float_bits.get_explicit_exponent(),
.fraction_bits = fputil::FPBits<T>::FRACTION_LEN,
+ .is_negative = float_bits.is_neg(),
+ .is_inf_or_nan = float_bits.is_inf_or_nan(),
+ .mantissa_is_zero = float_bits.get_mantissa() == 0,
};
}
+// Returns relevant floating point properties for conversion using
+// `to_conv.length_modifier` to infer the conversion value type.
+LIBC_INLINE FloatHexExpFPBitsProperties
+get_float_hex_exp_fp_bits_properties_lm(const FormatSection &to_conv) {
+#if defined(LIBC_INTERNAL_PRINTF_CONVERT_FLOAT128)
+ if (to_conv.length_modifier == LengthModifier::Q)
+ return get_float_hex_exp_fp_bits_properties_typed<float128>(
+ fputil::FPBits<float128>(to_conv.conv_val_raw));
+#endif // LIBC_INTERNAL_PRINTF_CONVERT_FLOAT128
+#ifndef LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
----------------
lntue wrote:
why don't we have to deal with other long double options here?
https://github.com/llvm/llvm-project/pull/225805
More information about the libc-commits
mailing list