Home | History | Annotate | Download | only in include
      1 /*
      2  $License:
      3    Copyright 2011 InvenSense, Inc.
      4 
      5  Licensed under the Apache License, Version 2.0 (the "License");
      6  you may not use this file except in compliance with the License.
      7  You may obtain a copy of the License at
      8 
      9  http://www.apache.org/licenses/LICENSE-2.0
     10 
     11  Unless required by applicable law or agreed to in writing, software
     12  distributed under the License is distributed on an "AS IS" BASIS,
     13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  See the License for the specific language governing permissions and
     15  limitations under the License.
     16   $
     17  */
     18 /*******************************************************************************
     19  *
     20  * $Id: mlmath.h 5629 2011-06-11 03:13:08Z mcaramello $
     21  *
     22  *******************************************************************************/
     23 
     24 #ifndef _ML_MATH_H_
     25 #define	_ML_MATH_H_
     26 
     27 #ifndef MLMATH
     28 // This define makes Microsoft pickup things like M_PI
     29 #define _USE_MATH_DEFINES
     30 #include <math.h>
     31 
     32 #ifdef WIN32
     33 // Microsoft doesn't follow standards
     34 #define  round(x)(((double)((long long)((x)>0?(x)+.5:(x)-.5))))
     35 #define roundf(x)(((float )((long long)((x)>0?(x)+.5f:(x)-.5f))))
     36 #endif
     37 
     38 #else  // MLMATH
     39 
     40 #ifdef __cplusplus
     41 extern "C" {
     42 #endif
     43 /* MPL needs below functions */
     44 double	ml_asin(double);
     45 double	ml_atan(double);
     46 double	ml_atan2(double, double);
     47 double	ml_log(double);
     48 double	ml_sqrt(double);
     49 double	ml_ceil(double);
     50 double	ml_floor(double);
     51 double  ml_cos(double);
     52 double  ml_sin(double);
     53 double  ml_acos(double);
     54 #ifdef __cplusplus
     55 } // extern "C"
     56 #endif
     57 
     58 /*
     59  * We rename functions here to provide the hook for other
     60  * customized math functions.
     61  */
     62 #define	sqrt(x)      ml_sqrt(x)
     63 #define	log(x)       ml_log(x)
     64 #define	asin(x)      ml_asin(x)
     65 #define	atan(x)      ml_atan(x)
     66 #define	atan2(x,y)   ml_atan2(x,y)
     67 #define	ceil(x)      ml_ceil(x)
     68 #define	floor(x)     ml_floor(x)
     69 #define fabs(x)      (((x)<0)?-(x):(x))
     70 #define round(x)     (((double)((long long)((x)>0?(x)+.5:(x)-.5))))
     71 #define roundf(x)    (((float )((long long)((x)>0?(x)+.5f:(x)-.5f))))
     72 #define cos(x)       ml_cos(x)
     73 #define sin(x)       ml_sin(x)
     74 #define acos(x)      ml_acos(x)
     75 
     76 #define pow(x,y)     ml_pow(x,y)
     77 
     78 #ifdef LINUX
     79 /* stubs for float version of math functions */
     80 #define cosf(x)      ml_cos(x)
     81 #define sinf(x)      ml_sin(x)
     82 #define atan2f(x,y)  ml_atan2(x,y)
     83 #define sqrtf(x)     ml_sqrt(x)
     84 #endif
     85 
     86 
     87 
     88 #endif // MLMATH
     89 
     90 #ifndef M_PI
     91 #define M_PI 3.14159265358979
     92 #endif
     93 
     94 #ifndef ABS
     95 #define ABS(x) (((x)>=0)?(x):-(x))
     96 #endif
     97 
     98 #ifndef MIN
     99 #define MIN(x,y) (((x)<(y))?(x):(y))
    100 #endif
    101 
    102 #ifndef MAX
    103 #define MAX(x,y) (((x)>(y))?(x):(y))
    104 #endif
    105 
    106 /*---------------------------*/
    107 #endif /* !_ML_MATH_H_ */
    108