OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkFloatingPoint_DEFINED | 10 #ifndef SkFloatingPoint_DEFINED |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 #include "SkFloatBits.h" | 23 #include "SkFloatBits.h" |
24 | 24 |
25 // C++98 cmath std::pow seems to be the earliest portable way to get float pow. | 25 // C++98 cmath std::pow seems to be the earliest portable way to get float pow. |
26 // However, on Linux including cmath undefines isfinite. | 26 // However, on Linux including cmath undefines isfinite. |
27 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14608 | 27 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14608 |
28 static inline float sk_float_pow(float base, float exp) { | 28 static inline float sk_float_pow(float base, float exp) { |
29 return powf(base, exp); | 29 return powf(base, exp); |
30 } | 30 } |
31 | 31 |
32 static inline float sk_float_copysign(float x, float y) { | |
33 // c++11 contains a 'float copysign(float, float)' function in <cmath>. | |
34 // clang-cl reports __cplusplus for clang, not the __cplusplus vc++ version _MSC
_VER would report. | |
35 #if (defined(_MSC_VER) && defined(__clang__)) | |
36 # define SK_BUILD_WITH_CLANG_CL 1 | |
37 #else | |
38 # define SK_BUILD_WITH_CLANG_CL 0 | |
39 #endif | |
40 #if (!SK_BUILD_WITH_CLANG_CL && __cplusplus >= 201103L) || (_MSC_VER >= 1800) | |
41 return copysignf(x, y); | |
42 | |
43 // Posix has demanded 'float copysignf(float, float)' (from C99) since Issue 6. | |
44 #elif defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L | |
45 return copysignf(x, y); | |
46 | |
47 // Visual studio prior to 13 only has 'double _copysign(double, double)'. | |
48 #elif defined(_MSC_VER) | |
49 return (float)_copysign(x, y); | |
50 | |
51 // Otherwise convert to bits and extract sign. | |
52 #else | |
53 int32_t xbits = SkFloat2Bits(x); | |
54 int32_t ybits = SkFloat2Bits(y); | |
55 return SkBits2Float((xbits & 0x7FFFFFFF) | (ybits & 0x80000000)); | |
56 #endif | |
57 } | |
58 | |
59 #define sk_float_sqrt(x) sqrtf(x) | 32 #define sk_float_sqrt(x) sqrtf(x) |
60 #define sk_float_sin(x) sinf(x) | 33 #define sk_float_sin(x) sinf(x) |
61 #define sk_float_cos(x) cosf(x) | 34 #define sk_float_cos(x) cosf(x) |
62 #define sk_float_tan(x) tanf(x) | 35 #define sk_float_tan(x) tanf(x) |
63 #define sk_float_floor(x) floorf(x) | 36 #define sk_float_floor(x) floorf(x) |
64 #define sk_float_ceil(x) ceilf(x) | 37 #define sk_float_ceil(x) ceilf(x) |
65 #ifdef SK_BUILD_FOR_MAC | 38 #ifdef SK_BUILD_FOR_MAC |
66 # define sk_float_acos(x) static_cast<float>(acos(x)) | 39 # define sk_float_acos(x) static_cast<float>(acos(x)) |
67 # define sk_float_asin(x) static_cast<float>(asin(x)) | 40 # define sk_float_asin(x) static_cast<float>(asin(x)) |
68 #else | 41 #else |
69 # define sk_float_acos(x) acosf(x) | 42 # define sk_float_acos(x) acosf(x) |
70 # define sk_float_asin(x) asinf(x) | 43 # define sk_float_asin(x) asinf(x) |
71 #endif | 44 #endif |
72 #define sk_float_atan2(y,x) atan2f(y,x) | 45 #define sk_float_atan2(y,x) atan2f(y,x) |
73 #define sk_float_abs(x) fabsf(x) | 46 #define sk_float_abs(x) fabsf(x) |
| 47 #define sk_float_copysign(x, y) copysignf(x, y) |
74 #define sk_float_mod(x,y) fmodf(x,y) | 48 #define sk_float_mod(x,y) fmodf(x,y) |
75 #define sk_float_exp(x) expf(x) | 49 #define sk_float_exp(x) expf(x) |
76 #define sk_float_log(x) logf(x) | 50 #define sk_float_log(x) logf(x) |
77 | 51 |
78 #define sk_float_round(x) sk_float_floor((x) + 0.5f) | 52 #define sk_float_round(x) sk_float_floor((x) + 0.5f) |
79 | 53 |
80 // can't find log2f on android, but maybe that just a tool bug? | 54 // can't find log2f on android, but maybe that just a tool bug? |
81 #ifdef SK_BUILD_FOR_ANDROID | 55 #ifdef SK_BUILD_FOR_ANDROID |
82 static inline float sk_float_log2(float x) { | 56 static inline float sk_float_log2(float x) { |
83 const double inv_ln_2 = 1.44269504088896; | 57 const double inv_ln_2 = 1.44269504088896; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 // This is the number of significant digits we can print in a string such that w
hen we read that | 142 // This is the number of significant digits we can print in a string such that w
hen we read that |
169 // string back we get the floating point number we expect. The minimum value C
requires is 6, but | 143 // string back we get the floating point number we expect. The minimum value C
requires is 6, but |
170 // most compilers support 9 | 144 // most compilers support 9 |
171 #ifdef FLT_DECIMAL_DIG | 145 #ifdef FLT_DECIMAL_DIG |
172 #define SK_FLT_DECIMAL_DIG FLT_DECIMAL_DIG | 146 #define SK_FLT_DECIMAL_DIG FLT_DECIMAL_DIG |
173 #else | 147 #else |
174 #define SK_FLT_DECIMAL_DIG 9 | 148 #define SK_FLT_DECIMAL_DIG 9 |
175 #endif | 149 #endif |
176 | 150 |
177 #endif | 151 #endif |
OLD | NEW |