mirror of
https://github.com/status-im/nim-stew.git
synced 2025-02-13 12:36:57 +00:00
Add stew/saturation_arith
This commit is contained in:
parent
1e86bd1ef3
commit
018760954a
8
stew/saturating_arith.nim
Normal file
8
stew/saturating_arith.nim
Normal file
@ -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)
|
8
stew/saturation_arith.nim
Normal file
8
stew/saturation_arith.nim
Normal file
@ -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…
x
Reference in New Issue
Block a user