1/* 2 $License: 3 Copyright (C) 2011 InvenSense Corporation, All Rights Reserved. 4 $ 5 */ 6/******************************************************************************* 7 * 8 * $Id: mlmath.h 5629 2011-06-11 03:13:08Z mcaramello $ 9 * 10 *******************************************************************************/ 11 12#ifndef _ML_MATH_H_ 13#define _ML_MATH_H_ 14 15#ifndef MLMATH 16// This define makes Microsoft pickup things like M_PI 17#define _USE_MATH_DEFINES 18#include <math.h> 19 20#ifdef WIN32 21// Microsoft doesn't follow standards 22#define round(x)(((double)((long long)((x)>0?(x)+.5:(x)-.5)))) 23#define roundf(x)(((float )((long long)((x)>0?(x)+.5f:(x)-.5f)))) 24#endif 25 26#else // MLMATH 27 28#ifdef __cplusplus 29extern "C" { 30#endif 31/* MPL needs below functions */ 32double ml_asin(double); 33double ml_atan(double); 34double ml_atan2(double, double); 35double ml_log(double); 36double ml_sqrt(double); 37double ml_ceil(double); 38double ml_floor(double); 39double ml_cos(double); 40double ml_sin(double); 41double ml_acos(double); 42#ifdef __cplusplus 43} // extern "C" 44#endif 45 46/* 47 * We rename functions here to provide the hook for other 48 * customized math functions. 49 */ 50#define sqrt(x) ml_sqrt(x) 51#define log(x) ml_log(x) 52#define asin(x) ml_asin(x) 53#define atan(x) ml_atan(x) 54#define atan2(x,y) ml_atan2(x,y) 55#define ceil(x) ml_ceil(x) 56#define floor(x) ml_floor(x) 57#define fabs(x) (((x)<0)?-(x):(x)) 58#define round(x) (((double)((long long)((x)>0?(x)+.5:(x)-.5)))) 59#define roundf(x) (((float )((long long)((x)>0?(x)+.5f:(x)-.5f)))) 60#define cos(x) ml_cos(x) 61#define sin(x) ml_sin(x) 62#define acos(x) ml_acos(x) 63 64#define pow(x,y) ml_pow(x,y) 65 66#ifdef LINUX 67/* stubs for float version of math functions */ 68#define cosf(x) ml_cos(x) 69#define sinf(x) ml_sin(x) 70#define atan2f(x,y) ml_atan2(x,y) 71#define sqrtf(x) ml_sqrt(x) 72#endif 73 74 75 76#endif // MLMATH 77 78#ifndef M_PI 79#define M_PI 3.14159265358979 80#endif 81 82#ifndef ABS 83#define ABS(x) (((x)>=0)?(x):-(x)) 84#endif 85 86#ifndef MIN 87#define MIN(x,y) (((x)<(y))?(x):(y)) 88#endif 89 90#ifndef MAX 91#define MAX(x,y) (((x)>(y))?(x):(y)) 92#endif 93 94/*---------------------------*/ 95#endif /* !_ML_MATH_H_ */ 96