[m-rev.] for review: add int32.clamp/3
Peter Wang
novalazy at gmail.com
Wed Mar 4 13:06:00 AEDT 2026
On Wed, 04 Mar 2026 12:13:37 +1100 Julien Fischer <jfischer at opturion.com> wrote:
> For review by anyone.
>
> I intend to add the clamp/3 to all of the integer modules. I will add
> it for the others
> after this change is reviewed.
>
> -----------------------
>
> Add int32.clamp/3.
>
> library/int32.m:
> Add the new function.
> diff --git a/library/int32.m b/library/int32.m
> index bc8f526fa..6f4d6b73c 100644
> --- a/library/int32.m
> +++ b/library/int32.m
> @@ -189,6 +189,14 @@
> %
> :- func min(int32, int32) = int32.
>
> + % clamp(Min, Max, N):
> + %
> + % Clamp N to the range [Min, Max] (inclusive).
> + % Returns Min if N < Min, Max if N > Max, and N otherwise.
> + % Throws an exception if Max < Min.
> + %
> +:- func clamp(int32, int32, int32) = int32.
> +
I suppose this is the obvious order for partial application.
Labelled arguments?
:- type range ---> range.
:- type value ---> value.
:- func clamp(range, int32, int32, value, int32) = int32.
;)
The diff looks fine.
Peter
More information about the reviews
mailing list