Improving precision of ecma_number_to_string in case number can be represented as UInt32.
This commit is contained in:
@@ -444,7 +444,7 @@ ecma_number_to_int32 (ecma_number_t value) /**< unsigned 32-bit integer value */
|
|||||||
*
|
*
|
||||||
* Warning:
|
* Warning:
|
||||||
* the conversion is not precise for all cases
|
* the conversion is not precise for all cases
|
||||||
* For example, 12345.0f converts to "12344.99931".
|
* For example, 12345.123f converts to "12345.12209".
|
||||||
*
|
*
|
||||||
* @return length of zt-string
|
* @return length of zt-string
|
||||||
*/
|
*/
|
||||||
@@ -507,6 +507,13 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
|
|||||||
# error "!CONFIG_ECMA_NUMBER_FLOAT32 && !CONFIG_ECMA_NUMBER_FLOAT64"
|
# error "!CONFIG_ECMA_NUMBER_FLOAT32 && !CONFIG_ECMA_NUMBER_FLOAT64"
|
||||||
#endif /* !CONFIG_ECMA_NUMBER_FLOAT32 && !CONFIG_ECMA_NUMBER_FLOAT64 */
|
#endif /* !CONFIG_ECMA_NUMBER_FLOAT32 && !CONFIG_ECMA_NUMBER_FLOAT64 */
|
||||||
|
|
||||||
|
uint32_t num_uint32 = ecma_number_to_uint32 (num);
|
||||||
|
if (ecma_uint32_to_number (num_uint32) == num)
|
||||||
|
{
|
||||||
|
ecma_uint32_to_string (num_uint32, dst_p, buffer_size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
uint64_t fraction_uint64;
|
uint64_t fraction_uint64;
|
||||||
LL_T fraction;
|
LL_T fraction;
|
||||||
int32_t exponent;
|
int32_t exponent;
|
||||||
@@ -750,6 +757,7 @@ ecma_number_to_zt_string (ecma_number_t num, /**< ecma-number */
|
|||||||
JERRY_ASSERT (s == 0);
|
JERRY_ASSERT (s == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ecma_length_t length = ecma_zt_string_length (buffer_p);
|
ecma_length_t length = ecma_zt_string_length (buffer_p);
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ main( int __unused argc,
|
|||||||
{
|
{
|
||||||
(const ecma_char_t*) "1",
|
(const ecma_char_t*) "1",
|
||||||
(const ecma_char_t*) "0.5",
|
(const ecma_char_t*) "0.5",
|
||||||
(const ecma_char_t*) "12344.99931",
|
(const ecma_char_t*) "12345",
|
||||||
|
(const ecma_char_t*) "12345.12209",
|
||||||
(const ecma_char_t*) "1.401298403e-45",
|
(const ecma_char_t*) "1.401298403e-45",
|
||||||
(const ecma_char_t*) "-2.5e+38",
|
(const ecma_char_t*) "-2.5e+38",
|
||||||
(const ecma_char_t*) "NaN",
|
(const ecma_char_t*) "NaN",
|
||||||
@@ -46,6 +47,7 @@ main( int __unused argc,
|
|||||||
1.0f,
|
1.0f,
|
||||||
0.5f,
|
0.5f,
|
||||||
12345.0f,
|
12345.0f,
|
||||||
|
12345.123f,
|
||||||
1.0e-45f,
|
1.0e-45f,
|
||||||
-2.5e+38f,
|
-2.5e+38f,
|
||||||
NAN,
|
NAN,
|
||||||
|
|||||||
Reference in New Issue
Block a user