nim-stew/stew/saturating_arith.nim

9 lines
246 B
Nim
Raw Normal View History

2022-08-18 20:57:27 +00:00
## 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)