kb_machblue_core_math.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:4k
- //*****************************************************************************
- //File Name: kb_machblue_core_math.c
- //
- //Description: math function
- //
- // used by Machblue to access the platform's math api.
- //
- //Author: steven
- //
- //Date: 2006.12.29
- //
- //Version: v1.0
- //*****************************************************************************
- #include "stdio.h"
- #include "stdlib.h"
- #include "math.h"
- typedef union
- {
- struct
- {
- unsigned int lsw;
- unsigned int msw;
- }parts;
- double value;
- }mb_double_shape_type;
- /**
- * Initializes the random number generator.
- * seed < seed number >
-
- * @return none.
- */
- void mb_srand(unsigned int seed)
- {
- srand(seed) ;
- }
- /**
- * @return a random number between 0 and mb_rand_max().
- */
- int mb_rand( void )
- {
- return rand();
- }
- /**
- * @return the value of the maximum random number that can be returned by
- * mb_rand().
- */
- int mb_rand_max(void)
- {
- return RAND_MAX;
- }
- /**
- * @return the absolute value of x.
- */
- float mb_fabsf(float x)
- {
- return (float)fabs(x);
- }
- /**
- * @return the Arc Cosine of x.
- */
- float mb_acosf(float x)
- {
- return (float)acos(x);
- }
- /**
- * @return the Arc Sine of x.
- */
- float mb_asinf(float x)
- {
- return (float)asin(x);
- }
- /**
- * @return the Arc Tangent of x ( ]-pi/2,pi/2[ resolution ).
- */
- float mb_atanf(float x)
- {
- return (float)atan(x);
- }
- /**
- * @return the Arc Tangent of (y / x) for ]-pi,pi] / {-pi/2,pi/2} resolution.
- */
- float mb_atan2f(float y,float x)
- {
- return (float)atan2(y, x);
- }
- /**
- * @return the Cosine of x.
- */
- float mb_cosf(float x)
- {
- return (float)cos(x);
- }
- /**
- * @return the Sine of x.
- */
- float mb_sinf(float x)
- {
- return (float)sin(x);
- }
- /**
- * @return the Tangent of x.
- */
- float mb_tanf(float x)
- {
- #ifdef _SH4GCC_
- /* Our SH4 linux implementation cannot calculate tan of PI/4. */
- if(x == (float)(PI/4.0))
- {
- return 1.0;
- }
- #endif
- return (float)tan(x);
- }
- /**
- * @return the Exponential of x.
- */
- float mb_expf(float x)
- {
- return (float)exp(x);
- }
- /**
- * @return the Natural Logarithm of x.
- */
- float mb_logf(float x)
- {
- return (float)log10(x);
- }
- /**
- * @return the x raised to the power of y.
- */
- float mb_powf(float x,float y)
- {
- return (float)pow(x,y);
- }
- /**
- * @return the square root of x.
- */
- float mb_sqrtf(float x)
- {
- return (float)sqrt(x);
- }
- /**
- * @return the largest integer smaller than x.
- */
- float mb_floorf(float x)
- {
- return (float)floor(x);
- }
- /**
- * @return the smallest integer larger than x.
- */
- float mb_ceilf(float x)
- {
- return (float)ceil(x);
- }
- /**
- * @return the reminder of x / y (double version).
- */
- double mb_fmod(double x,double y)
- {
- return fmod(x, y);
- }
- /**
- * @return the reminder of x / y (float version).
- */
- float mb_fmodf(float x,float y)
- {
- return (float)fmod(x, y);
- }
- static int isnan_f (float x) { return x != x; }
- static int isnan_d (double x) { return x != x; }
- static int isnan_ld (long double x) { return x != x; }
- /**
- * @return non zero if x is not a number, 0 otherwise.
- */
- int mb_isnan(double x)
- {
- #if 1
- return (sizeof (x) == sizeof (long double) ? isnan_ld (x)
- : sizeof (x) == sizeof (double) ? isnan_d (x)
- : isnan_f (x));
- #else
- return 0;
- #endif
- }
- /**
- * @return non zero if x is a finite number, 0 otherwise.
- */
- int mb_finite(double x)
- {
- #if 1
- int hx,rc;
- mb_double_shape_type gh_u;
-
- gh_u.value = x;
- hx = gh_u.parts.msw;
- rc=(int)((unsigned int)((hx&0x7fffffff)-0x7ff00000)>>31);
- if(rc==0) return 0;
- else return rc;
- #else
- return 0;
- #endif
- }