Add stew/saturation_arith

This commit is contained in:
Zahary Karadjov 2022-08-18 23:57:27 +03:00
parent 1e86bd1ef3
commit 018760954a
No known key found for this signature in database
GPG Key ID: C1F42EAFF38D570F
2 changed files with 16 additions and 0 deletions

View 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)

View 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)