3 * Purpose: Declarations/definitions of common math functions
4 * Author: John Labenski and others
7 * Copyright: (c) John Labenski
8 * Licence: wxWindows licence
11 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
21 #define M_PI 3.1415926535897932384626433832795
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)
30 #define mm2inches (METRIC_CONVERSION_CONSTANT)
34 #define inches2mm (1/(mm2inches))
38 #define mm2twips (METRIC_CONVERSION_CONSTANT*1440)
42 #define twips2mm (1/(mm2twips))
46 #define mm2pt (METRIC_CONVERSION_CONSTANT*72)
50 #define pt2mm (1/(mm2pt))
56 /* Any C++11 compiler should provide isfinite() */
57 #if __cplusplus >= 201103
59 #define wxFinite(x) std::isfinite(x)
60 #elif defined(__VISUALC__) || defined(__BORLANDC__) || defined(__WATCOMC__)
62 #define wxFinite(x) _finite(x)
63 #elif defined(__MINGW64_TOOLCHAIN__) || defined(__clang__)
65 add more compilers with C99 support here: using C99 isfinite() is
66 preferable to using BSD-ish finite()
68 #if defined(_GLIBCXX_CMATH) || defined(_LIBCPP_CMATH)
69 // these <cmath> headers #undef isfinite
70 #define wxFinite(x) std::isfinite(x)
72 #define wxFinite(x) isfinite(x)
74 #elif ( defined(__GNUG__)||defined(__GNUWIN32__)||defined(__DJGPP__)|| \
75 defined(__SGI_CC__)||defined(__SUNCC__)||defined(__XLC__)|| \
76 defined(__HPUX__) ) && ( !defined(wxOSX_USE_IPHONE) || wxOSX_USE_IPHONE == 0 )
80 #define wxFinite(x) finite(x)
82 #define wxFinite(x) ((x) == (x))
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__)|| \
91 #define wxIsNaN(x) isnan(x)
93 #define wxIsNaN(x) ((x) != (x))
98 inline bool wxIsSameDouble(double x
, double y
)
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
104 // Maybe we should always compare doubles up to some "epsilon" precision
105 #pragma warning(push)
107 // floating-point equality and inequality comparisons are unreliable
108 #pragma warning(disable: 1572)
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
)
120 #endif /* __INTELC__/!__INTELC__ */
122 inline bool wxIsNullDouble(double x
) { return wxIsSameDouble(x
, 0.); }
124 inline int wxRound(double x
)
126 wxASSERT_MSG( x
> INT_MIN
- 0.5 && x
< INT_MAX
+ 0.5,
127 wxT("argument out of supported range") );
129 #if defined(HAVE_ROUND)
130 return int(round(x
));
132 return (int)(x
< 0 ? x
- 0.5 : x
+ 0.5);
136 #endif /* __cplusplus */
139 #if defined(__WINDOWS__) && !defined(__WXWINCE__)
140 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
142 #define wxMulDivInt32( a , b , c ) (wxRound((a)*(((wxDouble)b)/((wxDouble)c))))
149 /* functions from common/extended.c */
150 WXDLLIMPEXP_BASE wxFloat64
wxConvertFromIeeeExtended(const wxInt8
*bytes
);
151 WXDLLIMPEXP_BASE
void wxConvertToIeeeExtended(wxFloat64 num
, wxInt8
*bytes
);
153 /* use wxConvertFromIeeeExtended() and wxConvertToIeeeExtended() instead */
154 #if WXWIN_COMPATIBILITY_2_8
155 wxDEPRECATED( WXDLLIMPEXP_BASE wxFloat64
ConvertFromIeeeExtended(const wxInt8
*bytes
) );
156 wxDEPRECATED( WXDLLIMPEXP_BASE
void ConvertToIeeeExtended(wxFloat64 num
, wxInt8
*bytes
) );
162 #endif /* wxUSE_APPLE_IEEE */
165 #endif /* _WX_MATH_H_ */