/** Return x cast to a float (i.e. (float)x)
*/
float SkIntToFloatCast(int x);
-float SkIntToFloatCast_NoOverflowCheck(int x);
/** Return the float cast to an int.
If the value is out of range, or NaN, return +/- SK_MaxS32
data.fSignBitInt = (sign << 31) | (shift << 23) | (value & ~MATISSA_MAGIC_BIG);
return data.fFloat;
}
-
-float SkIntToFloatCast_NoOverflowCheck(int32_t value) {
- if (0 == value) {
- return 0;
- }
-
- int shift = EXP_BIAS;
-
- // record the sign and make value positive
- int sign = SkExtractSign(value);
- value = SkApplySign(value, sign);
-
- int zeros = SkCLZ(value << 8);
- value <<= zeros;
- shift -= zeros;
-
- SkFloatIntUnion data;
- data.fSignBitInt = (sign << 31) | (shift << 23) | (value & ~MATISSA_MAGIC_BIG);
- return data.fFloat;
-}
static void test_int2float(skiatest::Reporter* reporter, int ival) {
float x0 = (float)ival;
float x1 = SkIntToFloatCast(ival);
- float x2 = SkIntToFloatCast_NoOverflowCheck(ival);
REPORTER_ASSERT(reporter, x0 == x1);
- REPORTER_ASSERT(reporter, x0 == x2);
}
static void unittest_fastfloat(skiatest::Reporter* reporter) {