2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkFloatingPoint_DEFINED
|
|
|
|
#define SkFloatingPoint_DEFINED
|
|
|
|
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
|
|
|
#include "SkFloatBits.h"
|
|
|
|
|
2012-07-25 17:00:47 +00:00
|
|
|
// C++98 cmath std::pow seems to be the earliest portable way to get float pow.
|
|
|
|
// However, on Linux including cmath undefines isfinite.
|
|
|
|
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14608
|
2009-04-03 14:26:10 +00:00
|
|
|
static inline float sk_float_pow(float base, float exp) {
|
2012-07-25 17:00:47 +00:00
|
|
|
return powf(base, exp);
|
2009-04-03 14:26:10 +00:00
|
|
|
}
|
|
|
|
|
2010-02-09 18:30:59 +00:00
|
|
|
static inline float sk_float_copysign(float x, float y) {
|
|
|
|
int32_t xbits = SkFloat2Bits(x);
|
|
|
|
int32_t ybits = SkFloat2Bits(y);
|
|
|
|
return SkBits2Float((xbits & 0x7FFFFFFF) | (ybits & 0x80000000));
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifdef SK_BUILD_FOR_WINCE
|
|
|
|
#define sk_float_sqrt(x) (float)::sqrt(x)
|
|
|
|
#define sk_float_sin(x) (float)::sin(x)
|
|
|
|
#define sk_float_cos(x) (float)::cos(x)
|
|
|
|
#define sk_float_tan(x) (float)::tan(x)
|
|
|
|
#define sk_float_acos(x) (float)::acos(x)
|
|
|
|
#define sk_float_asin(x) (float)::asin(x)
|
|
|
|
#define sk_float_atan2(y,x) (float)::atan2(y,x)
|
|
|
|
#define sk_float_abs(x) (float)::fabs(x)
|
|
|
|
#define sk_float_mod(x,y) (float)::fmod(x,y)
|
|
|
|
#define sk_float_exp(x) (float)::exp(x)
|
|
|
|
#define sk_float_log(x) (float)::log(x)
|
|
|
|
#define sk_float_floor(x) (float)::floor(x)
|
|
|
|
#define sk_float_ceil(x) (float)::ceil(x)
|
|
|
|
#else
|
|
|
|
#define sk_float_sqrt(x) sqrtf(x)
|
|
|
|
#define sk_float_sin(x) sinf(x)
|
|
|
|
#define sk_float_cos(x) cosf(x)
|
|
|
|
#define sk_float_tan(x) tanf(x)
|
|
|
|
#define sk_float_floor(x) floorf(x)
|
|
|
|
#define sk_float_ceil(x) ceilf(x)
|
|
|
|
#ifdef SK_BUILD_FOR_MAC
|
2009-01-15 14:38:33 +00:00
|
|
|
#define sk_float_acos(x) static_cast<float>(acos(x))
|
|
|
|
#define sk_float_asin(x) static_cast<float>(asin(x))
|
2008-12-17 15:59:43 +00:00
|
|
|
#else
|
|
|
|
#define sk_float_acos(x) acosf(x)
|
|
|
|
#define sk_float_asin(x) asinf(x)
|
|
|
|
#endif
|
2011-12-05 21:47:25 +00:00
|
|
|
#define sk_float_atan2(y,x) atan2f(y,x)
|
2008-12-17 15:59:43 +00:00
|
|
|
#define sk_float_abs(x) fabsf(x)
|
|
|
|
#define sk_float_mod(x,y) fmodf(x,y)
|
|
|
|
#define sk_float_exp(x) expf(x)
|
|
|
|
#define sk_float_log(x) logf(x)
|
|
|
|
#endif
|
|
|
|
|
2011-12-05 21:47:25 +00:00
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
|
|
|
#define sk_float_isfinite(x) _finite(x)
|
2011-12-06 20:18:05 +00:00
|
|
|
#define sk_float_isnan(x) _isnan(x)
|
|
|
|
static inline int sk_float_isinf(float x) {
|
|
|
|
int32_t bits = SkFloat2Bits(x);
|
|
|
|
return (bits << 1) == (0xFF << 24);
|
|
|
|
}
|
2011-12-05 21:47:25 +00:00
|
|
|
#else
|
|
|
|
#define sk_float_isfinite(x) isfinite(x)
|
2011-12-06 20:18:05 +00:00
|
|
|
#define sk_float_isnan(x) isnan(x)
|
|
|
|
#define sk_float_isinf(x) isinf(x)
|
2011-12-05 21:47:25 +00:00
|
|
|
#endif
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifdef SK_USE_FLOATBITS
|
|
|
|
#define sk_float_floor2int(x) SkFloatToIntFloor(x)
|
|
|
|
#define sk_float_round2int(x) SkFloatToIntRound(x)
|
|
|
|
#define sk_float_ceil2int(x) SkFloatToIntCeil(x)
|
|
|
|
#else
|
|
|
|
#define sk_float_floor2int(x) (int)sk_float_floor(x)
|
|
|
|
#define sk_float_round2int(x) (int)sk_float_floor((x) + 0.5f)
|
|
|
|
#define sk_float_ceil2int(x) (int)sk_float_ceil(x)
|
|
|
|
#endif
|
|
|
|
|
2012-11-02 19:50:26 +00:00
|
|
|
extern const uint32_t gIEEENotANumber;
|
|
|
|
extern const uint32_t gIEEEInfinity;
|
|
|
|
|
|
|
|
#define SK_FloatNaN (*reinterpret_cast<const float*>(&gIEEENotANumber))
|
|
|
|
#define SK_FloatInfinity (*reinterpret_cast<const float*>(&gIEEEInfinity))
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#endif
|