[m-rev.] for review: add int32.clamp/3

Zoltan Somogyi zoltan.somogyi at runbox.com
Wed Mar 4 15:46:59 AEDT 2026



On Wed, 4 Mar 2026 12:13:37 +1100, Julien Fischer <jfischer at opturion.com> wrote:
> For review by anyone.

Sorry for the late review, but I didn't have a chance until now.

> Add int32.clamp/3.

I would prefer for this function to have a more expressive name;
clamp_into_range, perhaps.

> +clamp(Min, Max, N) =
> +    ( if Max >= Min then
> +        max(Min, min(Max, N))
> +    else
> +        func_error($pred, "Max < Min")
> +    ).

I would replace the calls to max and min with

( if N < Min then Min else if N > Max then Max else N )

It is longer, but it is easier to understand, and should also be faster.

Zoltan.


More information about the reviews mailing list