1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2006 - INRIA
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 #ifndef __BASE_MATH_H__
17 #define __BASE_MATH_H__
18 
19 #ifdef _MSC_VER
20 #define NOMINMAX
21 #endif
22 
23 #include <limits.h>
24 #include <math.h>
25 
26 #ifdef __STDC__
27 #include <stdlib.h>
28 #endif
29 
30 
31 #ifdef _MSC_VER     //windows
32 #include <float.h>
33 #define finite(x) _finite(x)
34 #else               //linux & mac
35 #ifdef __cplusplus // C++
36 #include <cmath>   // for std::ifinite
37 #define finite(x) std::isfinite(x)
38 #else
39 #if defined(__APPLE__)
40 #define finite(x) isfinite(x)
41 #endif
42 #endif /* __cplusplus */
43 #endif /* _MSC_VER */
44 
45 #ifdef _MSC_VER     // windows
46 #include <float.h>
47 #define ISNAN(x) _isnan(x)
48 #else
49 #ifndef __cplusplus // C
50 #define ISNAN(x) isnan(x)
51 #else //C++
52 #define ISNAN(x) std::isnan(x)
53 #endif
54 #endif
55 
56 #define Abs(x) ( ( (x) >= 0) ? (x) : -( x) )
57 #ifndef Min
58 #define Min(x,y)	(((x)<(y))?(x):(y))
59 #endif
60 
61 #ifndef Max
62 #define Max(x,y)	(((x)>(y))?(x):(y))
63 #endif
64 
65 #define PI0 (int *) 0
66 #define PD0 (double *) 0
67 #define SMDOUBLE 1.e-200 /* Smalest number to avoid dividing by zero */
68 
69 /* angle conversion */
70 #define PI_OVER_180  0.01745329251994329576913914624236578987393
71 #define _180_OVER_PI 57.29577951308232087665461840231273527024
72 #define DEG2RAD(x) ((x) * PI_OVER_180  )
73 #define RAD2DEG(x) ((x) * _180_OVER_PI )
74 
75 #define scilab_round(a)	(int)(((a)<0.0)?(a)-.5:(a)+.5)
76 #define EPSILON 1.0e-13
77 
78 
79 /**
80   if we suppose that the x transmited is in the range of integers
81   we could also use :
82   #define inint(x) (( x > 0 ) ? ((int) (x + 0.5)) : ((int) (x - 0.5));
83  **/
84 
85 #define linint(x) ((int)  floor(x + 0.5 ))
86 #define inint(x) ((int) floor(x + 0.5 ))
87 
88 #if (defined(sun) && defined(SYSV))
89 #include <ieeefp.h>
90 #endif
91 
92 #if defined(_MSC_VER)
93 #define M_PI 3.14159265358979323846
94 #else
95 #if defined(HAVE_VALUES_H)
96 #include <values.h>
97 #else
98 #if defined(HAVE_LIMITS_H)
99 #include <limits.h>
100 #endif
101 #endif
102 #endif
103 
104 #ifndef M_PI
105 #define M_PI 3.14159265358979323846
106 #endif
107 
108 #ifndef HAVE_EXP10
109 #define log_10_ 2.3025850929940456840179914546844
110 /* Provide a macro to do exp10 */
111 #define exp10(x) exp( (log_10_) * (x) )
112 #endif
113 
114 #endif /* __BASE_MATH_H__ */
115 
116