diff options
author | Dániel Bátyai <dbatyai@inf.u-szeged.hu> | 2021-12-03 12:58:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-03 12:58:37 +0100 |
commit | 81d2319144377f87e716c73a9b8b46f2bf5d09e5 (patch) | |
tree | 92dd7f340e08bf8a42f7540b74659a218635b628 /jerry-core/ecma/operations | |
parent | a1c1d4271061eff9f4bb4a0c9c31bb68c7f1514d (diff) |
Improve float number handling and conversion (#4820)
Fixes #4739.
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
Diffstat (limited to 'jerry-core/ecma/operations')
-rw-r--r-- | jerry-core/ecma/operations/ecma-array-object.c | 1 | ||||
-rw-r--r-- | jerry-core/ecma/operations/ecma-bigint.c | 32 | ||||
-rw-r--r-- | jerry-core/ecma/operations/ecma-conversion.c | 1 | ||||
-rw-r--r-- | jerry-core/ecma/operations/ecma-iterator-object.c | 1 | ||||
-rw-r--r-- | jerry-core/ecma/operations/ecma-number-arithmetic.c | 56 | ||||
-rw-r--r-- | jerry-core/ecma/operations/ecma-number-arithmetic.h | 35 | ||||
-rw-r--r-- | jerry-core/ecma/operations/ecma-typedarray-object.c | 2 |
7 files changed, 13 insertions, 115 deletions
diff --git a/jerry-core/ecma/operations/ecma-array-object.c b/jerry-core/ecma/operations/ecma-array-object.c index 0e793516..0ce958c3 100644 --- a/jerry-core/ecma/operations/ecma-array-object.c +++ b/jerry-core/ecma/operations/ecma-array-object.c @@ -24,7 +24,6 @@ #include "ecma-globals.h" #include "ecma-helpers.h" #include "ecma-iterator-object.h" -#include "ecma-number-arithmetic.h" #include "ecma-objects-general.h" #include "ecma-objects.h" #include "ecma-property-hashmap.h" diff --git a/jerry-core/ecma/operations/ecma-bigint.c b/jerry-core/ecma/operations/ecma-bigint.c index 2415a1f3..8ce37788 100644 --- a/jerry-core/ecma/operations/ecma-bigint.c +++ b/jerry-core/ecma/operations/ecma-bigint.c @@ -17,6 +17,7 @@ #include "ecma-big-uint.h" #include "ecma-exceptions.h" +#include "ecma-helpers-number.h" #include "ecma-helpers.h" #include "ecma-objects.h" @@ -85,21 +86,10 @@ ecma_bigint_parse_string (const lit_utf8_byte_t *string_p, /**< string represena if (size >= 3 && string_p[0] == LIT_CHAR_0) { - if (string_p[1] == LIT_CHAR_LOWERCASE_X || string_p[1] == LIT_CHAR_UPPERCASE_X) - { - radix = 16; - string_p += 2; - size -= 2; - } - else if (string_p[1] == LIT_CHAR_LOWERCASE_O || string_p[1] == LIT_CHAR_UPPERCASE_O) - { - radix = 8; - string_p += 2; - size -= 2; - } - else if (string_p[1] == LIT_CHAR_LOWERCASE_B || string_p[1] == LIT_CHAR_UPPERCASE_B) + radix = lit_char_to_radix (string_p[1]); + + if (radix != 10) { - radix = 2; string_p += 2; size -= 2; } @@ -292,17 +282,15 @@ static uint32_t ecma_bigint_number_to_digits (ecma_number_t number, /**< ecma number */ ecma_bigint_digit_t *digits_p) /**< [out] BigInt digits */ { - uint32_t biased_exp; - uint64_t fraction; - - ecma_number_unpack (number, NULL, &biased_exp, &fraction); - - if (biased_exp == 0 && fraction == 0) + if (ecma_number_is_zero (number)) { - /* Number is zero. */ return ECMA_BIGINT_NUMBER_TO_DIGITS_SET_DIGITS (0); } + ecma_binary_num_t binary = ecma_number_to_binary (number); + uint32_t biased_exp = ecma_number_biased_exp (binary); + uint64_t fraction = ecma_number_fraction (binary); + if (biased_exp < ((1 << (ECMA_NUMBER_BIASED_EXP_WIDTH - 1)) - 1)) { /* Number is less than 1. */ @@ -618,7 +606,7 @@ ecma_bigint_to_number (ecma_value_t value) /**< BigInt value */ if (biased_exp < (1u << ECMA_NUMBER_BIASED_EXP_WIDTH) - 1) { - result = ecma_number_pack (sign, biased_exp, fraction); + result = ecma_number_create (sign, biased_exp, fraction); } else { diff --git a/jerry-core/ecma/operations/ecma-conversion.c b/jerry-core/ecma/operations/ecma-conversion.c index 661c5514..9a71b2ff 100644 --- a/jerry-core/ecma/operations/ecma-conversion.c +++ b/jerry-core/ecma/operations/ecma-conversion.c @@ -29,6 +29,7 @@ #include "ecma-function-object.h" #include "ecma-gc.h" #include "ecma-globals.h" +#include "ecma-helpers-number.h" #include "ecma-helpers.h" #include "ecma-number-object.h" #include "ecma-objects-general.h" diff --git a/jerry-core/ecma/operations/ecma-iterator-object.c b/jerry-core/ecma/operations/ecma-iterator-object.c index 943df3e6..21d88724 100644 --- a/jerry-core/ecma/operations/ecma-iterator-object.c +++ b/jerry-core/ecma/operations/ecma-iterator-object.c @@ -24,7 +24,6 @@ #include "ecma-gc.h" #include "ecma-globals.h" #include "ecma-helpers.h" -#include "ecma-number-arithmetic.h" #include "ecma-objects-general.h" #include "ecma-objects.h" diff --git a/jerry-core/ecma/operations/ecma-number-arithmetic.c b/jerry-core/ecma/operations/ecma-number-arithmetic.c deleted file mode 100644 index 2d17900a..00000000 --- a/jerry-core/ecma/operations/ecma-number-arithmetic.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ecma-number-arithmetic.h" - -#include "ecma-globals.h" -#include "ecma-helpers.h" - -/** \addtogroup ecma ECMA - * @{ - * - * \addtogroup numberarithmetic ECMA number arithmetic operations - * @{ - */ - -/** - * ECMA-defined number remainder calculation. - * - * See also: - * ECMA-262 v5, 11.5.3 - * - * @return number - calculated remainder. - */ -ecma_number_t -ecma_op_number_remainder (ecma_number_t left_num, /**< left operand */ - ecma_number_t right_num) /**< right operand */ -{ - if (ecma_number_is_nan (left_num) || ecma_number_is_nan (right_num) || ecma_number_is_infinity (left_num) - || ecma_number_is_zero (right_num)) - { - return ecma_number_make_nan (); - } - else if (ecma_number_is_infinity (right_num) || (ecma_number_is_zero (left_num) && !ecma_number_is_zero (right_num))) - { - return left_num; - } - - return ecma_number_calc_remainder (left_num, right_num); -} /* ecma_op_number_remainder */ - -/** - * @} - * @} - */ diff --git a/jerry-core/ecma/operations/ecma-number-arithmetic.h b/jerry-core/ecma/operations/ecma-number-arithmetic.h deleted file mode 100644 index 2d9d00ac..00000000 --- a/jerry-core/ecma/operations/ecma-number-arithmetic.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ECMA_NUMBER_ARITHMETIC_H -#define ECMA_NUMBER_ARITHMETIC_H - -#include "ecma-globals.h" - -/** \addtogroup ecma ECMA - * @{ - * - * \addtogroup numberarithmetic ECMA number arithmetic operations - * @{ - */ - -ecma_number_t ecma_op_number_remainder (ecma_number_t left_num, ecma_number_t right_num); - -/** - * @} - * @} - */ - -#endif /* !ECMA_NUMBER_ARITHMETIC_H */ diff --git a/jerry-core/ecma/operations/ecma-typedarray-object.c b/jerry-core/ecma/operations/ecma-typedarray-object.c index 7a2d171a..cd8c4f6e 100644 --- a/jerry-core/ecma/operations/ecma-typedarray-object.c +++ b/jerry-core/ecma/operations/ecma-typedarray-object.c @@ -22,10 +22,12 @@ #include "ecma-bigint.h" #include "ecma-builtin-helpers.h" #include "ecma-builtins.h" +#include "ecma-conversion.h" #include "ecma-exceptions.h" #include "ecma-function-object.h" #include "ecma-gc.h" #include "ecma-globals.h" +#include "ecma-helpers-number.h" #include "ecma-helpers.h" #include "ecma-iterator-object.h" #include "ecma-objects-general.h" |