SWI-Prolog / swipl-devel

SWI-Prolog Main development repository
http://www.swi-prolog.org
Other
982 stars 176 forks source link

ieee/rational test failures on OpenBSD #1267

Open vext01 opened 7 months ago

vext01 commented 7 months ago

Hi there,

I've just encountered these test failures when updating the OpenBSD package to version 9.2.3:

...
31: % [39/45] ieee754:ieee_nexttoward ..................................................................................................................................................... **FAILED (0.117 sec)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:491:
31: ERROR:     test ieee754:ieee_nexttoward: assertion
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:491:
31: ERROR:     test ieee754:ieee_nexttoward: assertion at line 494 failed
31:     Assertion: -1.0Inf<nexttoward(-inf,inf)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:491:
31: ERROR:     test ieee754:ieee_nexttoward: assertion at line 495 failed
31:     Assertion: 1.0Inf>nexttoward(inf,-inf)
...
31: % [42/45] ieee754:ieee_rmode .......................................................................................................................................................... **FAILED (0.021 sec)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:527:
31: ERROR:     test ieee754:ieee_rmode: assertion
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:527:
31: ERROR:     test ieee754:ieee_rmode: assertion at line 532 failed
31:     Assertion: plunit_ieee754:test_rounding(exp(log(2)))
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:527:
31: ERROR:     test ieee754:ieee_rmode: assertion at line 533 failed
31:     Assertion: plunit_ieee754:test_rounding(-2.0**1r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:527:
31: ERROR:     test ieee754:ieee_rmode: assertion at line 534 failed
31:     Assertion: plunit_ieee754:test_rounding(2.0**1r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:527:
31: ERROR:     test ieee754:ieee_rmode: assertion at line 535 failed
31:     Assertion: plunit_ieee754:test_rounding(pi)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:527:
31: ERROR:     test ieee754:ieee_rmode: assertion at /usr/local/pobj/swi-prolog-9.2.3/build-amd64/home/boot/init.pl:685 failed
31:     Assertion: plunit_ieee754:test_rounding(e)
31: 
31: % [43/45] ieee754:float_to_rat .......................................................................................................................................................... passed (0.000 sec)
31: % [44/45] ieee754:ieee_rndto .......................................................................................................................................................... **FAILED (0.158 sec)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 555 failed
31:     Assertion: plunit_ieee754:test_roundto(exp(log(2)))
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 556 failed
31:     Assertion: plunit_ieee754:test_roundto(2**0.5)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 557 failed
31:     Assertion: plunit_ieee754:test_roundto(-2.0002**2)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 558 failed
31:     Assertion: plunit_ieee754:test_roundto(2.0002**2)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 559 failed
31:     Assertion: plunit_ieee754:test_roundto(2.0002**1r2)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 560 failed
31:     Assertion: plunit_ieee754:test_roundto(-2.0002**1r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 561 failed
31:     Assertion: plunit_ieee754:test_roundto(2.0002**1r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 562 failed
31:     Assertion: plunit_ieee754:test_roundto(-2.0002**2r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 563 failed
31:     Assertion: plunit_ieee754:test_roundto(2.0002**2r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 564 failed
31:     Assertion: plunit_ieee754:test_roundto(0.0002**1r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 565 failed
31:     Assertion: plunit_ieee754:test_roundto(-0.0002**1r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 566 failed
31:     Assertion: plunit_ieee754:test_roundto(0.0002**2r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 567 failed
31:     Assertion: plunit_ieee754:test_roundto(-0.0002**2r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 568 failed
31:     Assertion: plunit_ieee754:test_roundto(0.0002** -1r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 569 failed
31:     Assertion: plunit_ieee754:test_roundto(-2.0002** -1r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 570 failed
31:     Assertion: plunit_ieee754:test_roundto(0.0002** -2r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 571 failed
31:     Assertion: plunit_ieee754:test_roundto(-2.0002** -2r3)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 572 failed
31:     Assertion: plunit_ieee754:test_roundto(pi)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 573 failed
31:     Assertion: plunit_ieee754:test_roundto(e)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 574 failed
31:     Assertion: plunit_ieee754:test_roundto(sin(pi/2))
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 575 failed
31:     Assertion: plunit_ieee754:test_roundto(atan2(1,-1))
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 576 failed
31:     Assertion: plunit_ieee754:test_roundto(cosh(-0.5))
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 586 failed
31:     Assertion: plunit_ieee754:test_roundto(float(36893488147419103232+1))
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 587 failed
31:     Assertion: plunit_ieee754:test_roundto(float(- (36893488147419103232+1)))
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 588 failed
31:     Assertion: plunit_ieee754:test_roundto(float(36893488147419103232-1))
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:550:
31: ERROR:     test ieee754:ieee_rndto: assertion at line 589 failed
31:     Assertion: plunit_ieee754:test_roundto(float(- (36893488147419103232-1)))
31:
31: % [45/45] ieee754:bounded ............................................................................................................................................................. **FAILED (0.012 sec)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:598:
31: ERROR:     test ieee754:bounded: assertion
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:598:
31: ERROR:     test ieee754:bounded: assertion at line 611 failed
31:     Assertion: bounded_number(_2024,_2026,-1.0),[_2024,_2026]=[-1.0000000000000002,-0.9999999999999999]
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl:598:
31: ERROR:     test ieee754:bounded: assertion at line 612 failed
31:     Assertion: bounded_number(_2024,_2026,-1r2),[_2024,_2026]=[-0.5000000000000001,-0.49999999999999994]
31:
31: ERROR: 4 tests failed
31: Script /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_ieee754.pl failed
...
31: % [14/15] rationalize:roundtrip_rational .............................................................................................................................................. **FAILED (0.010 sec)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_rational.pl:202:
31: ERROR:     test rationalize:roundtrip_rational: received error: is/2: Arithmetic: evaluation error: `float_overflow'
31: % [15/15] rationalize:roundtrip_rationalize ........................................................................................................................................... **FAILED (0.000 sec)
31: ERROR: /usr/local/pobj/swi-prolog-9.2.3/swipl-9.2.3/src/Tests/rational/test_rational.pl:206:
31: ERROR:     test rationalize:roundtrip_rationalize: received error: is/2: Arithmetic: evaluation error: `float_overflow'
31: ERROR: 2 tests failed
...

This was on amd64.

(I also have some patches for the SSL module (to make it work with a recent LibreSSL), which I can share if you are interested)

Thanks

JanWielemaker commented 7 months ago

Hmm. Looks like big time problem with float rounding. Not much of a problem for 99% of the Prolog code, but correct rounding is needed for e.g., the clpBNR package. Could be compiler flags. I think gcc has a flag to choose between fast and correct floats. You may have a look at that. Another source of problems are broken libm implementations, but it seems this also involves things where libm is not used.

And yes, for ssl, please raise an issue or send a PR. Thanks!

vext01 commented 7 months ago

gcc

amd64 uses clang by default. I've just checked and it's:

penBSD clang version 16.0.6
Target: amd64-unknown-openbsd7.5
Thread model: posix
InstalledDir: /usr/bin

Here's a build log. Do you see any suspicious flags in the invocations on the files that'd matter for those test failures? https://theunixzoo.co.uk/random/swipl-log.txt

I notice:

-- llround(nextoward(0.5),-10) == 1 (broken)

Is that relevant?

JanWielemaker commented 7 months ago

amd64 uses clang by default

That is bad luck. SWI-Prolog's performance using GCC is quite a bit better on x64 (~30%)

It doesn't use any interesting flags.

Is that relevant?

Looks like a symptom. There is a work-around in the code for particular bugs in nexttoward(), but apparently not the one in OpenBSD. Seems there is something big scale wrong with IEEE float rounding. Unfortunately it is an area that is often not taken serious as very few applications rely on it. That also applies to Prolog applications; very few are affected by this not working.

The best way out is probably to concentrate on one failing test, turn it into a small C program that reproduces the issue and raise it upstream. That shouldn't be too hard. All the arithmetic is in src/pl-arith.c.

Is the previous OpenBSD port so old that it predates SWI-Prolog's IEEE float support?