Repository: jerryscript-project/jerryscript
File: jerry-math/log.c (C)

Code before:
 * Accuracy:
 *      according to an error analysis, the error is always less than
 *      1 ulp (unit in the last place).
 *
 * Constants:
 * The hexadecimal values are the intended ones for the following
 * constants. The decimal values may be used, provided that the
 * compiler will convert from decimal to binary accurately enough
 * to produce the hexadecimal values shown.
 */

#define ln2_hi 6.93147180369123816490e-01 /* 3fe62e42 fee00000 */
#define ln2_lo 1.90821492927058770002e-10 /* 3dea39ef 35793c76 */
#define two54  1.80143985094819840000e+16 /* 43500000 00000000 */
#define Lg1    6.666666666666735130e-01 /* 3FE55555 55555593 */
#define Lg2    3.999999999940941908e-01 /* 3FD99999 9997FA04 */
#define Lg3    2.857142874366239149e-01 /* 3FD24924 94229359 */
#define Lg4    2.222219843214978396e-01 /* 3FCC71C5 1D8E78AF */
#define Lg5    1.818357216161805012e-01 /* 3FC74664 96CB03DE */
#define Lg6    1.531383769920937332e-01 /* 3FC39A09 D078C69F */
#define Lg7    1.479819860511658591e-01 /* 3FC2F112 DF3E5244 */

double
log (double x)
{
  const double zero = 0.0;
  double hfsq, f, s, z, R, w, t1, t2, dk;
  int k, hx, i, j;
  unsigned lx;

  hx = __HI (x); /* high word of x */
  lx = __LO (x); /* low  word of x */

  k = 0;
  if (hx < 0x00100000) /* x < 2**-1022  */
  {
    if (((hx & 0x7fffffff) | lx) == 0) /* log(+-0) = -inf */
    {
      return -two54 / zero;
    }
    if (hx < 0) /* log(-#) = NaN */
    {
      return (x - x) / zero;
    }
    k -= 54;
    x *= two54; /* subnormal number, scale up x */
    hx = __HI (x); /* high word of x */
  }
  if (hx >= 0x7ff00000)
  {
    return x + x;

Review comment (suggestion):
And in these files, instead of using a zero variable to make division by zero possible on MSVC, the div0 expressions should be changed to +/-INFINITY or NAN. (This is how the patch looked like at some point of time, but then it has changed.)

Code after:
 * Accuracy:
 *      according to an error analysis, the error is always less than
 *      1 ulp (unit in the last place).
 *
 * Constants:
 * The hexadecimal values are the intended ones for the following
 * constants. The decimal values may be used, provided that the
 * compiler will convert from decimal to binary accurately enough
 * to produce the hexadecimal values shown.
 */

#define zero   0.0
#define ln2_hi 6.93147180369123816490e-01 /* 3fe62e42 fee00000 */
#define ln2_lo 1.90821492927058770002e-10 /* 3dea39ef 35793c76 */
#define two54  1.80143985094819840000e+16 /* 43500000 00000000 */
#define Lg1    6.666666666666735130e-01 /* 3FE55555 55555593 */
#define Lg2    3.999999999940941908e-01 /* 3FD99999 9997FA04 */
#define Lg3    2.857142874366239149e-01 /* 3FD24924 94229359 */
#define Lg4    2.222219843214978396e-01 /* 3FCC71C5 1D8E78AF */
#define Lg5    1.818357216161805012e-01 /* 3FC74664 96CB03DE */
#define Lg6    1.531383769920937332e-01 /* 3FC39A09 D078C69F */
#define Lg7    1.479819860511658591e-01 /* 3FC2F112 DF3E5244 */

double
log (double x)
{
  double hfsq, f, s, z, R, w, t1, t2, dk;
  int k, hx, i, j;
  unsigned lx;

  hx = __HI (x); /* high word of x */
  lx = __LO (x); /* low  word of x */

  k = 0;
  if (hx < 0x00100000) /* x < 2**-1022  */
  {
    if (((hx & 0x7fffffff) | lx) == 0) /* log(+-0) = -inf */
    {
      return -INFINITY;
    }
    if (hx < 0) /* log(-#) = NaN */
    {
      return NAN;
    }
    k -= 54;
    x *= two54; /* subnormal number, scale up x */
    hx = __HI (x); /* high word of x */
  }
  if (hx >= 0x7ff00000)
  {
    return x + x;