Implementation of high/low for SomeReal (#6570)
This commit is contained in:
parent
0895064983
commit
badba83d38
2 changed files with 21 additions and 0 deletions
|
|
@ -2076,6 +2076,9 @@ proc max*[T](x, y: T): T =
|
||||||
if y <= x: x else: y
|
if y <= x: x else: y
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
|
proc high*(T: typedesc[SomeReal]): T = Inf
|
||||||
|
proc low*(T: typedesc[SomeReal]): T = NegInf
|
||||||
|
|
||||||
proc clamp*[T](x, a, b: T): T =
|
proc clamp*[T](x, a, b: T): T =
|
||||||
## limits the value ``x`` within the interval [a, b]
|
## limits the value ``x`` within the interval [a, b]
|
||||||
##
|
##
|
||||||
|
|
|
||||||
18
tests/system/tsystem_misc.nim
Normal file
18
tests/system/tsystem_misc.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
discard """
|
||||||
|
output:""
|
||||||
|
"""
|
||||||
|
|
||||||
|
# check high/low implementations
|
||||||
|
doAssert high(int) > low(int)
|
||||||
|
doAssert high(int8) > low(int8)
|
||||||
|
doAssert high(int16) > low(int16)
|
||||||
|
doAssert high(int32) > low(int32)
|
||||||
|
doAssert high(int64) > low(int64)
|
||||||
|
# doAssert high(uint) > low(uint) # reconsider depending on issue #6620
|
||||||
|
doAssert high(uint8) > low(uint8)
|
||||||
|
doAssert high(uint16) > low(uint16)
|
||||||
|
doAssert high(uint32) > low(uint32)
|
||||||
|
# doAssert high(uint64) > low(uint64) # reconsider depending on issue #6620
|
||||||
|
doAssert high(float) > low(float)
|
||||||
|
doAssert high(float32) > low(float32)
|
||||||
|
doAssert high(float64) > low(float64)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue