diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-05 16:24:59 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-05 16:24:59 -0300 |
| commit | be8120906304a8658fab998587b969e0e42f5650 (patch) | |
| tree | 81cf2d38522b10468d09763fc25d261486008197 /testes/math.lua | |
| parent | e05590591410a5e007a1e3f1691f6c1cf9d8fe45 (diff) | |
| download | lua-be8120906304a8658fab998587b969e0e42f5650.tar.gz lua-be8120906304a8658fab998587b969e0e42f5650.tar.bz2 lua-be8120906304a8658fab998587b969e0e42f5650.zip | |
First implementation of global declarations
Diffstat (limited to 'testes/math.lua')
| -rw-r--r-- | testes/math.lua | 16 |
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 | ||
| 4 | print("testing numbers and math lib") | 4 | print("testing numbers and math lib") |
| 5 | 5 | ||
| 6 | local math = require "math" | ||
| 7 | local string = require "string" | ||
| 8 | |||
| 9 | global none | ||
| 10 | |||
| 11 | global print, assert, pcall, type, pairs, load | ||
| 12 | global tonumber, tostring, select | ||
| 13 | |||
| 6 | local minint <const> = math.mininteger | 14 | local minint <const> = math.mininteger |
| 7 | local maxint <const> = math.maxinteger | 15 | local 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) |
| 431 | end | 439 | end |
| 432 | 440 | ||
| 433 | if not _soft then | 441 | if 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 |
| 635 | if not _port then | 643 | if 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 | ||
| 780 | do | 788 | do |
| 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 |
