-
Notifications
You must be signed in to change notification settings - Fork 3k
erts: Add guard BIF erlang:is_integer/3
#10276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
erts: Add guard BIF erlang:is_integer/3
#10276
Conversation
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>
CT Test Results 7 files 635 suites 3h 13m 41s ⏱️ 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 |
lib/compiler/src/beam_validator.erl
Outdated
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; |
There was a problem hiding this comment.
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
2fbafae
to
a211a3a
Compare
Add guard BIF
erlang:is_integer/3
, following the design of the original EEP-16, only changing the name fromis_between
tois_integer
. This BIF takes in 3 parameters,Term
,LowerBound
, andUpperBound
.It returns
true
ifTerm
,LowerBound
, andUpperBound
are all integers, andLowerBound =< Term =< UpperBound
; otherwise, it returns false.Failure:
badarg
ifLowerBound
orUpperBound
does not evaluate to an integer.Example:
We decide to not update and reuse the previous PR because the name of the BIF has changed.