LCOV - app.info - js/src/jslibmath.h

LCOV - code coverage report
| Current view: | directory - js/src - jslibmath.h (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 10 | 10 | 100.0 %
| Date: | 2012-04-07 | Functions: | 2 | 2 | 100.0 %

           1                 : /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
           2                 :  * vim: set ts=4 sw=4 et tw=79:
           3                 :  *
           4                 :  * ***** BEGIN LICENSE BLOCK *****
           5                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           6                 :  *
           7                 :  * The contents of this file are subject to the Mozilla Public License Version
           8                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           9                 :  * the License. You may obtain a copy of the License at
          10                 :  * http://www.mozilla.org/MPL/
          11                 :  *
          12                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          13                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          14                 :  * for the specific language governing rights and limitations under the
          15                 :  * License.
          16                 :  *
          17                 :  * The Original Code is Mozilla Communicator client code, released
          18                 :  * March 31, 1998.
          19                 :  *
          20                 :  * The Initial Developer of the Original Code is
          21                 :  * Netscape Communications Corporation.
          22                 :  * Portions created by the Initial Developer are Copyright (C) 1998
          23                 :  * the Initial Developer. All Rights Reserved.
          24                 :  *
          25                 :  * Contributor(s):
          26                 :  *   IBM Corp.
          27                 :  *
          28                 :  * Alternatively, the contents of this file may be used under the terms of
          29                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
          30                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          31                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          32                 :  * of those above. If you wish to allow use of your version of this file only
          33                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          34                 :  * use your version of this file under the terms of the MPL, indicate your
          35                 :  * decision by deleting the provisions above and replace them with the notice
          36                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          37                 :  * the provisions above, a recipient may use your version of this file under
          38                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          39                 :  *
          40                 :  * ***** END LICENSE BLOCK ***** */
          41                 :
          42                 : #ifndef _LIBMATH_H
          43                 : #define _LIBMATH_H
          44                 :
          45                 : #include <math.h>
          46                 : #include "jsnum.h"
          47                 :
          48                 : /*
          49                 :  * Use system provided math routines.
          50                 :  */
          51                 :
          52                 : /* The right copysign function is not always named the same thing. */
          53                 : #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
          54                 : #define js_copysign __builtin_copysign
          55                 : #elif defined _WIN32
          56                 : #if _MSC_VER < 1400
          57                 : /* Try to work around apparent _copysign bustage in VC7.x. */
          58                 : #define js_copysign js_copysign
          59                 : extern double js_copysign(double, double);
          60                 : #else
          61                 : #define js_copysign _copysign
          62                 : #endif
          63                 : #else
          64                 : #define js_copysign copysign
          65                 : #endif
          66                 :
          67                 : #if defined(_M_X64) && defined(_MSC_VER) && _MSC_VER <= 1500
          68                 : // This is a workaround for fmod bug (http://support.microsoft.com/kb/982107)
          69                 : extern "C" double js_myfmod(double x, double y);
          70                 : #define fmod js_myfmod
          71                 : #endif
          72                 :
          73                 : /* Consistency wrapper for platform deviations in fmod() */
          74                 : static inline double
          75           40280 : js_fmod(double d, double d2)
          76                 : {
          77                 : #ifdef XP_WIN
          78                 :     /*
          79                 :      * Workaround MS fmod bug where 42 % (1/0) => NaN, not 42.
          80                 :      * Workaround MS fmod bug where -0 % -N => 0, not -0.
          81                 :      */
          82                 :     if ((JSDOUBLE_IS_FINITE(d) && JSDOUBLE_IS_INFINITE(d2)) ||
          83                 :         (d == 0 && JSDOUBLE_IS_FINITE(d2))) {
          84                 :         return d;
          85                 :     }
          86                 : #endif
          87           40280 :     return fmod(d, d2);
          88                 : }
          89                 :
          90                 : namespace js {
          91                 :
          92                 : inline double
          93         1388564 : NumberDiv(double a, double b) {
          94         1388564 :     if (b == 0) {
          95            1385 :         if (a == 0 || JSDOUBLE_IS_NaN(a)
          96                 : #ifdef XP_WIN
          97                 :             || JSDOUBLE_IS_NaN(b) /* XXX MSVC miscompiles such that (NaN == 0) */
          98                 : #endif
          99                 :         )
         100              17 :             return js_NaN;
         101                 :
         102            1368 :         if (JSDOUBLE_IS_NEG(a) != JSDOUBLE_IS_NEG(b))
         103             487 :             return js_NegativeInfinity;
         104             881 :         return js_PositiveInfinity;
         105                 :     }
         106                 :
         107         1387179 :     return a / b;
         108                 : }
         109                 :
         110                 : }
         111                 :
         112                 : #endif /* _LIBMATH_H */
         113                 :

Generated by: LCOV version 1.7