@@ -27,47 +27,47 @@ LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<OutType> &&
2727 OutType>
2828cast (InType x) {
2929 // Casting to the same type is a no-op.
30- if constexpr (cpp::is_same_v<InType, OutType>)
30+ if constexpr (cpp::is_same_v<InType, OutType>) {
3131 return x;
32-
33- // bfloat16 is always defined (for now)
34- if constexpr (cpp::is_same_v<OutType, bfloat16> ||
35- cpp::is_same_v<InType, bfloat16>
32+ } else {
33+ if constexpr (cpp::is_same_v<OutType, bfloat16> ||
34+ cpp::is_same_v<InType, bfloat16>
3635#if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
37- || cpp::is_same_v<OutType, float16> ||
38- cpp::is_same_v<InType, float16>
36+ || cpp::is_same_v<OutType, float16> ||
37+ cpp::is_same_v<InType, float16>
3938#endif
40- ) {
41- using InFPBits = FPBits<InType>;
42- using InStorageType = typename InFPBits::StorageType;
43- using OutFPBits = FPBits<OutType>;
44- using OutStorageType = typename OutFPBits::StorageType;
39+ ) {
40+ using InFPBits = FPBits<InType>;
41+ using InStorageType = typename InFPBits::StorageType;
42+ using OutFPBits = FPBits<OutType>;
43+ using OutStorageType = typename OutFPBits::StorageType;
4544
46- InFPBits x_bits (x);
45+ InFPBits x_bits (x);
4746
48- if (x_bits.is_nan ()) {
49- if (x_bits.is_signaling_nan ()) {
50- raise_except_if_required (FE_INVALID);
51- return OutFPBits::quiet_nan ().get_val ();
52- }
47+ if (x_bits.is_nan ()) {
48+ if (x_bits.is_signaling_nan ()) {
49+ raise_except_if_required (FE_INVALID);
50+ return OutFPBits::quiet_nan ().get_val ();
51+ }
5352
54- InStorageType x_mant = x_bits.get_mantissa ();
55- if (InFPBits::FRACTION_LEN > OutFPBits::FRACTION_LEN)
56- x_mant >>= InFPBits::FRACTION_LEN - OutFPBits::FRACTION_LEN;
57- return OutFPBits::quiet_nan (x_bits.sign (),
58- static_cast <OutStorageType>(x_mant))
59- .get_val ();
60- }
53+ InStorageType x_mant = x_bits.get_mantissa ();
54+ if (InFPBits::FRACTION_LEN > OutFPBits::FRACTION_LEN)
55+ x_mant >>= InFPBits::FRACTION_LEN - OutFPBits::FRACTION_LEN;
56+ return OutFPBits::quiet_nan (x_bits.sign (),
57+ static_cast <OutStorageType>(x_mant))
58+ .get_val ();
59+ }
6160
62- if (x_bits.is_inf ())
63- return OutFPBits::inf (x_bits.sign ()).get_val ();
61+ if (x_bits.is_inf ())
62+ return OutFPBits::inf (x_bits.sign ()).get_val ();
6463
65- constexpr size_t MAX_FRACTION_LEN =
66- cpp::max (OutFPBits::FRACTION_LEN, InFPBits::FRACTION_LEN);
67- DyadicFloat<cpp::bit_ceil (MAX_FRACTION_LEN)> xd (x);
68- return xd.template as <OutType, /* ShouldSignalExceptions=*/ true >();
69- } else {
70- return static_cast <OutType>(x);
64+ constexpr size_t MAX_FRACTION_LEN =
65+ cpp::max (OutFPBits::FRACTION_LEN, InFPBits::FRACTION_LEN);
66+ DyadicFloat<cpp::bit_ceil (MAX_FRACTION_LEN)> xd (x);
67+ return xd.template as <OutType, /* ShouldSignalExceptions=*/ true >();
68+ } else {
69+ return static_cast <OutType>(x);
70+ }
7171 }
7272}
7373
0 commit comments