diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-09-02 11:21:26 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-09-02 11:21:26 +0200 |
commit | 3d4ad9739cb2055bb037e9795fae7e015dc186e4 (patch) | |
tree | 37cca8d5888d772f310466464309295ae51c6842 /lib | |
parent | ad82e65387f39970b0f12cbcb12d8b382236f3da (diff) | |
download | Nim-3d4ad9739cb2055bb037e9795fae7e015dc186e4.tar.gz |
fix min/max for float numbers (#12068)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system.nim | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/system.nim b/lib/system.nim index 6b1421160..05dc43ab2 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2880,17 +2880,21 @@ proc max*[T](x: openArray[T]): T = for i in 1..high(x): if result < x[i]: result = x[i] -proc abs*(x: float): float {.magic: "AbsF64", noSideEffect.} = +proc abs*(x: float64): float64 {.noSideEffect, inline.} = if x < 0.0: -x else: x -proc min*(x, y: float): float {.magic: "MinF64", noSideEffect.} = - if x <= y: x else: y -proc max*(x, y: float): float {.magic: "MaxF64", noSideEffect.} = - if y <= x: x else: y - -proc min*[T](x, y: T): T {.inline.}= +proc abs*(x: float32): float32 {.noSideEffect, inline.} = + if x < 0.0: -x else: x +proc min*(x, y: float32): float32 {.noSideEffect, inline.} = + if x <= y or y != y: x else: y +proc min*(x, y: float64): float64 {.noSideEffect, inline.} = + if x <= y or y != y: x else: y +proc max*(x, y: float32): float32 {.noSideEffect, inline.} = + if y <= x or y != y: x else: y +proc max*(x, y: float64): float64 {.noSideEffect, inline.} = + if y <= x or y != y: x else: y +proc min*[T: not SomeFloat](x, y: T): T {.inline.} = if x <= y: x else: y - -proc max*[T](x, y: T): T {.inline.}= +proc max*[T: not SomeFloat](x, y: T): T {.inline.} = if y <= x: x else: y {.pop.} |