Skip to content

Commit 81d2319

Browse files
authored
Improve float number handling and conversion (#4820)
Fixes #4739. JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai [email protected]
1 parent a1c1d42 commit 81d2319

30 files changed

+987
-1568
lines changed

jerry-core/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ set(SOURCE_CORE_FILES
283283
ecma/operations/ecma-iterator-object.c
284284
ecma/operations/ecma-jobqueue.c
285285
ecma/operations/ecma-lex-env.c
286-
ecma/operations/ecma-number-arithmetic.c
287286
ecma/operations/ecma-number-object.c
288287
ecma/operations/ecma-objects-general.c
289288
ecma/operations/ecma-objects.c
@@ -462,7 +461,6 @@ if(ENABLE_AMALGAM)
462461
ecma/operations/ecma-iterator-object.h
463462
ecma/operations/ecma-jobqueue.h
464463
ecma/operations/ecma-lex-env.h
465-
ecma/operations/ecma-number-arithmetic.h
466464
ecma/operations/ecma-number-object.h
467465
ecma/operations/ecma-objects-general.h
468466
ecma/operations/ecma-objects.h

jerry-core/ecma/base/ecma-globals.h

+10-198
Original file line numberDiff line numberDiff line change
@@ -1386,112 +1386,34 @@ typedef struct
13861386
#define ECMA_PROPERTY_FLAGS_MASK \
13871387
((uint16_t) (JERRY_PROP_IS_CONFIGURABLE | JERRY_PROP_IS_ENUMERABLE | JERRY_PROP_IS_WRITABLE))
13881388

1389-
#if !JERRY_NUMBER_TYPE_FLOAT64
1390-
/**
1391-
* Description of an ecma-number
1392-
*/
1393-
typedef float ecma_number_t;
1394-
1395-
/**
1396-
* It makes possible to read/write an ecma_number_t as uint32_t without strict aliasing rule violation.
1397-
*/
1398-
typedef union
1399-
{
1400-
ecma_number_t as_ecma_number_t;
1401-
uint32_t as_uint32_t;
1402-
} ecma_number_accessor_t;
1403-
1404-
#define DOUBLE_TO_ECMA_NUMBER_T(value) (ecma_number_t) (value)
1405-
1406-
/**
1407-
* Maximum number of significant digits that ecma-number can store
1408-
*/
1409-
#define ECMA_NUMBER_MAX_DIGITS (9)
1410-
1411-
/**
1412-
* Width of sign field
1413-
*
1414-
* See also:
1415-
* IEEE-754 2008, 3.6, Table 3.5
1416-
*/
1417-
#define ECMA_NUMBER_SIGN_WIDTH (1)
1418-
1419-
/**
1420-
* Width of biased exponent field
1421-
*
1422-
* See also:
1423-
* IEEE-754 2008, 3.6, Table 3.5
1424-
*/
1425-
#define ECMA_NUMBER_BIASED_EXP_WIDTH (8)
1426-
1427-
/**
1428-
* Width of fraction field
1429-
*
1430-
* See also:
1431-
* IEEE-754 2008, 3.6, Table 3.5
1432-
*/
1433-
#define ECMA_NUMBER_FRACTION_WIDTH (23)
1434-
#elif JERRY_NUMBER_TYPE_FLOAT64
14351389
/**
14361390
* Description of an ecma-number
14371391
*/
1392+
#if JERRY_NUMBER_TYPE_FLOAT64
14381393
typedef double ecma_number_t;
1394+
#else /* !JERRY_NUMBER_TYPE_FLOAT64 */
1395+
typedef float ecma_number_t;
1396+
#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */
14391397

14401398
/**
1441-
* It makes possible to read/write an ecma_number_t as uint64_t without strict aliasing rule violation.
1442-
*/
1443-
typedef union
1444-
{
1445-
ecma_number_t as_ecma_number_t;
1446-
uint64_t as_uint64_t;
1447-
} ecma_number_accessor_t;
1448-
1449-
#define DOUBLE_TO_ECMA_NUMBER_T(value) value
1450-
1451-
/**
1452-
* Maximum number of significant digits that ecma-number can store
1453-
*/
1454-
#define ECMA_NUMBER_MAX_DIGITS (19)
1455-
1456-
/**
1457-
* Width of sign field
1458-
*
1459-
* See also:
1460-
* IEEE-754 2008, 3.6, Table 3.5
1461-
*/
1462-
#define ECMA_NUMBER_SIGN_WIDTH (1)
1463-
1464-
/**
1465-
* Width of biased exponent field
1466-
*
1467-
* See also:
1468-
* IEEE-754 2008, 3.6, Table 3.5
1469-
*/
1470-
#define ECMA_NUMBER_BIASED_EXP_WIDTH (11)
1471-
1472-
/**
1473-
* Width of fraction field
1474-
*
1475-
* See also:
1476-
* IEEE-754 2008, 3.6, Table 3.5
1399+
* Convert double to an ecma-number.
14771400
*/
1478-
#define ECMA_NUMBER_FRACTION_WIDTH (52)
1479-
#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */
1401+
#define DOUBLE_TO_ECMA_NUMBER_T(value) ((ecma_number_t) (value))
14801402

14811403
/**
14821404
* Value '0' of ecma_number_t
14831405
*/
1484-
#define ECMA_NUMBER_ZERO ((ecma_number_t) 0)
1406+
#define ECMA_NUMBER_ZERO ((ecma_number_t) 0.0f)
14851407

14861408
/**
14871409
* Value '1' of ecma_number_t
14881410
*/
1489-
#define ECMA_NUMBER_ONE ((ecma_number_t) 1)
1411+
#define ECMA_NUMBER_ONE ((ecma_number_t) 1.0f)
14901412

14911413
/**
14921414
* Value '2' of ecma_number_t
14931415
*/
1494-
#define ECMA_NUMBER_TWO ((ecma_number_t) 2)
1416+
#define ECMA_NUMBER_TWO ((ecma_number_t) 2.0f)
14951417

14961418
/**
14971419
* Value '0.5' of ecma_number_t
@@ -1501,117 +1423,7 @@ typedef union
15011423
/**
15021424
* Value '-1' of ecma_number_t
15031425
*/
1504-
#define ECMA_NUMBER_MINUS_ONE ((ecma_number_t) -1)
1505-
1506-
#if !JERRY_NUMBER_TYPE_FLOAT64
1507-
/**
1508-
* Number.MIN_VALUE (i.e., the smallest positive value of ecma-number)
1509-
*
1510-
* See also: ECMA_262 v5, 15.7.3.3
1511-
*/
1512-
#define ECMA_NUMBER_MIN_VALUE (FLT_MIN)
1513-
/**
1514-
* Number.MAX_VALUE (i.e., the maximum value of ecma-number)
1515-
*
1516-
* See also: ECMA_262 v5, 15.7.3.2
1517-
*/
1518-
#define ECMA_NUMBER_MAX_VALUE (FLT_MAX)
1519-
/**
1520-
* Number.EPSILON
1521-
*
1522-
* See also: ECMA_262 v6, 20.1.2.1
1523-
*/
1524-
#define ECMA_NUMBER_EPSILON ((ecma_number_t) 1.1920928955078125e-7)
1525-
1526-
/**
1527-
* Number.MAX_SAFE_INTEGER
1528-
*
1529-
* See also: ECMA_262 v6, 20.1.2.6
1530-
*/
1531-
#define ECMA_NUMBER_MAX_SAFE_INTEGER ((ecma_number_t) 0xFFFFFF)
1532-
1533-
/**
1534-
* Number.MIN_SAFE_INTEGER
1535-
*
1536-
* See also: ECMA_262 v6, 20.1.2.8
1537-
*/
1538-
#define ECMA_NUMBER_MIN_SAFE_INTEGER ((ecma_number_t) -0xFFFFFF)
1539-
#elif JERRY_NUMBER_TYPE_FLOAT64
1540-
/**
1541-
* Number.MAX_VALUE (i.e., the maximum value of ecma-number)
1542-
*
1543-
* See also: ECMA_262 v5, 15.7.3.2
1544-
*/
1545-
#define ECMA_NUMBER_MAX_VALUE ((ecma_number_t) 1.7976931348623157e+308)
1546-
1547-
/**
1548-
* Number.MIN_VALUE (i.e., the smallest positive value of ecma-number)
1549-
*
1550-
* See also: ECMA_262 v5, 15.7.3.3
1551-
*/
1552-
#define ECMA_NUMBER_MIN_VALUE ((ecma_number_t) 5e-324)
1553-
1554-
/**
1555-
* Number.EPSILON
1556-
*
1557-
* See also: ECMA_262 v6, 20.1.2.1
1558-
*/
1559-
#define ECMA_NUMBER_EPSILON ((ecma_number_t) 2.2204460492503130808472633361816e-16)
1560-
1561-
/**
1562-
* Number.MAX_SAFE_INTEGER
1563-
*
1564-
* See also: ECMA_262 v6, 20.1.2.6
1565-
*/
1566-
#define ECMA_NUMBER_MAX_SAFE_INTEGER ((ecma_number_t) 0x1FFFFFFFFFFFFF)
1567-
1568-
/**
1569-
* Number.MIN_SAFE_INTEGER
1570-
*
1571-
* See also: ECMA_262 v6, 20.1.2.8
1572-
*/
1573-
#define ECMA_NUMBER_MIN_SAFE_INTEGER ((ecma_number_t) -0x1FFFFFFFFFFFFF)
1574-
#endif /* !JERRY_NUMBER_TYPE_FLOAT64 */
1575-
1576-
/**
1577-
* Euler number
1578-
*/
1579-
#define ECMA_NUMBER_E ((ecma_number_t) 2.7182818284590452354)
1580-
1581-
/**
1582-
* Natural logarithm of 10
1583-
*/
1584-
#define ECMA_NUMBER_LN10 ((ecma_number_t) 2.302585092994046)
1585-
1586-
/**
1587-
* Natural logarithm of 2
1588-
*/
1589-
#define ECMA_NUMBER_LN2 ((ecma_number_t) 0.6931471805599453)
1590-
1591-
/**
1592-
* Logarithm base 2 of the Euler number
1593-
*/
1594-
#define ECMA_NUMBER_LOG2E ((ecma_number_t) 1.4426950408889634)
1595-
1596-
/**
1597-
* Logarithm base 10 of the Euler number
1598-
*/
1599-
#define ECMA_NUMBER_LOG10E ((ecma_number_t) 0.4342944819032518)
1600-
1601-
/**
1602-
* Pi number
1603-
*/
1604-
#define ECMA_NUMBER_PI ((ecma_number_t) 3.1415926535897932)
1605-
1606-
/**
1607-
* Square root of 0.5
1608-
*/
1609-
#define ECMA_NUMBER_SQRT_1_2 ((ecma_number_t) 0.7071067811865476)
1610-
1611-
/**
1612-
* Square root of 2
1613-
*/
1614-
#define ECMA_NUMBER_SQRT2 ((ecma_number_t) 1.4142135623730951)
1426+
#define ECMA_NUMBER_MINUS_ONE ((ecma_number_t) -1.0f)
16151427

16161428
/**
16171429
* Maximum number of characters in string representation of ecma-number

0 commit comments

Comments
 (0)