aboutsummaryrefslogtreecommitdiff
path: root/testes/math.lua
diff options
context:
space:
mode:
Diffstat (limited to 'testes/math.lua')
-rw-r--r--testes/math.lua16
1 files changed, 13 insertions, 3 deletions
diff --git a/testes/math.lua b/testes/math.lua
index 88a57ce7..242579b1 100644
--- a/testes/math.lua
+++ b/testes/math.lua
@@ -3,6 +3,14 @@
3 3
4print("testing numbers and math lib") 4print("testing numbers and math lib")
5 5
6local math = require "math"
7local string = require "string"
8
9global none
10
11global print, assert, pcall, type, pairs, load
12global tonumber, tostring, select
13
6local minint <const> = math.mininteger 14local minint <const> = math.mininteger
7local maxint <const> = math.maxinteger 15local maxint <const> = math.maxinteger
8 16
@@ -184,7 +192,7 @@ do
184 for i = -3, 3 do -- variables avoid constant folding 192 for i = -3, 3 do -- variables avoid constant folding
185 for j = -3, 3 do 193 for j = -3, 3 do
186 -- domain errors (0^(-n)) are not portable 194 -- domain errors (0^(-n)) are not portable
187 if not _port or i ~= 0 or j > 0 then 195 if not _ENV._port or i ~= 0 or j > 0 then
188 assert(eq(i^j, 1 / i^(-j))) 196 assert(eq(i^j, 1 / i^(-j)))
189 end 197 end
190 end 198 end
@@ -430,7 +438,7 @@ for i = 2,36 do
430 assert(tonumber('\t10000000000\t', i) == i10) 438 assert(tonumber('\t10000000000\t', i) == i10)
431end 439end
432 440
433if not _soft then 441if not _ENV._soft then
434 -- tests with very long numerals 442 -- tests with very long numerals
435 assert(tonumber("0x"..string.rep("f", 13)..".0") == 2.0^(4*13) - 1) 443 assert(tonumber("0x"..string.rep("f", 13)..".0") == 2.0^(4*13) - 1)
436 assert(tonumber("0x"..string.rep("f", 150)..".0") == 2.0^(4*150) - 1) 444 assert(tonumber("0x"..string.rep("f", 150)..".0") == 2.0^(4*150) - 1)
@@ -632,7 +640,7 @@ assert(maxint % -2 == -1)
632 640
633-- non-portable tests because Windows C library cannot compute 641-- non-portable tests because Windows C library cannot compute
634-- fmod(1, huge) correctly 642-- fmod(1, huge) correctly
635if not _port then 643if not _ENV._port then
636 local function anan (x) assert(isNaN(x)) end -- assert Not a Number 644 local function anan (x) assert(isNaN(x)) end -- assert Not a Number
637 anan(0.0 % 0) 645 anan(0.0 % 0)
638 anan(1.3 % 0) 646 anan(1.3 % 0)
@@ -779,6 +787,7 @@ assert(a == '10' and b == '20')
779 787
780do 788do
781 print("testing -0 and NaN") 789 print("testing -0 and NaN")
790 global rawset, undef
782 local mz <const> = -0.0 791 local mz <const> = -0.0
783 local z <const> = 0.0 792 local z <const> = 0.0
784 assert(mz == z) 793 assert(mz == z)
@@ -1074,6 +1083,7 @@ do
1074 -- different numbers should print differently. 1083 -- different numbers should print differently.
1075 -- check pairs of floats with minimum detectable difference 1084 -- check pairs of floats with minimum detectable difference
1076 local p = floatbits - 1 1085 local p = floatbits - 1
1086 global ipairs
1077 for i = 1, maxexp - 1 do 1087 for i = 1, maxexp - 1 do
1078 for _, i in ipairs{-i, i} do 1088 for _, i in ipairs{-i, i} do
1079 local x = 2^i 1089 local x = 2^i