14 #ifdef __INTEL_COMPILER 16 #define FPU_CONTROLWORD_WRITEMASK 0xFFFFF // if you look at defn of _CW_DEFAULT, all settings fall within 0xFFFFF 17 #define FPU_CONTROLWORD_NEW_SETTING _CW_DEFAULT 47 INLINE
float ctan(
float v) {
55 csincos(
float v,
float *sin_result,
float *cos_result) {
57 #if defined(_M_IX86) || defined(_X86_) 68 *sin_result = sinf(v);
69 *cos_result = cosf(v);
78 if (1.0f + v * v == 1.0f) {
105 catan2(
float y,
float x) {
131 return x - floor(x / y) * y;
138 cpow(
float x,
float y) {
148 #ifdef __INTEL_COMPILER 151 unsigned int saved_fpu_control_word=_controlfp(0x0,0x0);
152 _controlfp(FPU_CONTROLWORD_NEW_SETTING,FPU_CONTROLWORD_WRITEMASK);
153 double retval=floor(f);
154 _controlfp(saved_fpu_control_word,FPU_CONTROLWORD_WRITEMASK);
166 #ifdef __INTEL_COMPILER 169 unsigned int saved_fpu_control_word=_controlfp(0x0,0x0);
170 _controlfp(FPU_CONTROLWORD_NEW_SETTING,FPU_CONTROLWORD_WRITEMASK);
171 double retval=ceil(f);
172 _controlfp(saved_fpu_control_word,FPU_CONTROLWORD_WRITEMASK);
184 return f - cfloor(f);
223 csincos(
double v,
double *sin_result,
double *cos_result) {
224 #if defined(_M_IX86) || defined(_X86_) 235 *sin_result = sin(v);
236 *cos_result = cos(v);
245 if (1.0 + v * v == 1.0) {
272 catan2(
double y,
double x) {
298 return x - cfloor(x / y) * y;
305 cpow(
double x,
double y) {
335 #if __FINITE_MATH_ONLY__ 337 union {
float f; uint32_t x; } u = { v };
338 return ((u.x << 1) > 0xff000000u);
339 #elif !defined(_WIN32) 340 return std::isnan(v);
342 return (_isnan(v) != 0);
351 #if __FINITE_MATH_ONLY__ 353 union {
double d; uint64_t x; } u = { v };
354 return ((u.x << 1) > 0xff70000000000000ull);
355 #elif !defined(_WIN32) 356 return std::isnan(v);
358 return (_isnan(v) != 0);
367 #if __FINITE_MATH_ONLY__ 369 union {
float f; uint32_t x; } u = { v };
370 return ((u.x << 1) == 0xff000000u);
371 #elif !defined(_WIN32) 372 return std::isinf(v);
374 return (_isnan(v) == 0 && _finite(v) == 0);
383 #if __FINITE_MATH_ONLY__ 385 union {
double d; uint64_t x; } u = { v };
386 return ((u.x << 1) == 0xff70000000000000ull);
387 #elif !defined(_WIN32) 388 return std::isinf(v);
390 return (_isnan(v) == 0 && _finite(v) == 0);
399 return std::numeric_limits<float>::quiet_NaN();
407 return std::numeric_limits<double>::quiet_NaN();
415 return std::numeric_limits<float>::infinity();
423 return std::numeric_limits<double>::infinity();
436 return y - 1 - ((-x - 1) % y);
float cmod(float x, float y)
This is similar to fmod(), but it behaves properly when x is negative: that is, it always returns a v...
double cfrac(double f)
Returns the fractional component of f: f - cfloor(f).
float csin_over_x(float v)
Computes sin(x) / x, well-behaved as x approaches 0.