OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 #if OS(SOLARIS) | 37 #if OS(SOLARIS) |
38 #include <ieeefp.h> | 38 #include <ieeefp.h> |
39 #endif | 39 #endif |
40 | 40 |
41 #if OS(OPENBSD) | 41 #if OS(OPENBSD) |
42 #include <sys/types.h> | 42 #include <sys/types.h> |
43 #include <machine/ieee.h> | 43 #include <machine/ieee.h> |
44 #endif | 44 #endif |
45 | 45 |
46 #if OS(QNX) | |
47 // FIXME: Look into a way to have cmath import its functions into both the stand
ard and global | |
48 // namespace. For now, we include math.h since the QNX cmath header only imports
its functions | |
49 // into the standard namespace. | |
50 #include <math.h> | |
51 #endif | |
52 | |
53 #ifndef M_PI | 46 #ifndef M_PI |
54 const double piDouble = 3.14159265358979323846; | 47 const double piDouble = 3.14159265358979323846; |
55 const float piFloat = 3.14159265358979323846f; | 48 const float piFloat = 3.14159265358979323846f; |
56 #else | 49 #else |
57 const double piDouble = M_PI; | 50 const double piDouble = M_PI; |
58 const float piFloat = static_cast<float>(M_PI); | 51 const float piFloat = static_cast<float>(M_PI); |
59 #endif | 52 #endif |
60 | 53 |
61 #ifndef M_PI_2 | 54 #ifndef M_PI_2 |
62 const double piOverTwoDouble = 1.57079632679489661923; | 55 const double piOverTwoDouble = 1.57079632679489661923; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 return integer - num >= 0.5f ? integer - 1.0f : integer; | 127 return integer - num >= 0.5f ? integer - 1.0f : integer; |
135 } | 128 } |
136 inline long long llround(double num) { return static_cast<long long>(round(num))
; } | 129 inline long long llround(double num) { return static_cast<long long>(round(num))
; } |
137 inline long long llroundf(float num) { return static_cast<long long>(roundf(num)
); } | 130 inline long long llroundf(float num) { return static_cast<long long>(roundf(num)
); } |
138 inline long lround(double num) { return static_cast<long>(round(num)); } | 131 inline long lround(double num) { return static_cast<long>(round(num)); } |
139 inline long lroundf(float num) { return static_cast<long>(roundf(num)); } | 132 inline long lroundf(float num) { return static_cast<long>(roundf(num)); } |
140 inline double trunc(double num) { return num > 0 ? floor(num) : ceil(num); } | 133 inline double trunc(double num) { return num > 0 ? floor(num) : ceil(num); } |
141 | 134 |
142 #endif | 135 #endif |
143 | 136 |
144 #if COMPILER(GCC) && OS(QNX) | |
145 // The stdlib on QNX doesn't contain long abs(long). See PR #104666. | |
146 inline long long abs(long num) { return labs(num); } | |
147 #endif | |
148 | |
149 #if OS(ANDROID) || COMPILER(MSVC) | 137 #if OS(ANDROID) || COMPILER(MSVC) |
150 // ANDROID and MSVC's math.h does not currently supply log2 or log2f. | 138 // ANDROID and MSVC's math.h does not currently supply log2 or log2f. |
151 inline double log2(double num) | 139 inline double log2(double num) |
152 { | 140 { |
153 // This constant is roughly M_LN2, which is not provided by default on Windo
ws and Android. | 141 // This constant is roughly M_LN2, which is not provided by default on Windo
ws and Android. |
154 return log(num) / 0.693147180559945309417232121458176568; | 142 return log(num) / 0.693147180559945309417232121458176568; |
155 } | 143 } |
156 | 144 |
157 inline float log2f(float num) | 145 inline float log2f(float num) |
158 { | 146 { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 if (i >> 2) | 433 if (i >> 2) |
446 log2 += 2, i >>= 2; | 434 log2 += 2, i >>= 2; |
447 if (i >> 1) | 435 if (i >> 1) |
448 log2 += 1; | 436 log2 += 1; |
449 return log2; | 437 return log2; |
450 } | 438 } |
451 | 439 |
452 } // namespace WTF | 440 } // namespace WTF |
453 | 441 |
454 #endif // #ifndef WTF_MathExtras_h | 442 #endif // #ifndef WTF_MathExtras_h |
OLD | NEW |