]> git.saurik.com Git - wxWidgets.git/blob - include/wx/math.h
wxDialogBase only has one ctor, so just do initialization in ctor instead of Init()
[wxWidgets.git] / include / wx / math.h
1 /**
2 * Name: wx/math.h
3 * Purpose: Declarations/definitions of common math functions
4 * Author: John Labenski and others
5 * Modified by:
6 * Created: 02/02/03
7 * Copyright: (c) John Labenski
8 * Licence: wxWindows licence
9 */
10
11 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
12
13 #ifndef _WX_MATH_H_
14 #define _WX_MATH_H_
15
16 #include "wx/defs.h"
17
18 #include <math.h>
19
20 #ifndef M_PI
21 #define M_PI 3.1415926535897932384626433832795
22 #endif
23
24 /* Scaling factors for various unit conversions: 1 inch = 2.54 cm */
25 #ifndef METRIC_CONVERSION_CONSTANT
26 #define METRIC_CONVERSION_CONSTANT (1/25.4)
27 #endif
28
29 #ifndef mm2inches
30 #define mm2inches (METRIC_CONVERSION_CONSTANT)
31 #endif
32
33 #ifndef inches2mm
34 #define inches2mm (1/(mm2inches))
35 #endif
36
37 #ifndef mm2twips
38 #define mm2twips (METRIC_CONVERSION_CONSTANT*1440)
39 #endif
40
41 #ifndef twips2mm
42 #define twips2mm (1/(mm2twips))
43 #endif
44
45 #ifndef mm2pt
46 #define mm2pt (METRIC_CONVERSION_CONSTANT*72)
47 #endif
48
49 #ifndef pt2mm
50 #define pt2mm (1/(mm2pt))
51 #endif
52
53
54 /* unknown __VISAGECC__, __SYMANTECCC__ */
55
56 #if defined(__VISUALC__) || defined(__BORLANDC__) || defined(__WATCOMC__)
57 #include <float.h>
58 #define wxFinite(x) _finite(x)
59 #elif defined(__MINGW64__) || defined(__clang__)
60 /*
61 add more compilers with C99 support here: using C99 isfinite() is
62 preferable to using BSD-ish finite()
63 */
64 #if defined(_GLIBCXX_CMATH) || defined(_LIBCPP_CMATH)
65 // these <cmath> headers #undef isfinite
66 #define wxFinite(x) std::isfinite(x)
67 #else
68 #define wxFinite(x) isfinite(x)
69 #endif
70 #elif ( defined(__GNUG__)||defined(__GNUWIN32__)||defined(__DJGPP__)|| \
71 defined(__SGI_CC__)||defined(__SUNCC__)||defined(__XLC__)|| \
72 defined(__HPUX__) ) && ( !defined(wxOSX_USE_IPHONE) || wxOSX_USE_IPHONE == 0 )
73 #ifdef __SOLARIS__
74 #include <ieeefp.h>
75 #endif
76 #define wxFinite(x) finite(x)
77 #else
78 #define wxFinite(x) ((x) == (x))
79 #endif
80
81
82 #if defined(__VISUALC__)||defined(__BORLAND__)
83 #define wxIsNaN(x) _isnan(x)
84 #elif defined(__GNUG__)||defined(__GNUWIN32__)||defined(__DJGPP__)|| \
85 defined(__SGI_CC__)||defined(__SUNCC__)||defined(__XLC__)|| \
86 defined(__HPUX__)
87 #define wxIsNaN(x) isnan(x)
88 #else
89 #define wxIsNaN(x) ((x) != (x))
90 #endif
91
92 #ifdef __cplusplus
93
94 #ifdef __INTELC__
95
96 inline bool wxIsSameDouble(double x, double y)
97 {
98 // VZ: this warning, given for operators==() and !=() is not wrong, as ==
99 // shouldn't be used with doubles, but we get too many of them and
100 // removing these operators is probably not a good idea
101 //
102 // Maybe we should always compare doubles up to some "epsilon" precision
103 #pragma warning(push)
104
105 // floating-point equality and inequality comparisons are unreliable
106 #pragma warning(disable: 1572)
107
108 return x == y;
109
110 #pragma warning(pop)
111 }
112
113 #else /* !__INTELC__ */
114 wxGCC_WARNING_SUPPRESS(float-equal)
115 inline bool wxIsSameDouble(double x, double y) { return x == y; }
116 wxGCC_WARNING_RESTORE(float-equal)
117
118 #endif /* __INTELC__/!__INTELC__ */
119
120 inline bool wxIsNullDouble(double x) { return wxIsSameDouble(x, 0.); }
121
122 inline int wxRound(double x)
123 {
124 wxASSERT_MSG( x > INT_MIN - 0.5 && x < INT_MAX + 0.5,
125 wxT("argument out of supported range") );
126
127 #if defined(HAVE_ROUND)
128 return int(round(x));
129 #else
130 return (int)(x < 0 ? x - 0.5 : x + 0.5);
131 #endif
132 }
133 #endif /* __cplusplus */
134
135
136 #if defined(__WINDOWS__) && !defined(__WXWINCE__)
137 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
138 #else
139 #define wxMulDivInt32( a , b , c ) (wxRound((a)*(((wxDouble)b)/((wxDouble)c))))
140 #endif
141
142 #if wxUSE_APPLE_IEEE
143 #ifdef __cplusplus
144 extern "C" {
145 #endif
146 /* functions from common/extended.c */
147 WXDLLIMPEXP_BASE wxFloat64 wxConvertFromIeeeExtended(const wxInt8 *bytes);
148 WXDLLIMPEXP_BASE void wxConvertToIeeeExtended(wxFloat64 num, wxInt8 *bytes);
149
150 /* use wxConvertFromIeeeExtended() and wxConvertToIeeeExtended() instead */
151 #if WXWIN_COMPATIBILITY_2_8
152 wxDEPRECATED( WXDLLIMPEXP_BASE wxFloat64 ConvertFromIeeeExtended(const wxInt8 *bytes) );
153 wxDEPRECATED( WXDLLIMPEXP_BASE void ConvertToIeeeExtended(wxFloat64 num, wxInt8 *bytes) );
154 #endif
155
156 #ifdef __cplusplus
157 }
158 #endif
159 #endif /* wxUSE_APPLE_IEEE */
160
161
162 #endif /* _WX_MATH_H_ */