]> git.saurik.com Git - wxWidgets.git/blame - include/wx/math.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / include / wx / math.h
CommitLineData
83c5e934 1/**
068becf5 2* Name: wx/math.h
83c5e934
WS
3* Purpose: Declarations/definitions of common math functions
4* Author: John Labenski and others
5* Modified by:
6* Created: 02/02/03
99d80019 7* Copyright: (c) John Labenski
83c5e934
WS
8* Licence: wxWindows licence
9*/
10
11/* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
a02afd14
VZ
12
13#ifndef _WX_MATH_H_
14#define _WX_MATH_H_
15
a02afd14
VZ
16#include "wx/defs.h"
17
19edb09c
WS
18#include <math.h>
19
20#ifndef M_PI
21 #define M_PI 3.1415926535897932384626433832795
22#endif
23
97b25378 24/* Scaling factors for various unit conversions: 1 inch = 2.54 cm */
e2bcbdfb 25#ifndef METRIC_CONVERSION_CONSTANT
eb00016c 26 #define METRIC_CONVERSION_CONSTANT (1/25.4)
e2bcbdfb
WS
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
bfdaa917 54#ifdef __cplusplus
a02afd14 55
bfdaa917
VZ
56/* Any C++11 compiler should provide isfinite() */
57#if __cplusplus >= 201103
58 #include <cmath>
59 #define wxFinite(x) std::isfinite(x)
60#elif defined(__VISUALC__) || defined(__BORLANDC__) || defined(__WATCOMC__)
a02afd14
VZ
61 #include <float.h>
62 #define wxFinite(x) _finite(x)
866a7cd7 63#elif defined(__MINGW64_TOOLCHAIN__) || defined(__clang__)
e78c47e3
DS
64 /*
65 add more compilers with C99 support here: using C99 isfinite() is
66 preferable to using BSD-ish finite()
67 */
f256de11
VS
68 #if defined(_GLIBCXX_CMATH) || defined(_LIBCPP_CMATH)
69 // these <cmath> headers #undef isfinite
70 #define wxFinite(x) std::isfinite(x)
71 #else
72 #define wxFinite(x) isfinite(x)
73 #endif
ac9e3f1f 74#elif ( defined(__GNUG__)||defined(__GNUWIN32__)||defined(__DJGPP__)|| \
a02afd14 75 defined(__SGI_CC__)||defined(__SUNCC__)||defined(__XLC__)|| \
2415cf67 76 defined(__HPUX__) ) && ( !defined(wxOSX_USE_IPHONE) || wxOSX_USE_IPHONE == 0 )
d8976354
SN
77#ifdef __SOLARIS__
78#include <ieeefp.h>
79#endif
a02afd14
VZ
80 #define wxFinite(x) finite(x)
81#else
82 #define wxFinite(x) ((x) == (x))
83#endif
84
85
86#if defined(__VISUALC__)||defined(__BORLAND__)
87 #define wxIsNaN(x) _isnan(x)
88#elif defined(__GNUG__)||defined(__GNUWIN32__)||defined(__DJGPP__)|| \
89 defined(__SGI_CC__)||defined(__SUNCC__)||defined(__XLC__)|| \
2415cf67 90 defined(__HPUX__)
4e32eea1 91 #define wxIsNaN(x) isnan(x)
a02afd14
VZ
92#else
93 #define wxIsNaN(x) ((x) != (x))
94#endif
95
bfdaa917 96#ifdef __INTELC__
23f826bd 97
bfdaa917
VZ
98 inline bool wxIsSameDouble(double x, double y)
99 {
100 // VZ: this warning, given for operators==() and !=() is not wrong, as ==
101 // shouldn't be used with doubles, but we get too many of them and
102 // removing these operators is probably not a good idea
103 //
104 // Maybe we should always compare doubles up to some "epsilon" precision
105 #pragma warning(push)
23f826bd 106
bfdaa917
VZ
107 // floating-point equality and inequality comparisons are unreliable
108 #pragma warning(disable: 1572)
23f826bd 109
bfdaa917 110 return x == y;
23f826bd 111
bfdaa917
VZ
112 #pragma warning(pop)
113 }
23f826bd 114
bfdaa917
VZ
115#else /* !__INTELC__ */
116 wxGCC_WARNING_SUPPRESS(float-equal)
117 inline bool wxIsSameDouble(double x, double y) { return x == y; }
118 wxGCC_WARNING_RESTORE(float-equal)
23f826bd 119
bfdaa917 120#endif /* __INTELC__/!__INTELC__ */
23f826bd 121
bfdaa917 122inline bool wxIsNullDouble(double x) { return wxIsSameDouble(x, 0.); }
23f826bd 123
bfdaa917
VZ
124inline int wxRound(double x)
125{
126 wxASSERT_MSG( x > INT_MIN - 0.5 && x < INT_MAX + 0.5,
127 wxT("argument out of supported range") );
128
129 #if defined(HAVE_ROUND)
130 return int(round(x));
131 #else
132 return (int)(x < 0 ? x - 0.5 : x + 0.5);
133 #endif
134}
23f826bd 135
bc14c8b2
VZ
136#endif /* __cplusplus */
137
a02afd14 138
d98a58c5 139#if defined(__WINDOWS__) && !defined(__WXWINCE__)
068becf5 140 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
068becf5 141#else
7ca3cc6f 142 #define wxMulDivInt32( a , b , c ) (wxRound((a)*(((wxDouble)b)/((wxDouble)c))))
068becf5
WS
143#endif
144
17a1ebd1
VZ
145#if wxUSE_APPLE_IEEE
146#ifdef __cplusplus
147 extern "C" {
148#endif
149 /* functions from common/extended.c */
163b3ad7
VZ
150 WXDLLIMPEXP_BASE wxFloat64 wxConvertFromIeeeExtended(const wxInt8 *bytes);
151 WXDLLIMPEXP_BASE void wxConvertToIeeeExtended(wxFloat64 num, wxInt8 *bytes);
225dfbc5
VZ
152
153 /* use wxConvertFromIeeeExtended() and wxConvertToIeeeExtended() instead */
154#if WXWIN_COMPATIBILITY_2_8
163b3ad7
VZ
155 wxDEPRECATED( WXDLLIMPEXP_BASE wxFloat64 ConvertFromIeeeExtended(const wxInt8 *bytes) );
156 wxDEPRECATED( WXDLLIMPEXP_BASE void ConvertToIeeeExtended(wxFloat64 num, wxInt8 *bytes) );
e78c47e3 157#endif
225dfbc5 158
17a1ebd1
VZ
159#ifdef __cplusplus
160 }
161#endif
162#endif /* wxUSE_APPLE_IEEE */
163
164
5f8ba10e 165#endif /* _WX_MATH_H_ */