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
This commit is contained in:
Dániel Bátyai
2021-12-03 12:58:37 +01:00
committed by GitHub
parent a1c1d42710
commit 81d2319144
30 changed files with 1022 additions and 1603 deletions
@@ -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"
+10 -22
View File
@@ -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 = lit_char_to_radix (string_p[1]);
if (radix != 10)
{
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 = 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
{
@@ -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"
@@ -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"
@@ -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 */
/**
* @}
* @}
*/
@@ -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 */
@@ -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"