diff options
author | 2018-01-31 15:55:47 -0500 | |
---|---|---|
committer | 2018-01-31 21:21:36 +0000 | |
commit | 3d5a6b5f25b0e1c0bf23106f55e736b1bf0d9be8 (patch) | |
tree | d37b0571949244fd17cca56c9633e0b208444136 /include/private/SkFloatingPoint.h | |
parent | 17823764300ff33ce5969113a818eb8de7cef3fc (diff) |
add saturate helper for float2int64
Bug: skia:
Change-Id: I157f8c047145874c4585ae870018163908389b26
Reviewed-on: https://skia-review.googlesource.com/102321
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'include/private/SkFloatingPoint.h')
-rw-r--r-- | include/private/SkFloatingPoint.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/include/private/SkFloatingPoint.h b/include/private/SkFloatingPoint.h index 05191e651d..bbb117982f 100644 --- a/include/private/SkFloatingPoint.h +++ b/include/private/SkFloatingPoint.h @@ -81,6 +81,9 @@ static inline float sk_float_pow(float base, float exp) { #define SK_MaxS32FitsInFloat 2147483520 #define SK_MinS32FitsInFloat -SK_MaxS32FitsInFloat +#define SK_MaxS64FitsInFloat (SK_MaxS64 >> (63-24) << (63-24)) // 0x7fffff8000000000 +#define SK_MinS64FitsInFloat -SK_MaxS64FitsInFloat + /** * Return the closest int for the given float. Returns SK_MaxS32FitsInFloat for NaN. */ @@ -99,6 +102,15 @@ static inline int sk_double_saturate2int(double x) { return (int)x; } +/** + * Return the closest int64_t for the given float. Returns SK_MaxS64FitsInFloat for NaN. + */ +static inline int64_t sk_float_saturate2int64(float x) { + x = SkTMin<float>(x, SK_MaxS64FitsInFloat); + x = SkTMax<float>(x, SK_MinS64FitsInFloat); + return (int64_t)x; +} + #define sk_float_floor2int(x) sk_float_saturate2int(sk_float_floor(x)) #define sk_float_round2int(x) sk_float_saturate2int(sk_float_floor((x) + 0.5f)) #define sk_float_ceil2int(x) sk_float_saturate2int(sk_float_ceil(x)) |