lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, 5 Jan 2015 09:20:36 -0200
Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:

> This error is probably due to a poor implementation of 'pow'. (That
> is why we do not distribute the test suite with Lua; it is too much
> sensitive to the libc.)
> 
> You might change that line to
>         print(i, j, i^j, 1 / i^(-j)); assert(eq(i^j, 1 / i^(-j)))
> to see what is going on.
> 

You are right, looks like pow() does strange things with a base of zero:

***** FILE 'math.lua'*****
.testing numbers and math lib
64-bit integers, 53-bit (mantissa) floats
-3      -3      -0.037037037037037      -0.037037037037037
-3      -2      0.11111111111111        0.11111111111111
-3      -1      -0.33333333333333       -0.33333333333333
-3      0       1.0     1.0
-3      1       -3.0    -3.0
-3      2       9.0     9.0
-3      3       -27.0   -27.0
-2      -3      -0.125  -0.125
-2      -2      0.25    0.25
-2      -1      -0.5    -0.5
-2      0       1.0     1.0
-2      1       -2.0    -2.0
-2      2       4.0     4.0
-2      3       -8.0    -8.0
-1      -3      -1.0    -1.0
-1      -2      1.0     1.0
-1      -1      -1.0    -1.0
-1      0       1.0     1.0
-1      1       -1.0    -1.0
-1      2       1.0     1.0
-1      3       -1.0    -1.0
0       -3      -inf    inf
/usr/local/bin/lua: math.lua:155: assertion failed!
stack traceback:
        [C]: in function 'assert'
        math.lua:155: in main chunk
        (...tail calls...)
        all.lua:177: in main chunk
        [C]: in ?
.>>> closing state <<<


I also tried it on NetBSD/amd64 and got the same error, so almost
certainly libc and not sparc weirdness.

If I put an if statement around that assert to exclude zero
base exponents, I get the final OK.

-- 
Aaron B. <aaron@zadzmo.org>