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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 #define sk_float_ceil2int(x) (int)sk_float_ceil(x) | 93 #define sk_float_ceil2int(x) (int)sk_float_ceil(x) |
94 #endif | 94 #endif |
95 | 95 |
96 #define sk_double_floor(x) floor(x) | 96 #define sk_double_floor(x) floor(x) |
97 #define sk_double_round(x) floor((x) + 0.5) | 97 #define sk_double_round(x) floor((x) + 0.5) |
98 #define sk_double_ceil(x) ceil(x) | 98 #define sk_double_ceil(x) ceil(x) |
99 #define sk_double_floor2int(x) (int)floor(x) | 99 #define sk_double_floor2int(x) (int)floor(x) |
100 #define sk_double_round2int(x) (int)floor((x) + 0.5f) | 100 #define sk_double_round2int(x) (int)floor((x) + 0.5f) |
101 #define sk_double_ceil2int(x) (int)ceil(x) | 101 #define sk_double_ceil2int(x) (int)ceil(x) |
102 | 102 |
103 extern const uint32_t gIEEENotANumber; | 103 static const uint32_t kIEEENotANumber = 0x7fffffff; |
104 extern const uint32_t gIEEEInfinity; | 104 #define SK_FloatNaN (*SkTCast<const float*>(&kIEEENotANumber)) |
105 extern const uint32_t gIEEENegativeInfinity; | 105 #define SK_FloatInfinity (+(float)INFINITY) |
106 | 106 #define SK_FloatNegativeInfinity (-(float)INFINITY) |
107 #define SK_FloatNaN (*SkTCast<const float*>(&gIEEENotANumber)) | |
108 #define SK_FloatInfinity (*SkTCast<const float*>(&gIEEEInfinity)) | |
109 #define SK_FloatNegativeInfinity (*SkTCast<const float*>(&gIEEENegativeInfini
ty)) | |
110 | 107 |
111 static inline float sk_float_rsqrt_portable(float x) { | 108 static inline float sk_float_rsqrt_portable(float x) { |
112 // Get initial estimate. | 109 // Get initial estimate. |
113 int i = *SkTCast<int*>(&x); | 110 int i = *SkTCast<int*>(&x); |
114 i = 0x5F1FFFF9 - (i>>1); | 111 i = 0x5F1FFFF9 - (i>>1); |
115 float estimate = *SkTCast<float*>(&i); | 112 float estimate = *SkTCast<float*>(&i); |
116 | 113 |
117 // One step of Newton's method to refine. | 114 // One step of Newton's method to refine. |
118 const float estimate_sq = estimate*estimate; | 115 const float estimate_sq = estimate*estimate; |
119 estimate *= 0.703952253f*(2.38924456f-x*estimate_sq); | 116 estimate *= 0.703952253f*(2.38924456f-x*estimate_sq); |
(...skipping 29 matching lines...) Expand all Loading... |
149 // This is the number of significant digits we can print in a string such that w
hen we read that | 146 // This is the number of significant digits we can print in a string such that w
hen we read that |
150 // string back we get the floating point number we expect. The minimum value C
requires is 6, but | 147 // string back we get the floating point number we expect. The minimum value C
requires is 6, but |
151 // most compilers support 9 | 148 // most compilers support 9 |
152 #ifdef FLT_DECIMAL_DIG | 149 #ifdef FLT_DECIMAL_DIG |
153 #define SK_FLT_DECIMAL_DIG FLT_DECIMAL_DIG | 150 #define SK_FLT_DECIMAL_DIG FLT_DECIMAL_DIG |
154 #else | 151 #else |
155 #define SK_FLT_DECIMAL_DIG 9 | 152 #define SK_FLT_DECIMAL_DIG 9 |
156 #endif | 153 #endif |
157 | 154 |
158 #endif | 155 #endif |
OLD | NEW |