Skip to content

Commit c1f00fc

Browse files
committed
Support boxed numbers
Signed-off-by: Jakub Gonet <jakub.gonet@swmansion.com>
1 parent d0207c1 commit c1f00fc

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

src/libAtomVM/bif.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,13 +864,10 @@ term bif_erlang_mul_2(Context *ctx, uint32_t fail_label, int live, term arg1, te
864864
term bif_erlang_fdiv_2(Context *ctx, uint32_t fail_label, int live, term arg1, term arg2)
865865
{
866866
UNUSED(live);
867-
if (!term_is_integer(arg1) && !term_is_float(arg1)) {
868-
TRACE("error: arg1: 0x%lx, arg2: 0x%lx\n", arg1, arg2);
867+
if (UNLIKELY(!term_is_number(arg1))) {
869868
RAISE_ERROR_BIF(fail_label, BADARITH_ATOM);
870869
}
871-
872-
if (!term_is_integer(arg2) && !term_is_float(arg2)) {
873-
TRACE("error: arg1: 0x%lx, arg2: 0x%lx\n", arg1, arg2);
870+
if (UNLIKELY(!term_is_number(arg2))) {
874871
RAISE_ERROR_BIF(fail_label, BADARITH_ATOM);
875872
}
876873
avm_float_t farg1 = term_conv_to_float(arg1);

tests/erlang_tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ compile_erlang(floatabs)
389389
compile_erlang(floatdiv)
390390
compile_erlang(floatmath)
391391
compile_erlang(floatext)
392+
compile_erlang(bif_bin_arith_ops)
392393

393394
compile_erlang(boxed_is_not_float)
394395
compile_erlang(float_is_float)
@@ -880,6 +881,7 @@ add_custom_target(erlang_test_modules DEPENDS
880881
floatdiv.beam
881882
floatmath.beam
882883
floatext.beam
884+
bif_bin_arith_ops.beam
883885

884886
boxed_is_not_float.beam
885887
float_is_float.beam

tests/libs/estdlib/test_bif_bin_arith_ops.erl renamed to tests/erlang_tests/bif_bin_arith_ops.erl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
%
1818
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
1919
%
20-
-module(test_bif_bin_arith_ops).
20+
-module(bif_bin_arith_ops).
2121

2222
-define(ID(X), ?MODULE:id(X)).
23-
-export([test/0, id/1]).
23+
-export([start/0, id/1]).
2424

25-
test() ->
25+
start() ->
2626
Ops = ['+', '-', '*', '/'],
2727
ValidInputs = [[2, 3], [0, 2], [2.0, 3], [2, 3.0], [2.0, 3.0]],
2828
InvalidInputs = [[not_int, 1], [1, not_int]],
@@ -35,10 +35,12 @@ test() ->
3535
{error, badarith} = call_op('div', [2, 3.0]),
3636
{error, badarith} = call_op('rem', [2.0, 3]),
3737
{error, badarith} = call_op('rem', [2, 3.0]),
38-
ok.
38+
0.
3939

40-
call_op(Name, Args) ->
41-
try apply(erlang, ?ID(Name), ?ID(Args)) of
40+
call_op(RawName, [RawA, RawB]) ->
41+
Name = ?ID(RawName),
42+
[A, B] = ?ID([RawA, RawB]),
43+
try erlang:Name(A, B) of
4244
V -> {ok, V}
4345
catch
4446
C:E -> {C, E}

tests/libs/estdlib/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ set(ERLANG_MODULES
5050
test_lists_subtraction
5151
test_tcp_socket
5252
test_udp_socket
53-
test_bif_bin_arith_ops
5453
notify_init_server
5554
ping_pong_server
5655
)

tests/libs/estdlib/tests.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ get_non_networking_tests(_OTPVersion) ->
7575
test_timer,
7676
test_spawn,
7777
test_supervisor,
78-
test_lists_subtraction,
79-
test_bif_bin_arith_ops
78+
test_lists_subtraction
8079
].
8180

8281
get_networking_tests(OTPVersion) when

tests/test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ struct Test tests[] = {
458458
TEST_CASE_EXPECTED(list2float, 511),
459459
TEST_CASE(floatmath),
460460
TEST_CASE(floatext),
461+
TEST_CASE(bif_bin_arith_ops),
461462

462463
TEST_CASE(test_fp_allocate_heap_zero),
463464

0 commit comments

Comments
 (0)