Skip to content

Commit a3ee88b

Browse files
committed
Fix allocate_heap_zero with floats
Signed-off-by: Paul Guyot <[email protected]>
1 parent bc3bf97 commit a3ee88b

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

src/libAtomVM/opcodesswitch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,7 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
17831783
uint32_t stack_need;
17841784
DECODE_LITERAL(stack_need, code, i, next_off);
17851785
uint32_t heap_need;
1786-
DECODE_LITERAL(heap_need, code, i, next_off);
1786+
DECODE_ALLOCATOR_LIST(heap_need, code, i, next_off);
17871787
uint32_t live;
17881788
DECODE_LITERAL(live, code, i, next_off);
17891789
TRACE("allocate_heap_zero/3 stack_need=%i, heap_need=%i, live=%i\n", stack_need, heap_need, live);

tests/erlang_tests/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ compile_erlang(float2list2)
363363
compile_erlang(bin2float)
364364
compile_erlang(list2float)
365365

366+
compile_erlang(test_fp_allocate_heap_zero)
367+
366368
compile_erlang(improper_concat)
367369
compile_erlang(improper_cmp)
368370
compile_erlang(improper_literal)
@@ -770,6 +772,8 @@ add_custom_target(erlang_test_modules DEPENDS
770772
bin2float.beam
771773
list2float.beam
772774

775+
test_fp_allocate_heap_zero.beam
776+
773777
improper_concat.beam
774778
improper_cmp.beam
775779
improper_literal.beam
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
%
2+
% This file is part of AtomVM.
3+
%
4+
% Copyright 2023 Paul Guyot <[email protected]>
5+
%
6+
% Licensed under the Apache License, Version 2.0 (the "License");
7+
% you may not use this file except in compliance with the License.
8+
% You may obtain a copy of the License at
9+
%
10+
% http://www.apache.org/licenses/LICENSE-2.0
11+
%
12+
% Unless required by applicable law or agreed to in writing, software
13+
% distributed under the License is distributed on an "AS IS" BASIS,
14+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
% See the License for the specific language governing permissions and
16+
% limitations under the License.
17+
%
18+
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
%
20+
21+
-module(test_fp_allocate_heap_zero).
22+
-export([start/0]).
23+
24+
start() ->
25+
R = e(0.1, 10000, 0.0),
26+
true = R > 2183.832274,
27+
true = R < 2183.832276,
28+
0.
29+
30+
e(_Step, 0, Acc) ->
31+
Acc;
32+
e(Step, N, Acc) when is_float(Step) andalso is_integer(N) andalso is_float(Acc) ->
33+
R = f(Step * N),
34+
e(Step, N - 1, Acc + math:sqrt(R * R) * Step).
35+
36+
f(T) when is_float(T) ->
37+
0.3 + 3.2 * math:sin(T) + 0.7 * math:sin(2 * T) + 0.2 * math:sin(4 * T) + 1.2 * math:sin(8 * T).

tests/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ struct Test tests[] = {
399399
TEST_CASE_COND(list2float, 511, SKIP_NO_FP),
400400
TEST_CASE_COND(floatmath, 0, SKIP_NO_FP),
401401

402+
TEST_CASE_COND(test_fp_allocate_heap_zero, 0, SKIP_NO_FP),
403+
402404
TEST_CASE_EXPECTED(improper_concat, 7),
403405
TEST_CASE_EXPECTED(improper_cmp, 3),
404406
TEST_CASE_EXPECTED(improper_literal, 3),

0 commit comments

Comments
 (0)