Skip to content

Commit ae60ff0

Browse files
Sanggyu Leezherczeg
authored andcommitted
Handle negative zero in number multiplication (#1856)
Keep sign for zero. For example, 1 / (0 * (-1)) should be -Infinity, not +Infinity. JerryScript-DCO-1.0-Signed-off-by: Sanggyu Lee [email protected]
1 parent 631e9f9 commit ae60ff0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

jerry-core/vm/vm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,9 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
17721772
if (-ECMA_INTEGER_MULTIPLY_MAX <= left_integer
17731773
&& left_integer <= ECMA_INTEGER_MULTIPLY_MAX
17741774
&& -ECMA_INTEGER_MULTIPLY_MAX <= right_integer
1775-
&& right_integer <= ECMA_INTEGER_MULTIPLY_MAX)
1775+
&& right_integer <= ECMA_INTEGER_MULTIPLY_MAX
1776+
&& left_value != 0
1777+
&& right_value != 0)
17761778
{
17771779
result = ecma_make_integer_value (left_integer * right_integer);
17781780
break;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
assert ((1 / 0*(-1)) == -Infinity);
16+
assert ((1 / 0*1) == Infinity);

0 commit comments

Comments
 (0)