Functions 'frexp'-'ldexp' back to the math library

They are basic for anything that handles the representation of
floating numbers.
This commit is contained in:
Roberto I
2025-08-09 15:15:20 -03:00
parent 5b179eaf6a
commit 53dc5a3bba
3 changed files with 46 additions and 17 deletions

View File

@@ -685,6 +685,18 @@ assert(eq(math.exp(0), 1))
assert(eq(math.sin(10), math.sin(10%(2*math.pi))))
do print("testing ldexp/frexp")
global ipairs
for _, x in ipairs{0, 10, 32, -math.pi, 1e10, 1e-10, math.huge, -math.huge} do
local m, p = math.frexp(x)
assert(math.ldexp(m, p) == x)
local am = math.abs(m)
assert(m == x or (0.5 <= am and am < 1))
end
end
assert(tonumber(' 1.3e-2 ') == 1.3e-2)
assert(tonumber(' -1.00000000000001 ') == -1.00000000000001)