Add stew/saturation_arith
This commit is contained in:
parent
1e86bd1ef3
commit
018760954a
|
@ -0,0 +1,8 @@
|
|||
## This module may hold various saturating arithmetic definitions.
|
||||
## It will be expanded on demand as more definitions are requred.
|
||||
|
||||
func saturate*(T: type int64, u: uint64): T =
|
||||
if u > high(int64).uint64:
|
||||
high(int64)
|
||||
else:
|
||||
int64(u)
|
|
@ -0,0 +1,8 @@
|
|||
## This module may hold various saturating arithmetic definitions.
|
||||
## It will be expanded on demand as Status project require its definition
|
||||
|
||||
func saturate*(T: type int64, u: uint64): T =
|
||||
if u > high(int64).uint64:
|
||||
high(int64)
|
||||
else:
|
||||
int64(u)
|
Loading…
Reference in New Issue