vlib/math/math_test.v fails on Alpine

Created on 10 Nov 2019  路  4Comments  路  Source: vlang/v

V version: V 0.1.22 3d4f850
OS: Alpine Linux

What did you do?

Compile V and run the tests on an Alpine Docker Image:

docker run --rm -it alpine
/ # apk add -U git make gcc libc-dev
/ # git clone https://github.com/vlang/v
/ # cd v
/v # make
/v # ./v test vlib/math/math_test.v
Testing...
   485 ms | vlib/math/math_test.v FAIL
`/v/vlib/math/math_test.v`
 (
/v/vlib/math/math_test.v:49: FAILED assertion
Function: test_gamma()
Source  :    assert math.log_gamma(4.5) == math.log(math.gamma(4.5))
)
----------------------------------------------------------------------------
   485 ms | <=== total time spent running V _test.v files
 ok, fail, total =     0,     1,     1

What did you expect to see?

Expected the test to pass.

What did you see instead?

I think this is a floating point arithmetic issue.

Changing the assertion to the following causes the test to pass:

x := math.log_gamma(4.5)
y := math.log(math.gamma(4.5))
assert math.abs(x - y) < 0.000000000000001

While if we go one order of magnitude smaller, we fail:

assert math.abs(x - y) < 0.0000000000000001
Bug

All 4 comments

Thanks for the detailed report.

I've set up a CI for musl, need to enable tests on it.

Oh man this was bugging me for a bit because I couldn't reproduce it when using musl on any other system. Then I remembered versions matters.

The alpine:latest image is currently alpine:3.10 which uses musl-dev-1.1.22-r3 (see https://pkgs.alpinelinux.org/package/v3.10/main/x86/musl-dev).

However, musl only refactored its math functions for performance in v1.1.23 (see https://git.musl-libc.org/cgit/musl/tree/WHATSNEW?h=v1.1.23#n2094).

We can use a later version by pulling from the edge repo when adding musl-dev:

docker run --rm -it alpine:3.10
/ # apk add -U git make gcc
/ # apk add -X http://dl-cdn.alpinelinux.org/alpine/edge/main musl-dev
/ # git clone https://github.com/vlang/v
/ # cd v
/v # make
/v # ./v test vlib/math/math_test.v

This will install musl-dev-1.1.24-r0 and passes the test. :-)

Fixed and added to CI.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

medvednikov picture medvednikov  路  3Comments

ArcDrake picture ArcDrake  路  3Comments

cjmxp picture cjmxp  路  3Comments

aurora picture aurora  路  3Comments

XVilka picture XVilka  路  3Comments