diff options
author | Mike Reed <reed@google.com> | 2017-08-04 15:12:14 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-04 21:25:07 +0000 |
commit | 8addae8b539a2db6ed34d34bf12609fbc0b2d198 (patch) | |
tree | 957dde0e9fb3e289e55ad6f3a1b01387dd0540a4 /include | |
parent | b86aaeb7b0841c2c23f7b36b0bb0520ce2fb3256 (diff) |
just use math.h for converting from float to int
Bug: skia:
Change-Id: I40cce503cd4cef09c671511a705192efc5d67d71
Reviewed-on: https://skia-review.googlesource.com/31002
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/private/SkFloatBits.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/private/SkFloatBits.h b/include/private/SkFloatBits.h index 4909926f13..7a4c708218 100644 --- a/include/private/SkFloatBits.h +++ b/include/private/SkFloatBits.h @@ -11,6 +11,7 @@ #include "SkTypes.h" #include "SkSafe_math.h" +#include <float.h> /** Convert a sign-bit int (i.e. float interpreted as int) into a 2s compliement int. This also converts -0 (0x80000000) to 0. Doing this to a float allows @@ -79,21 +80,33 @@ static inline int32_t pin_double_to_int(double x) { If the value is out of range, or NaN, return +/- SK_MaxS32 */ static inline int32_t SkFloatToIntFloor(float x) { +#ifdef SK_SUPPORT_LEGACY_FLOATBITS return pin_double_to_int(floor(x)); +#else + return (int)floorf(x); +#endif } /** Return the float rounded to an int. If the value is out of range, or NaN, return +/- SK_MaxS32 */ static inline int32_t SkFloatToIntRound(float x) { +#ifdef SK_SUPPORT_LEGACY_FLOATBITS return pin_double_to_int(floor((double)x + 0.5)); +#else + return (int)floorf(x + 0.5f); +#endif } /** Return the ceiling of the float as an int. If the value is out of range, or NaN, return +/- SK_MaxS32 */ static inline int32_t SkFloatToIntCeil(float x) { +#ifdef SK_SUPPORT_LEGACY_FLOATBITS return pin_double_to_int(ceil(x)); +#else + return (int)ceilf(x); +#endif } // Scalar wrappers for float-bit routines |