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