[libc-commits] [libc] [libc][NFC] Make EXPONENT_BIAS int32_t (PR #75046)

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Mon Dec 11 05:07:10 PST 2023


================
@@ -29,8 +29,9 @@ constexpr int32_t DETAILED_POWERS_OF_TEN_MIN_EXP_10 = -348;
 constexpr int32_t DETAILED_POWERS_OF_TEN_MAX_EXP_10 = 347;
 
 // This rescales the base 10 exponent by a factor of log(10)/log(2).
-LIBC_INLINE int64_t exp10_to_exp2(int64_t exp10) {
-  return (217706 * exp10) >> 16;
+LIBC_INLINE int32_t exp10_to_exp2(int32_t exp10) {
----------------
gchatelet wrote:

This is always called with an `int32_t` and should also return an `int32_t`.
I've highlighted the overflow risk. Note that the risk was already there before this patch, only that it was handled on the callee side.

https://github.com/llvm/llvm-project/pull/75046


More information about the libc-commits mailing list