js/src/jslibmath.h

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     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"
    16 /*
    17  * Use system provided math routines.
    18  */
    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)
    32 {
    33 #ifdef XP_WIN
    34     /*
    35      * Workaround MS fmod bug where 42 % (1/0) => NaN, not 42.
    36      * Workaround MS fmod bug where -0 % -N => 0, not -0.
    37      */
    38     if ((mozilla::IsFinite(d) && mozilla::IsInfinite(d2)) ||
    39         (d == 0 && mozilla::IsFinite(d2))) {
    40         return d;
    41     }
    42 #endif
    43     return fmod(d, d2);
    44 }
    46 namespace js {
    48 inline double
    49 NumberDiv(double a, double b)
    50 {
    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
    56         )
    57             return JS::GenericNaN();
    59         if (mozilla::IsNegative(a) != mozilla::IsNegative(b))
    60             return mozilla::NegativeInfinity<double>();
    61         return mozilla::PositiveInfinity<double>();
    62     }
    64     return a / b;
    65 }
    67 inline double
    68 NumberMod(double a, double b) {
    69     if (b == 0)
    70         return JS::GenericNaN();
    71     return js_fmod(a, b);
    72 }
    74 }
    76 #endif /* jslibmath_h */

mercurial