Skip to content

Commit b3852b9

Browse files
committed
Make erlang:is_number/1 return true for floats
Fix an old TODO: "change to term_is_number". Signed-off-by: Davide Bettio <davide@uninstall.it>
1 parent 74fe76e commit b3852b9

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ memory error
6565
- Fix `is_function/2` guard
6666
- Fixed segfault when calling `lists:reverse/1` (#1600)
6767
- Fixed nif_atomvm_posix_read GC bug
68+
- Fixed `erlang:is_number/1` function, now returns true also for floats
6869

6970
### Changed
7071

src/libAtomVM/bif.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ term bif_erlang_is_number_1(Context *ctx, uint32_t fail_label, term arg1)
213213
UNUSED(ctx);
214214
UNUSED(fail_label);
215215

216-
//TODO: change to term_is_number
217-
return term_is_any_integer(arg1) ? TRUE_ATOM : FALSE_ATOM;
216+
return term_is_number(arg1) ? TRUE_ATOM : FALSE_ATOM;
218217
}
219218

220219
term bif_erlang_is_pid_1(Context *ctx, uint32_t fail_label, term arg1)

tests/erlang_tests/float_is_number.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323
-export([start/0, pow/2, test/1, id/1]).
2424

2525
start() ->
26-
Res = (pow(-2, 63) + id(10.0)) * id(-1.0),
26+
Res = ?MODULE:id((pow(-2, 63) + id(10.0)) * id(-1.0)),
27+
true = ?MODULE:id(is_number(Res)),
2728
test(Res).
2829

2930
id(I) when is_float(I) ->
31+
I;
32+
id(I) when is_atom(I) ->
3033
I.
3134

3235
pow(_N, 0) ->

0 commit comments

Comments
 (0)