haskell / vector

An efficient implementation of Int-indexed arrays (both mutable and immutable), with a powerful loop optimisation framework .
Other
360 stars 141 forks source link

Tests fail when built against QuickCheck-2.14.3 #460

Closed Bodigrim closed 1 year ago

Bodigrim commented 1 year ago
Test suite vector-tests-O2: RUNNING...
toplevel
  Tests.Vector.Unboxed
    (Float)
      product:                                   FAIL
        *** Failed! Falsified (after 60 tests):
        [32.0,-18.487179,-46.0,4.0,1.3333334,-0.33333334,-19.0,-32.022728,1.6666666,0.4007722,45.192307,0.375,-49.0,45.210526,27.458334,16.0,33.97059,-18.466667,57.939392,-40.0,-18.0,0.81411356,-7.0,-9.222222,-0.25,-17.0,31.85965,-0.5714286,58.6,-38.01695,0.2850433,6.1225712e-2,0.75,46.0,19.666666,-13.0,-0.3773585,18.5,20.0,0.8629303,0.7045016,18.458334,0.18349916,1.125,32.06,-41.757576,-47.0,20.8,-31.714285,-41.363636,-11.896552,0.0,-19.0]
        NaN /= NaN
        Use --quickcheck-replay=745456 to reproduce.
        Use -p '/(Float).product/' to rerun this test only.
Shimuuar commented 1 year ago

This has nothing to do with QC version. Just usual floating point shenanigans. Single precision float is not difficult to overflow with maximum finite number of about 1e38. In this example multiplication first overflows to infinity and then is multiplied by zero (second to last) getting NaN.

I guess we should use newtype wrapper over floats for which NaN==NaN = True

Bodigrim commented 1 year ago

QuickCheck-2.14.3 changed instance Arbitrary Float to generate more "interesting" numbers, thus increasing chances of this fault to almost 100%.