Path: blob/master/thirdparty/sdl/libm/math_private.h
10278 views
/*1* ====================================================2* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.3*4* Developed at SunPro, a Sun Microsystems, Inc. business.5* Permission to use, copy, modify, and distribute this6* software is freely granted, provided that this notice7* is preserved.8* ====================================================9*/1011/*12* from: @(#)fdlibm.h 5.1 93/09/2413* $Id: math_private.h,v 1.3 2004/02/09 07:10:38 andersen Exp $14*/1516#ifndef _MATH_PRIVATE_H_17#define _MATH_PRIVATE_H_1819/* #include <endian.h> */20/* #include <sys/types.h> */2122#define _IEEE_LIBM23#define attribute_hidden24#define libm_hidden_proto(x)25#define libm_hidden_def(x)26#define strong_alias(x, y)27#define weak_alias(x, y)2829#if !defined(SDL_PLATFORM_HAIKU) && !defined(SDL_PLATFORM_PSP) && !defined(SDL_PLATFORM_3DS) && !defined(SDL_PLATFORM_PS2) /* already defined in a system header. */30typedef unsigned int u_int32_t;31#endif3233#define atan SDL_uclibc_atan34#define __ieee754_atan2 SDL_uclibc_atan235#define copysign SDL_uclibc_copysign36#define cos SDL_uclibc_cos37#define __ieee754_exp SDL_uclibc_exp38#define fabs SDL_uclibc_fabs39#define floor SDL_uclibc_floor40#define __ieee754_fmod SDL_uclibc_fmod41#undef __isinf42#define __isinf SDL_uclibc_isinf43#undef __isinff44#define __isinff SDL_uclibc_isinff45#undef __isnan46#define __isnan SDL_uclibc_isnan47#undef __isnanf48#define __isnanf SDL_uclibc_isnanf49#define __ieee754_log SDL_uclibc_log50#define __ieee754_log10 SDL_uclibc_log1051#define modf SDL_uclibc_modf52#define __ieee754_pow SDL_uclibc_pow53#define scalbln SDL_uclibc_scalbln54#define scalbn SDL_uclibc_scalbn55#define sin SDL_uclibc_sin56#define __ieee754_sqrt SDL_uclibc_sqrt57#define tan SDL_uclibc_tan5859/* The original fdlibm code used statements like:60n0 = ((*(int*)&one)>>29)^1; * index of high word *61ix0 = *(n0+(int*)&x); * high word of x *62ix1 = *((1-n0)+(int*)&x); * low word of x *63to dig two 32 bit words out of the 64 bit IEEE floating point64value. That is non-ANSI, and, moreover, the gcc instruction65scheduler gets it wrong. We instead use the following macros.66Unlike the original code, we determine the endianness at compile67time, not at run time; I don't see much benefit to selecting68endianness at run time. */6970/* A union which permits us to convert between a double and two 32 bit71ints. */7273/*74* Math on arm is special:75* For FPA, float words are always big-endian.76* For VFP, floats words follow the memory system mode.77* For Maverick, float words are always little-endian.78*/7980#if (SDL_FLOATWORDORDER == SDL_BIG_ENDIAN)8182typedef union83{84double value;85struct86{87u_int32_t msw;88u_int32_t lsw;89} parts;90} ieee_double_shape_type;9192#else9394typedef union95{96double value;97struct98{99u_int32_t lsw;100u_int32_t msw;101} parts;102} ieee_double_shape_type;103104#endif105106/* Get two 32 bit ints from a double. */107108#define EXTRACT_WORDS(ix0,ix1,d) \109do { \110ieee_double_shape_type ew_u; \111ew_u.value = (d); \112(ix0) = ew_u.parts.msw; \113(ix1) = ew_u.parts.lsw; \114} while (0)115116/* Get the more significant 32 bit int from a double. */117118#define GET_HIGH_WORD(i,d) \119do { \120ieee_double_shape_type gh_u; \121gh_u.value = (d); \122(i) = gh_u.parts.msw; \123} while (0)124125/* Get the less significant 32 bit int from a double. */126127#define GET_LOW_WORD(i,d) \128do { \129ieee_double_shape_type gl_u; \130gl_u.value = (d); \131(i) = gl_u.parts.lsw; \132} while (0)133134/* Set a double from two 32 bit ints. */135136#define INSERT_WORDS(d,ix0,ix1) \137do { \138ieee_double_shape_type iw_u; \139iw_u.parts.msw = (ix0); \140iw_u.parts.lsw = (ix1); \141(d) = iw_u.value; \142} while (0)143144/* Set the more significant 32 bits of a double from an int. */145146#define SET_HIGH_WORD(d,v) \147do { \148ieee_double_shape_type sh_u; \149sh_u.value = (d); \150sh_u.parts.msw = (v); \151(d) = sh_u.value; \152} while (0)153154/* Set the less significant 32 bits of a double from an int. */155156#define SET_LOW_WORD(d,v) \157do { \158ieee_double_shape_type sl_u; \159sl_u.value = (d); \160sl_u.parts.lsw = (v); \161(d) = sl_u.value; \162} while (0)163164/* A union which permits us to convert between a float and a 32 bit165int. */166167typedef union168{169float value;170u_int32_t word;171} ieee_float_shape_type;172173/* Get a 32 bit int from a float. */174175#define GET_FLOAT_WORD(i,d) \176do { \177ieee_float_shape_type gf_u; \178gf_u.value = (d); \179(i) = gf_u.word; \180} while (0)181182/* Set a float from a 32 bit int. */183184#define SET_FLOAT_WORD(d,i) \185do { \186ieee_float_shape_type sf_u; \187sf_u.word = (i); \188(d) = sf_u.value; \189} while (0)190191/* ieee style elementary functions */192extern double __ieee754_sqrt(double) attribute_hidden;193extern double __ieee754_acos(double) attribute_hidden;194extern double __ieee754_acosh(double) attribute_hidden;195extern double __ieee754_log(double) attribute_hidden;196extern double __ieee754_atanh(double) attribute_hidden;197extern double __ieee754_asin(double) attribute_hidden;198extern double __ieee754_atan2(double, double) attribute_hidden;199extern double __ieee754_exp(double) attribute_hidden;200extern double __ieee754_cosh(double) attribute_hidden;201extern double __ieee754_fmod(double, double) attribute_hidden;202extern double __ieee754_pow(double, double) attribute_hidden;203extern double __ieee754_lgamma_r(double, int *) attribute_hidden;204extern double __ieee754_gamma_r(double, int *) attribute_hidden;205extern double __ieee754_lgamma(double) attribute_hidden;206extern double __ieee754_gamma(double) attribute_hidden;207extern double __ieee754_log10(double) attribute_hidden;208extern double __ieee754_sinh(double) attribute_hidden;209extern double __ieee754_hypot(double, double) attribute_hidden;210extern double __ieee754_j0(double) attribute_hidden;211extern double __ieee754_j1(double) attribute_hidden;212extern double __ieee754_y0(double) attribute_hidden;213extern double __ieee754_y1(double) attribute_hidden;214extern double __ieee754_jn(int, double) attribute_hidden;215extern double __ieee754_yn(int, double) attribute_hidden;216extern double __ieee754_remainder(double, double) attribute_hidden;217extern int32_t __ieee754_rem_pio2(double, double *) attribute_hidden;218#if defined(_SCALB_INT)219extern double __ieee754_scalb(double, int) attribute_hidden;220#else221extern double __ieee754_scalb(double, double) attribute_hidden;222#endif223224/* fdlibm kernel function */225#ifndef _IEEE_LIBM226extern double __kernel_standard(double, double, int) attribute_hidden;227#endif228extern double __kernel_sin(double, double, int) attribute_hidden;229extern double __kernel_cos(double, double) attribute_hidden;230extern double __kernel_tan(double, double, int) attribute_hidden;231extern int32_t __kernel_rem_pio2(const double *, double *, int, int, const unsigned int, const int32_t *) attribute_hidden;232233#endif /* _MATH_PRIVATE_H_ */234235236