From 53dc5a3bbadac166a8b40904790f91b351e55dd9 Mon Sep 17 00:00:00 2001 From: Roberto I Date: Sat, 9 Aug 2025 15:15:20 -0300 Subject: Functions 'frexp'-'ldexp' back to the math library They are basic for anything that handles the representation of floating numbers. --- testes/math.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'testes/math.lua') diff --git a/testes/math.lua b/testes/math.lua index 0d228d09..54d19c40 100644 --- a/testes/math.lua +++ b/testes/math.lua @@ -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) -- cgit v1.2.3-55-g6feb