]>
Commit | Line | Data |
---|---|---|
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 | ||
5f8ba10e | 25 | /* Scaling factors for various unit conversions */ |
e2bcbdfb WS |
26 | #ifndef METRIC_CONVERSION_CONSTANT |
27 | #define METRIC_CONVERSION_CONSTANT 0.0393700787 | |
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) | |
60 | #elif defined(__GNUG__)||defined(__GNUWIN32__)||defined(__DJGPP__)|| \ | |
61 | defined(__SGI_CC__)||defined(__SUNCC__)||defined(__XLC__)|| \ | |
4e32eea1 | 62 | defined(__HPUX__)||defined(__MWERKS__) |
a02afd14 VZ |
63 | #define wxFinite(x) finite(x) |
64 | #else | |
65 | #define wxFinite(x) ((x) == (x)) | |
66 | #endif | |
67 | ||
68 | ||
69 | #if defined(__VISUALC__)||defined(__BORLAND__) | |
70 | #define wxIsNaN(x) _isnan(x) | |
71 | #elif defined(__GNUG__)||defined(__GNUWIN32__)||defined(__DJGPP__)|| \ | |
72 | defined(__SGI_CC__)||defined(__SUNCC__)||defined(__XLC__)|| \ | |
4e32eea1 WS |
73 | defined(__HPUX__)||defined(__MWERKS__) |
74 | #define wxIsNaN(x) isnan(x) | |
a02afd14 VZ |
75 | #else |
76 | #define wxIsNaN(x) ((x) != (x)) | |
77 | #endif | |
78 | ||
bc14c8b2 | 79 | #ifdef __cplusplus |
23f826bd WS |
80 | |
81 | #ifdef __INTELC__ | |
82 | ||
83 | inline bool wxIsSameDouble(double x, double y) | |
84 | { | |
85 | // VZ: this warning, given for operators==() and !=() is not wrong, as == | |
86 | // shouldn't be used with doubles, but we get too many of them and | |
87 | // removing these operators is probably not a good idea | |
88 | // | |
89 | // Maybe we should alway compare doubles up to some "epsilon" precision | |
90 | #pragma warning(push) | |
91 | ||
92 | // floating-point equality and inequality comparisons are unreliable | |
93 | #pragma warning(disable: 1572) | |
94 | ||
95 | return x == y; | |
96 | ||
97 | #pragma warning(pop) | |
98 | } | |
99 | ||
100 | #else /* !__INTELC__ */ | |
101 | ||
102 | inline bool wxIsSameDouble(double x, double y) { return x == y; } | |
103 | ||
104 | #endif /* __INTELC__/!__INTELC__ */ | |
105 | ||
106 | inline bool wxIsNullDouble(double x) { return wxIsSameDouble(x, 0.); } | |
107 | ||
108 | #ifdef __VMS | |
109 | //Missing definition in OpenVMS C++ header files. | |
110 | double round(double __x); | |
111 | #endif | |
112 | inline int wxRound(double x) | |
113 | { | |
114 | #ifdef __VMS | |
115 | return int(round(x)); | |
116 | #else | |
117 | return (int)(x < 0 ? x - 0.5 : x + 0.5); | |
118 | #endif | |
119 | } | |
bc14c8b2 VZ |
120 | #endif /* __cplusplus */ |
121 | ||
a02afd14 | 122 | |
068becf5 WS |
123 | #if defined(__WXMSW__) && !defined(__WXWINCE__) |
124 | #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c ) | |
125 | #elif defined( __WXMAC__ ) | |
126 | #define wxMulDivInt32( a , b , c ) ( (wxInt32) ( ( (wxInt64)(a) * (wxInt64)(b) ) / (wxInt64)(c) ) ) | |
127 | #else | |
128 | #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c)))) | |
129 | #endif | |
130 | ||
17a1ebd1 VZ |
131 | #if wxUSE_APPLE_IEEE |
132 | #ifdef __cplusplus | |
133 | extern "C" { | |
134 | #endif | |
135 | /* functions from common/extended.c */ | |
136 | extern wxFloat64 ConvertFromIeeeExtended(const wxInt8 *bytes); | |
137 | extern void ConvertToIeeeExtended(wxFloat64 num, wxInt8 *bytes); | |
138 | #ifdef __cplusplus | |
139 | } | |
140 | #endif | |
141 | #endif /* wxUSE_APPLE_IEEE */ | |
142 | ||
143 | ||
5f8ba10e | 144 | #endif /* _WX_MATH_H_ */ |