Basic module

clamp_to_another_integer_type

procedureSource

Converts value to TargetType, using the nearest value that fits when it is out of range, where a plain cast would wrap.

clamp_to_another_integer_type :: (
    value: $SourceType,
    $TargetType: Type
) -> TargetType

Parameters

value: $SourceType
$TargetType: Type

Returns

TargetType
Example↗
big := 1000;
assert(clamp_to_another_integer_type(big, u8) == 255);
assert(clamp_to_another_integer_type(-5, u8) == 0);
assert(clamp_to_another_integer_type(100, u8) == 100);

See also