Skip to content

Commit

Permalink
Fix a bug in compile-time evaluation.
Browse files Browse the repository at this point in the history
compiler/uint_emu.m:
    Fix the bounds check for valid uint values.

compiler/{int,uint}_emu.m:
    Use integer.two/0 in a few spots.
  • Loading branch information
juliensf committed Apr 19, 2023
1 parent a959c47 commit 8e1b91e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions compiler/int_emu.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@
:- pred to_int_in_range(bits_per_int::in, integer::in, int::out) is semidet.

to_int_in_range(bits_per_int(BitsPerInt), Integer, Int) :-
Integer >= -pow(integer(2), integer(BitsPerInt - 1)),
Integer =< pow(integer(2), integer(BitsPerInt - 1)) - one,
Integer >= -pow(integer.two, integer(BitsPerInt - 1)),
Integer =< pow(integer.two, integer(BitsPerInt - 1)) - one,
integer.to_int(Integer, Int).

%----------------------------------------------------------------------------%
Expand Down
2 changes: 1 addition & 1 deletion compiler/uint_emu.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@

to_uint_in_range(bits_per_uint(BitsPerUInt), Integer, UInt) :-
Integer >= integer.zero,
Integer =< pow(integer(2), integer(BitsPerUInt)),
Integer < pow(integer.two, integer(BitsPerUInt)),
integer.to_uint(Integer, UInt).

%----------------------------------------------------------------------------%
Expand Down

0 comments on commit 8e1b91e

Please sign in to comment.