aboutsummaryrefslogtreecommitdiff
path: root/testes/math.lua
diff options
context:
space:
mode:
authorRoberto I <roberto@inf.puc-rio.br>2025-08-09 15:15:20 -0300
committerRoberto I <roberto@inf.puc-rio.br>2025-08-09 15:15:20 -0300
commit53dc5a3bbadac166a8b40904790f91b351e55dd9 (patch)
treee3bab3f52b3db44ade2a21877e874815d126919e /testes/math.lua
parent5b179eaf6a78af5f000d76147af94669d04487b2 (diff)
downloadlua-53dc5a3bbadac166a8b40904790f91b351e55dd9.tar.gz
lua-53dc5a3bbadac166a8b40904790f91b351e55dd9.tar.bz2
lua-53dc5a3bbadac166a8b40904790f91b351e55dd9.zip
Functions 'frexp'-'ldexp' back to the math library
They are basic for anything that handles the representation of floating numbers.
Diffstat (limited to 'testes/math.lua')
-rw-r--r--testes/math.lua12
1 files changed, 12 insertions, 0 deletions
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))
685assert(eq(math.sin(10), math.sin(10%(2*math.pi)))) 685assert(eq(math.sin(10), math.sin(10%(2*math.pi))))
686 686
687 687
688do print("testing ldexp/frexp")
689 global ipairs
690 for _, x in ipairs{0, 10, 32, -math.pi, 1e10, 1e-10, math.huge, -math.huge} do
691 local m, p = math.frexp(x)
692 assert(math.ldexp(m, p) == x)
693 local am = math.abs(m)
694 assert(m == x or (0.5 <= am and am < 1))
695 end
696
697end
698
699
688assert(tonumber(' 1.3e-2 ') == 1.3e-2) 700assert(tonumber(' 1.3e-2 ') == 1.3e-2)
689assert(tonumber(' -1.00000000000001 ') == -1.00000000000001) 701assert(tonumber(' -1.00000000000001 ') == -1.00000000000001)
690 702