Bumping manifests a=b2g-bump
[gecko.git] / js / src / jslibmath.h
blobbc33e97ae4c1301c98a603329500140602e25ee3
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef jslibmath_h
8 #define jslibmath_h
10 #include "mozilla/FloatingPoint.h"
12 #include <math.h>
14 #include "jsnum.h"
17 * Use system provided math routines.
20 /* The right copysign function is not always named the same thing. */
21 #ifdef __GNUC__
22 #define js_copysign __builtin_copysign
23 #elif defined _WIN32
24 #define js_copysign _copysign
25 #else
26 #define js_copysign copysign
27 #endif
29 /* Consistency wrapper for platform deviations in fmod() */
30 static inline double
31 js_fmod(double d, double d2)
33 #ifdef XP_WIN
35 * Workaround MS fmod bug where 42 % (1/0) => NaN, not 42.
36 * Workaround MS fmod bug where -0 % -N => 0, not -0.
38 if ((mozilla::IsFinite(d) && mozilla::IsInfinite(d2)) ||
39 (d == 0 && mozilla::IsFinite(d2))) {
40 return d;
42 #endif
43 return fmod(d, d2);
46 namespace js {
48 inline double
49 NumberDiv(double a, double b)
51 if (b == 0) {
52 if (a == 0 || mozilla::IsNaN(a)
53 #ifdef XP_WIN
54 || mozilla::IsNaN(b) /* XXX MSVC miscompiles such that (NaN == 0) */
55 #endif
57 return JS::GenericNaN();
59 if (mozilla::IsNegative(a) != mozilla::IsNegative(b))
60 return mozilla::NegativeInfinity<double>();
61 return mozilla::PositiveInfinity<double>();
64 return a / b;
67 inline double
68 NumberMod(double a, double b) {
69 if (b == 0)
70 return JS::GenericNaN();
71 return js_fmod(a, b);
76 #endif /* jslibmath_h */