diff --git a/include/pocketpy/common.h b/include/pocketpy/common.h index 38b6cd23..8cf9db48 100644 --- a/include/pocketpy/common.h +++ b/include/pocketpy/common.h @@ -172,15 +172,15 @@ struct PyObject; inline PyObject* tag_float(f64 val){ BitsCvt decomposed(val); - unsigned int exp_7b = decomposed._float_bits.exp; - if(exp_7b - BitsCvt::C0 < BitsCvt::C1){ - exp_7b = 0; + int exp_7b = decomposed._float_bits.exp - BitsCvt::C0; + if(exp_7b < BitsCvt::C1){ + exp_7b = BitsCvt::C1 - 1; // -63 + 63 = 0 decomposed._float_bits.mantissa = 0; - }else if(exp_7b - BitsCvt::C0 > BitsCvt::C2){ - exp_7b = BitsCvt::C0; + }else if(exp_7b > BitsCvt::C2){ + exp_7b = BitsCvt::C2 + 1; // 64 + 63 = 127 if(!std::isnan(val)) decomposed._float_bits.mantissa = 0; } - decomposed._float_bits.exp = exp_7b - BitsCvt::C0 + BitsCvt::C2; + decomposed._float_bits.exp = exp_7b + BitsCvt::C2; decomposed._int = (decomposed._int << 1) | 0b01; return reinterpret_cast(decomposed._int); }