• Home
  • Raw
  • Download

Lines Matching +full:float +full:- +full:divide +full:- +full:by +full:- +full:zero

4  * Use of this source code is governed by a BSD-style license that can be
14 #include <float.h>
31 // C++98 cmath std::pow seems to be the earliest portable way to get float pow.
34 static inline float sk_float_pow(float base, float exp) { in sk_float_pow()
46 # define sk_float_acos(x) static_cast<float>(acos(x))
47 # define sk_float_asin(x) static_cast<float>(asin(x))
63 static inline float sk_float_log2(float x) { in sk_float_log2()
65 return (float)(log(x) * inv_ln_2); in sk_float_log2()
71 static inline bool sk_float_isfinite(float x) { in sk_float_isfinite()
75 static inline bool sk_float_isinf(float x) { in sk_float_isinf()
79 static inline bool sk_float_isnan(float x) { in sk_float_isnan()
86 #define SK_MinS32FitsInFloat -SK_MaxS32FitsInFloat
88 #define SK_MaxS64FitsInFloat (SK_MaxS64 >> (63-24) << (63-24)) // 0x7fffff8000000000
89 #define SK_MinS64FitsInFloat -SK_MaxS64FitsInFloat
92 * Return the closest int for the given float. Returns SK_MaxS32FitsInFloat for NaN.
94 static inline int sk_float_saturate2int(float x) { in sk_float_saturate2int()
95 x = SkTMin<float>(x, SK_MaxS32FitsInFloat); in sk_float_saturate2int()
96 x = SkTMax<float>(x, SK_MinS32FitsInFloat); in sk_float_saturate2int()
110 * Return the closest int64_t for the given float. Returns SK_MaxS64FitsInFloat for NaN.
112 static inline int64_t sk_float_saturate2int64(float x) { in sk_float_saturate2int64()
113 x = SkTMin<float>(x, SK_MaxS64FitsInFloat); in sk_float_saturate2int64()
114 x = SkTMax<float>(x, SK_MinS64FitsInFloat); in sk_float_saturate2int64()
133 // Cast double to float, ignoring any warning about too-large finite values being cast to float.
135 // the largest float or infinity (one of the two bracketing representable floats). Good enough!
137 __attribute__((no_sanitize("float-cast-overflow")))
139 static inline float sk_double_to_float(double x) { in sk_double_to_float()
140 return static_cast<float>(x); in sk_double_to_float()
143 #define SK_FloatNaN std::numeric_limits<float>::quiet_NaN()
144 #define SK_FloatInfinity (+std::numeric_limits<float>::infinity())
145 #define SK_FloatNegativeInfinity (-std::numeric_limits<float>::infinity())
147 static inline float sk_float_rsqrt_portable(float x) { in sk_float_rsqrt_portable()
151 i = 0x5F1FFFF9 - (i>>1); in sk_float_rsqrt_portable()
152 float estimate; in sk_float_rsqrt_portable()
156 const float estimate_sq = estimate*estimate; in sk_float_rsqrt_portable()
157 estimate *= 0.703952253f*(2.38924456f-x*estimate_sq); in sk_float_rsqrt_portable()
162 // Compare to name-brand "1.0f / sk_float_sqrt(x)". Should be around 10x faster on SSE, 2x on NEON.
163 static inline float sk_float_rsqrt(float x) { in sk_float_rsqrt()
196 // IEEE defines how float divide behaves for non-finite values and zero-denoms, but C does not
197 // so we have a helper that suppresses the possible undefined-behavior warnings.
200 __attribute__((no_sanitize("float-divide-by-zero")))
202 static inline float sk_ieee_float_divide(float numer, float denom) { in sk_ieee_float_divide()
207 __attribute__((no_sanitize("float-divide-by-zero")))
213 // While we clean up divide by zero, we'll replace places that do divide by zero with this TODO.
214 static inline float sk_ieee_float_divide_TODO_IS_DIVIDE_BY_ZERO_SAFE_HERE(float n, float d) { in sk_ieee_float_divide_TODO_IS_DIVIDE_BY_ZERO_SAFE_HERE()
217 static inline float sk_ieee_double_divide_TODO_IS_DIVIDE_BY_ZERO_SAFE_HERE(double n, double d) { in sk_ieee_double_divide_TODO_IS_DIVIDE_BY_ZERO_SAFE_HERE()