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