Closed tixxit closed 7 years ago
For whatever reason, the fromDouble
test is failing for FPApprox[Float]
and FPApprox[Double]
on JS only. The values I'm getting make no sense and it seems suspiciously like a bug in BigInt
. Need to investigate further...
@@ master #192 diff @@
==========================================
Files 36 36
Lines 766 769 +3
Methods 713 708 -5
Messages 0 0
Branches 53 61 +8
==========================================
+ Hits 541 569 +28
+ Misses 225 200 -25
Partials 0 0
Powered by Codecov. Last update baa32ef...22a3743
So, this is because the fromDouble
test uses BigDecimal
, which is apparently broken on scalajs. I'm going to skip the tests if Platform.isJVM
is false, which should be OK for now. If BigDecimal gets unbroken, we can re-enable.
👍
This tests the
Field
instances forFloat
,Double
andBigDecimal
in a bit of a sneaky way. Rather than test them directly, it uses aFPApprox
wrapper type. This exercises the underlyingField
to handle the regular operations, but also maintains an error bound on the approximation. TheEq
instance forFPApprox[A]
will return true for any 2 numbers that could be equal, given their error bounds. Of course, there are more subtleties than that:The numbers occasionally underflow, which causes all sorts of annoying problems. So, we also have to occasionally check if values after multiplications are near-zero and, if so, bump them back up to a very small, but useable number.
The numbers occasionally overflow to infinity, at which point the game is lost, since we soon start getting NaNs. So, we also return
true
if a comparison gets us into non-finite number territory.