js/src/jslibmath.h
author Tooru Fujisawa <arai_a@mac.com>
Sat, 01 Dec 2018 04:52:05 +0900
changeset 449035 66eb1f485c1a3ea81372758bc92292c9428b17cd
parent 449028 e4712449ba4303cef134ba0b3f1bea13fbd50c4a
child 461724 865ffd54922df9290d217c75d126da23d0a373c0
permissions -rw-r--r--
Bug 1511393 - Use c-basic-offset: 2 in Emacs mode line for C/C++ code. r=nbp

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=8 sts=2 et sw=2 tw=80:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef jslibmath_h
#define jslibmath_h

#include "mozilla/FloatingPoint.h"

#include <math.h>

#include "js/Value.h"
#include "vm/JSContext.h"

namespace js {

inline double NumberDiv(double a, double b) {
  AutoUnsafeCallWithABI unsafe(UnsafeABIStrictness::AllowPendingExceptions);
  if (b == 0) {
    if (a == 0 || mozilla::IsNaN(a)) {
      return JS::GenericNaN();
    }
    if (mozilla::IsNegative(a) != mozilla::IsNegative(b)) {
      return mozilla::NegativeInfinity<double>();
    }
    return mozilla::PositiveInfinity<double>();
  }

  return a / b;
}

inline double NumberMod(double a, double b) {
  AutoUnsafeCallWithABI unsafe(UnsafeABIStrictness::AllowPendingExceptions);
  if (b == 0) {
    return JS::GenericNaN();
  }
  return fmod(a, b);
}

}  // namespace js

#endif /* jslibmath_h */