Make NaN equal NaN

This commit is contained in:
Emery Hemingway 2023-12-22 22:16:59 +02:00
parent 75916ea0dd
commit cf5efb7d86
1 changed files with 8 additions and 3 deletions

View File

@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/[hashes, options, sets, sequtils, tables]
import std/[hashes, math, options, sets, sequtils, tables]
import bigints
@ -56,6 +56,11 @@ type
DictEntry*[E] = tuple[key: Preserve[E], val: Preserve[E]]
func `===`[T: SomeFloat](a, b: T): bool =
## Compare where Nan == NaN.
let class = a.classify
(class == b.classify) and ((class notin {fcNormal,fcSubnormal}) or (a == b))
func `==`*[A, B](x: Preserve[A]; y: Preserve[B]): bool =
## Check `x` and `y` for equivalence.
if x.kind == y.kind and x.embedded == y.embedded:
@ -63,9 +68,9 @@ func `==`*[A, B](x: Preserve[A]; y: Preserve[B]): bool =
of pkBoolean:
result = x.bool == y.bool
of pkFloat:
result = x.float == y.float
result = x.float === y.float
of pkDouble:
result = x.double == y.double
result = x.double === y.double
of pkRegister:
result = x.register == y.register
of pkBigInt: