[m-rev.] for review: add int32.clamp/3
Julien Fischer
jfischer at opturion.com
Wed Mar 4 16:02:50 AEDT 2026
On Wed, 4 Mar 2026 at 15:47, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
>
> 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.
I'm not overly fussed. clamp is the usual name for this operation in
programming languages that provide it, so I went with that.
Peter, do you have a preference?
> > +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.
Ok, shall do.
Julien.
More information about the reviews
mailing list