OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkFloatBits.h" | 8 #include "SkFloatBits.h" |
9 #include "SkMathPriv.h" | 9 #include "SkMathPriv.h" |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 } else { | 78 } else { |
79 value <<= exp; | 79 value <<= exp; |
80 } | 80 } |
81 // apply the sign after we check for overflow | 81 // apply the sign after we check for overflow |
82 return SkApplySign(value, SkExtractSign(packed)); | 82 return SkApplySign(value, SkExtractSign(packed)); |
83 } else { | 83 } else { |
84 // apply the sign before we right-shift | 84 // apply the sign before we right-shift |
85 value = SkApplySign(value, SkExtractSign(packed)); | 85 value = SkApplySign(value, SkExtractSign(packed)); |
86 exp = -exp; | 86 exp = -exp; |
87 if (exp > 25) { // underflow | 87 if (exp > 25) { // underflow |
88 #ifdef SK_BUILD_FOR_IOS | |
89 if (exp > 149) return 0; | |
reed1
2014/07/10 18:39:39
Can we perhaps encapsulate this in a helper functi
caryclark
2014/07/10 21:07:03
I commented and gave it a platform independent #de
| |
90 #else | |
88 exp = 25; | 91 exp = 25; |
92 #endif | |
89 } | 93 } |
90 // int add = 0; | 94 // int add = 0; |
91 return value >> exp; | 95 return value >> exp; |
92 } | 96 } |
93 } | 97 } |
94 | 98 |
95 // same as (int)floor(float + 0.5) | 99 // same as (int)floor(float + 0.5) |
96 int32_t SkFloatBits_toIntRound(int32_t packed) { | 100 int32_t SkFloatBits_toIntRound(int32_t packed) { |
97 // curse you negative 0 | 101 // curse you negative 0 |
98 if ((packed << 1) == 0) { | 102 if ((packed << 1) == 0) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 } else { | 142 } else { |
139 value <<= exp; | 143 value <<= exp; |
140 } | 144 } |
141 // apply the sign after we check for overflow | 145 // apply the sign after we check for overflow |
142 return SkApplySign(value, SkExtractSign(packed)); | 146 return SkApplySign(value, SkExtractSign(packed)); |
143 } else { | 147 } else { |
144 // apply the sign before we right-shift | 148 // apply the sign before we right-shift |
145 value = SkApplySign(value, SkExtractSign(packed)); | 149 value = SkApplySign(value, SkExtractSign(packed)); |
146 exp = -exp; | 150 exp = -exp; |
147 if (exp > 25) { // underflow | 151 if (exp > 25) { // underflow |
152 #ifdef SK_BUILD_FOR_IOS | |
153 if (exp > 149) return 0; | |
154 return 0 < value; | |
155 #else | |
148 exp = 25; | 156 exp = 25; |
157 #endif | |
149 } | 158 } |
150 int add = (1 << exp) - 1; | 159 int add = (1 << exp) - 1; |
151 return (value + add) >> exp; | 160 return (value + add) >> exp; |
152 } | 161 } |
153 } | 162 } |
154 | 163 |
155 float SkIntToFloatCast(int32_t value) { | 164 float SkIntToFloatCast(int32_t value) { |
156 if (0 == value) { | 165 if (0 == value) { |
157 return 0; | 166 return 0; |
158 } | 167 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 value = SkApplySign(value, sign); | 206 value = SkApplySign(value, sign); |
198 | 207 |
199 int zeros = SkCLZ(value << 8); | 208 int zeros = SkCLZ(value << 8); |
200 value <<= zeros; | 209 value <<= zeros; |
201 shift -= zeros; | 210 shift -= zeros; |
202 | 211 |
203 SkFloatIntUnion data; | 212 SkFloatIntUnion data; |
204 data.fSignBitInt = (sign << 31) | (shift << 23) | (value & ~MATISSA_MAGIC_BI G); | 213 data.fSignBitInt = (sign << 31) | (shift << 23) | (value & ~MATISSA_MAGIC_BI G); |
205 return data.fFloat; | 214 return data.fFloat; |
206 } | 215 } |
OLD | NEW |