Add Complex version of almostEqual function (#23549)

This adds a version of `almostEqual` (which was already available for
floats) thata works with `Complex[SomeFloat]`.

Proof that this is needed is that the first thing that the complex.nim
runnable examples block did before this commit was define (an
incomplete) `almostEqual` function that worked with complex values.
This commit is contained in:
Angel Ezquerra
2024-05-08 22:53:01 +02:00
committed by GitHub
parent 09bd9d0b19
commit d8e1504ed1
2 changed files with 21 additions and 3 deletions

View File

@@ -84,6 +84,9 @@ let t = polar(a)
doAssert(rect(t.r, t.phi) =~ a)
doAssert(rect(1.0, 2.0) =~ complex(-0.4161468365471424, 0.9092974268256817))
doAssert(almostEqual(a, a + complex(1e-16, 1e-16)))
doAssert(almostEqual(a, a + complex(2e-15, 2e-15), unitsInLastPlace = 5))
let
i64: Complex32 = complex(0.0f, 1.0f)