@@ -282,6 +282,7 @@ template <typename Float> struct float_traits : std::numeric_limits<Float> {
282282 static constexpr int num_exp_bits = num_bits - num_sig_bits - 1 ;
283283 static constexpr int exp_mask = (1 << num_exp_bits) - 1 ;
284284 static constexpr int exp_bias = (1 << (num_exp_bits - 1 )) - 1 ;
285+ static constexpr int exp_offset = exp_bias + num_sig_bits;
285286
286287 using sig_type = std::conditional_t <num_bits == 64 , uint64_t , uint32_t >;
287288 static constexpr sig_type implicit_bit = sig_type(1 ) << num_sig_bits;
@@ -389,13 +390,12 @@ struct exp_shift_table {
389390 using traits = float_traits<double >;
390391 static constexpr bool enable = true ;
391392 static constexpr int num_exps = traits::exp_mask + 1 ;
392- static constexpr int offset = traits::num_sig_bits + traits::exp_bias;
393393 unsigned char data[enable ? num_exps : 1 ] = {};
394394
395395 constexpr exp_shift_table () {
396396 if (!enable) return ;
397397 for (int raw_exp = 0 ; raw_exp < num_exps; ++raw_exp) {
398- int bin_exp = raw_exp - offset ;
398+ int bin_exp = raw_exp - traits::exp_offset ;
399399 if (raw_exp == 0 ) ++bin_exp;
400400 int dec_exp = compute_dec_exp (bin_exp, true );
401401 data[raw_exp] = do_compute_exp_shift (bin_exp, dec_exp);
@@ -418,7 +418,7 @@ template <int num_bits, bool only_regular = false>
418418constexpr ZMIJ_INLINE auto compute_exp_shift (int bin_exp, int dec_exp) noexcept
419419 -> unsigned char {
420420 if (num_bits == 64 && exp_shift_table::enable && only_regular)
421- return exp_shifts.data [bin_exp + exp_shift_table::offset ];
421+ return exp_shifts.data [bin_exp + float_traits< double >::exp_offset ];
422422 return do_compute_exp_shift (bin_exp, dec_exp);
423423}
424424
@@ -766,12 +766,12 @@ auto to_decimal_schubfach(UInt bin_sig, int64_t bin_exp, bool regular) noexcept
766766
767767// Here be 🐉s.
768768// Converts a binary FP number bin_sig * 2**bin_exp to the shortest decimal
769- // representation, where bin_exp = raw_exp - num_sig_bits - exp_bias .
769+ // representation, where bin_exp = raw_exp - exp_offset .
770770template <typename Float, typename UInt>
771771ZMIJ_INLINE auto to_decimal_normal (UInt bin_sig, int64_t raw_exp,
772772 bool regular) noexcept -> zmij::dec_fp {
773773 using traits = float_traits<Float>;
774- int64_t bin_exp = raw_exp - traits::num_sig_bits - traits::exp_bias ;
774+ int64_t bin_exp = raw_exp - traits::exp_offset ;
775775 constexpr int num_bits = std::numeric_limits<UInt>::digits;
776776 // An optimization from yy by Yaoyuan Guo:
777777 while (regular) [[ZMIJ_LIKELY]] {
@@ -881,8 +881,7 @@ inline auto to_decimal(double value) noexcept -> dec_fp {
881881 if (bin_exp == 0 || bin_exp == traits::exp_mask) [[ZMIJ_UNLIKELY]] {
882882 if (bin_exp != 0 ) return {0 , int (~0u >> 1 )};
883883 if (bin_sig == 0 ) return {0 , 0 };
884- constexpr int exp_offset = traits::num_sig_bits + traits::exp_bias;
885- dec = to_decimal_schubfach<true >(bin_sig, 1 - exp_offset, true );
884+ dec = to_decimal_schubfach<true >(bin_sig, 1 - traits::exp_offset, true );
886885 } else {
887886 dec = to_decimal_normal<double >(bin_sig | traits::implicit_bit, bin_exp,
888887 bin_sig != 0 );
@@ -914,8 +913,7 @@ auto write(Float value, char* buffer) noexcept -> char* {
914913 memcpy (buffer, " 0" , 2 );
915914 return buffer + 1 ;
916915 }
917- constexpr int exp_offset = traits::num_sig_bits + traits::exp_bias;
918- dec = to_decimal_schubfach<true >(bin_sig, 1 - exp_offset, true );
916+ dec = to_decimal_schubfach<true >(bin_sig, 1 - traits::exp_offset, true );
919917 } else {
920918 dec = to_decimal_normal<Float>(bin_sig | traits::implicit_bit, bin_exp,
921919 bin_sig != 0 );
0 commit comments