Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/builtin-objects/ecma-builtin-number.c (C)

Code before:
 * The Number object 'isInteger' and 'isSafeInteger' routine
 *
 * See also:
 *          ECMA-262 v6, 20.1.2.3
 *          ECMA-262 v6, 20.1.2.3
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_number_object_is_integer_helper (ecma_value_t arg, /**< routine's argument */
                                              ecma_number_t num, /**< this number */
                                              bool is_safe) /**< is the number safe */
{
  if (ecma_number_is_nan (num) || ecma_number_is_infinity (num))
  {
    return ECMA_VALUE_FALSE;
  }

  ecma_number_t int_num;

  if (is_safe)
  {
    int_num = ecma_number_trunc (num);

    if (int_num == num && fabs (int_num) <= ECMA_NUMBER_MAX_SAFE_INTEGER)
    {
      return ECMA_VALUE_TRUE;
    }
  }
  else
  {
    ecma_op_to_integer (arg, &int_num);

    if (int_num == num)
    {
      return ECMA_VALUE_TRUE;
    }
  }

  return ECMA_VALUE_FALSE;
} /* ecma_builtin_number_object_is_integer_helper */

/**
 * Dispatcher of the built-in's routines
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_builtin_number_dispatch_routine (uint16_t builtin_routine_id, /**< built-in wide routine

Review comment (suggestion):
`int_num == num` could be factored out, just do
```c
if (fabs (int_num) > ECMA_NUMBER_MAX_SAFE_INTEGER)
{
  return ECMA_VALUE_FALSE;
}
```
here, and then you can
```c
return (int_num == num) ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE;
```

Code after:
 * The Number object 'isInteger' and 'isSafeInteger' routine
 *
 * See also:
 *          ECMA-262 v6, 20.1.2.3
 *          ECMA-262 v6, 20.1.2.3
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_number_object_is_integer_helper (ecma_value_t arg, /**< routine's argument */
                                              ecma_number_t num, /**< this number */
                                              bool is_safe) /**< is the number safe */
{
  if (ecma_number_is_nan (num) || ecma_number_is_infinity (num))
  {
    return ECMA_VALUE_FALSE;
  }

  ecma_number_t int_num;

  if (is_safe)
  {
    int_num = ecma_number_trunc (num);

    if (fabs (int_num) > ECMA_NUMBER_MAX_SAFE_INTEGER)
    {
      return ECMA_VALUE_FALSE;
    }
  }
  else
  {
    ecma_op_to_integer (arg, &int_num);
  }

  return (int_num == num) ? ECMA_VALUE_TRUE : ECMA_VALUE_FALSE;
} /* ecma_builtin_number_object_is_integer_helper */

/**
 * Dispatcher of the built-in's routines
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_builtin_number_dispatch_routine (uint16_t builtin_routine_id, /**< built-in wide routine
                                                                    *   identifier */
                                      ecma_value_t this_arg, /**< 'this' argument value */
                                      const ecma_value_t arguments_list_p[], /**< list of arguments
                                                                              *   passed to routine */
                                      uint32_t arguments_number) /**< length of arguments' list */