From 859d617138db36e38cf68b5caf5d8f7905742b88 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Tue, 30 Mar 2021 18:06:58 +0200 Subject: [PATCH] Fix math.fround --- math.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/math.lua b/math.lua index 3e7afc3..e2be3b2 100644 --- a/math.lua +++ b/math.lua @@ -61,12 +61,11 @@ function fround(number) number = -number end local exp = math.floor(math.log(number, 2)) - local powexp = 2 ^ math.max(-126, math.min(number, 127)) + local powexp = 2 ^ math.max(-126, math.min(exp, 127)) local leading = exp < -127 and 0 or 1 local mantissa = math.floor((leading - number / powexp) * 0x800000 + 0.5) if mantissa <= -0x800000 then return sign * math.huge end - mantissa = mantissa / 0x800000 - return sign * powexp * (leading - mantissa), mantissa + return sign * powexp * (leading - mantissa / 0x800000) end \ No newline at end of file