diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2025-08-09 15:15:20 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2025-08-09 15:15:20 -0300 |
| commit | 53dc5a3bbadac166a8b40904790f91b351e55dd9 (patch) | |
| tree | e3bab3f52b3db44ade2a21877e874815d126919e /testes/math.lua | |
| parent | 5b179eaf6a78af5f000d76147af94669d04487b2 (diff) | |
| download | lua-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.lua | 12 |
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)) | |||
| 685 | assert(eq(math.sin(10), math.sin(10%(2*math.pi)))) | 685 | assert(eq(math.sin(10), math.sin(10%(2*math.pi)))) |
| 686 | 686 | ||
| 687 | 687 | ||
| 688 | do 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 | |||
| 697 | end | ||
| 698 | |||
| 699 | |||
| 688 | assert(tonumber(' 1.3e-2 ') == 1.3e-2) | 700 | assert(tonumber(' 1.3e-2 ') == 1.3e-2) |
| 689 | assert(tonumber(' -1.00000000000001 ') == -1.00000000000001) | 701 | assert(tonumber(' -1.00000000000001 ') == -1.00000000000001) |
| 690 | 702 | ||
