Skip to content

Conversation

lucioleKi
Copy link
Contributor

Add guard BIF erlang:is_integer/3, following the design of the original EEP-16, only changing the name from is_between to is_integer. This BIF takes in 3 parameters, Term, LowerBound, and UpperBound.
It returns true if Term, LowerBound, and UpperBound are all integers, and LowerBound =< Term =< UpperBound; otherwise, it returns false.

Failure: badarg if LowerBound or UpperBound does not evaluate to an integer.

Example:

1> is_integer(2, 1, 10).
true
2> is_integer(11, 1, 10).
false
3> is_integer(1, 1.0, 10.0).
** exception error: bad argument
     in function  is_integer/3
        called as is_integer(1,1.0,10.0)

We decide to not update and reuse the previous PR because the name of the BIF has changed.

Add guard BIF `erlang:is_integer/3`, following the design of the
original EEP-16, only changing the name from `is_between` to
`is_integer`. This BIF takes in 3 parameters, `Term`, `LowerBound`,
and `UpperBound`.
It returns `true` if `Term`, `LowerBound`, and `UpperBound` are
all integers, and `LowerBound =< Term =< UpperBound`; otherwise,
it returns false.

Failure: `badarg` if `LowerBound` or `UpperBound` does not evaluate to
an integer.

Example:

````
1> is_integer(2, 1, 10).
true
2> is_integer(11, 1, 10).
false
3> is_integer(1, 1.0, 10.0).
** exception error: bad argument
     in function  is_integer/3
        called as is_integer(1,1.0,10.0)
````

Co-authored-by: Björn Gustavsson <bjorn@erlang.org>
Co-authored-by: John Högberg <john@erlang.org>
@lucioleKi lucioleKi self-assigned this Oct 13, 2025
@lucioleKi lucioleKi added the team:VM Assigned to OTP team VM label Oct 13, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 13, 2025

CT Test Results

     7 files     635 suites   3h 13m 41s ⏱️
 6 275 tests  5 834 ✅ 441 💤 0 ❌
12 561 runs  12 035 ✅ 526 💤 0 ❌

Results for commit a211a3a.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

Comment on lines 2295 to 2303
infer_types_1(#value{op={bif,is_integer},args=[Src, _, _]}, Val, Op, Vst) ->
%% Unknown bounds; we know it's an integer when 'true', but cannot draw
%% any conclusions when 'false'.
case Val of
{atom, Bool} when Op =:= eq_exact, Bool; Op =:= ne_exact, not Bool ->
update_type(fun meet/2, #t_integer{}, Src, Vst);
_ ->
Vst
end;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to narrow the range if just one of the bounds is a literal - I think we would do that with comparisons today, so converting them to is_integer guard would remove information from the compiler

@lucioleKi lucioleKi force-pushed the isabell/erts/is-integer-3/OTP-19809 branch from 2fbafae to a211a3a Compare October 22, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants