]>
Commit | Line | Data |
---|---|---|
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 | * RCS-ID: $Id$ | |
8 | * Copyright: (c) John Labenski | |
9 | * Licence: wxWindows licence | |
10 | */ | |
11 | ||
12 | /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */ | |
13 | ||
14 | #ifndef _WX_MATH_H_ | |
15 | #define _WX_MATH_H_ | |
16 | ||
17 | #include "wx/defs.h" | |
18 | ||
19 | #include <math.h> | |
20 | ||
21 | #ifndef M_PI | |
22 | #define M_PI 3.1415926535897932384626433832795 | |
23 | #endif | |
24 | ||
25 | /* Scaling factors for various unit conversions: 1 inch = 2.54 cm */ | |
26 | #ifndef METRIC_CONVERSION_CONSTANT | |
27 | #define METRIC_CONVERSION_CONSTANT (1/25.4) | |
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 | ||
55 | /* unknown __VISAGECC__, __SYMANTECCC__ */ | |
56 | ||
57 | #if defined(__VISUALC__) || defined(__BORLANDC__) || defined(__WATCOMC__) | |
58 | #include <float.h> | |
59 | #define wxFinite(x) _finite(x) | |
60 | #elif defined(__MINGW64__) || defined(__clang__) | |
61 | /* | |
62 | add more compilers with C99 support here: using C99 isfinite() is | |
63 | preferable to using BSD-ish finite() | |
64 | */ | |
65 | #define wxFinite(x) isfinite(x) | |
66 | #elif ( defined(__GNUG__)||defined(__GNUWIN32__)||defined(__DJGPP__)|| \ | |
67 | defined(__SGI_CC__)||defined(__SUNCC__)||defined(__XLC__)|| \ | |
68 | defined(__HPUX__) ) && ( !defined(wxOSX_USE_IPHONE) || wxOSX_USE_IPHONE == 0 ) | |
69 | #ifdef __SOLARIS__ | |
70 | #include <ieeefp.h> | |
71 | #endif | |
72 | #define wxFinite(x) finite(x) | |
73 | #else | |
74 | #define wxFinite(x) ((x) == (x)) | |
75 | #endif | |
76 | ||
77 | ||
78 | #if defined(__VISUALC__)||defined(__BORLAND__) | |
79 | #define wxIsNaN(x) _isnan(x) | |
80 | #elif defined(__GNUG__)||defined(__GNUWIN32__)||defined(__DJGPP__)|| \ | |
81 | defined(__SGI_CC__)||defined(__SUNCC__)||defined(__XLC__)|| \ | |
82 | defined(__HPUX__) | |
83 | #define wxIsNaN(x) isnan(x) | |
84 | #else | |
85 | #define wxIsNaN(x) ((x) != (x)) | |
86 | #endif | |
87 | ||
88 | #ifdef __cplusplus | |
89 | ||
90 | #ifdef __INTELC__ | |
91 | ||
92 | inline bool wxIsSameDouble(double x, double y) | |
93 | { | |
94 | // VZ: this warning, given for operators==() and !=() is not wrong, as == | |
95 | // shouldn't be used with doubles, but we get too many of them and | |
96 | // removing these operators is probably not a good idea | |
97 | // | |
98 | // Maybe we should always compare doubles up to some "epsilon" precision | |
99 | #pragma warning(push) | |
100 | ||
101 | // floating-point equality and inequality comparisons are unreliable | |
102 | #pragma warning(disable: 1572) | |
103 | ||
104 | return x == y; | |
105 | ||
106 | #pragma warning(pop) | |
107 | } | |
108 | ||
109 | #else /* !__INTELC__ */ | |
110 | wxGCC_WARNING_SUPPRESS(float-equal) | |
111 | inline bool wxIsSameDouble(double x, double y) { return x == y; } | |
112 | wxGCC_WARNING_RESTORE(float-equal) | |
113 | ||
114 | #endif /* __INTELC__/!__INTELC__ */ | |
115 | ||
116 | inline bool wxIsNullDouble(double x) { return wxIsSameDouble(x, 0.); } | |
117 | ||
118 | inline int wxRound(double x) | |
119 | { | |
120 | wxASSERT_MSG( x > INT_MIN - 0.5 && x < INT_MAX + 0.5, | |
121 | wxT("argument out of supported range") ); | |
122 | ||
123 | #if defined(HAVE_ROUND) | |
124 | return int(round(x)); | |
125 | #else | |
126 | return (int)(x < 0 ? x - 0.5 : x + 0.5); | |
127 | #endif | |
128 | } | |
129 | #endif /* __cplusplus */ | |
130 | ||
131 | ||
132 | #if defined(__WINDOWS__) && !defined(__WXWINCE__) | |
133 | #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c ) | |
134 | #else | |
135 | #define wxMulDivInt32( a , b , c ) (wxRound((a)*(((wxDouble)b)/((wxDouble)c)))) | |
136 | #endif | |
137 | ||
138 | #if wxUSE_APPLE_IEEE | |
139 | #ifdef __cplusplus | |
140 | extern "C" { | |
141 | #endif | |
142 | /* functions from common/extended.c */ | |
143 | WXDLLIMPEXP_BASE wxFloat64 wxConvertFromIeeeExtended(const wxInt8 *bytes); | |
144 | WXDLLIMPEXP_BASE void wxConvertToIeeeExtended(wxFloat64 num, wxInt8 *bytes); | |
145 | ||
146 | /* use wxConvertFromIeeeExtended() and wxConvertToIeeeExtended() instead */ | |
147 | #if WXWIN_COMPATIBILITY_2_8 | |
148 | wxDEPRECATED( WXDLLIMPEXP_BASE wxFloat64 ConvertFromIeeeExtended(const wxInt8 *bytes) ); | |
149 | wxDEPRECATED( WXDLLIMPEXP_BASE void ConvertToIeeeExtended(wxFloat64 num, wxInt8 *bytes) ); | |
150 | #endif | |
151 | ||
152 | #ifdef __cplusplus | |
153 | } | |
154 | #endif | |
155 | #endif /* wxUSE_APPLE_IEEE */ | |
156 | ||
157 | ||
158 | #endif /* _WX_MATH_H_ */ |