3 * Purpose: Declarations/definitions of common math functions
4 * Author: John Labenski and others
8 * Copyright: (c) John Labenski
9 * Licence: wxWindows licence
12 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
22 #define M_PI 3.1415926535897932384626433832795
25 /* Scaling factors for various unit conversions: 1 inch = 2.54 cm */
26 #ifndef METRIC_CONVERSION_CONSTANT
27 #define METRIC_CONVERSION_CONSTANT (1./254)
31 #define mm2inches (METRIC_CONVERSION_CONSTANT)
35 #define inches2mm (1/(mm2inches))
39 #define mm2twips (METRIC_CONVERSION_CONSTANT*1440)
43 #define twips2mm (1/(mm2twips))
47 #define mm2pt (METRIC_CONVERSION_CONSTANT*72)
51 #define pt2mm (1/(mm2pt))
55 /* unknown __VISAGECC__, __SYMANTECCC__ */
57 #if defined(__VISUALC__) || defined(__BORLANDC__) || defined(__WATCOMC__)
59 #define wxFinite(x) _finite(x)
60 #elif defined(__MINGW64__)
61 // add more compilers with C99 support here: using C99 isfinite() is
62 // preferable to using BSD-ish finite()
63 #define wxFinite(x) isfinite(x)
64 #elif ( defined(__GNUG__)||defined(__GNUWIN32__)||defined(__DJGPP__)|| \
65 defined(__SGI_CC__)||defined(__SUNCC__)||defined(__XLC__)|| \
66 defined(__HPUX__)||defined(__MWERKS__) ) && ( !defined(wxOSX_USE_IPHONE) || wxOSX_USE_IPHONE == 0 )
70 #define wxFinite(x) finite(x)
72 #define wxFinite(x) ((x) == (x))
76 #if defined(__VISUALC__)||defined(__BORLAND__)
77 #define wxIsNaN(x) _isnan(x)
78 #elif defined(__GNUG__)||defined(__GNUWIN32__)||defined(__DJGPP__)|| \
79 defined(__SGI_CC__)||defined(__SUNCC__)||defined(__XLC__)|| \
80 defined(__HPUX__)||defined(__MWERKS__)
81 #define wxIsNaN(x) isnan(x)
83 #define wxIsNaN(x) ((x) != (x))
90 inline bool wxIsSameDouble(double x
, double y
)
92 // VZ: this warning, given for operators==() and !=() is not wrong, as ==
93 // shouldn't be used with doubles, but we get too many of them and
94 // removing these operators is probably not a good idea
96 // Maybe we should alway compare doubles up to some "epsilon" precision
99 // floating-point equality and inequality comparisons are unreliable
100 #pragma warning(disable: 1572)
107 #else /* !__INTELC__ */
109 inline bool wxIsSameDouble(double x
, double y
) { return x
== y
; }
111 #endif /* __INTELC__/!__INTELC__ */
113 inline bool wxIsNullDouble(double x
) { return wxIsSameDouble(x
, 0.); }
115 inline int wxRound(double x
)
117 wxASSERT_MSG( x
> INT_MIN
- 0.5 && x
< INT_MAX
+ 0.5,
118 _T("argument out of supported range") );
120 #if defined(HAVE_ROUND)
121 return int(round(x
));
123 return (int)(x
< 0 ? x
- 0.5 : x
+ 0.5);
126 #endif /* __cplusplus */
129 #if defined(__WXMSW__) && !defined(__WXWINCE__)
130 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
131 #elif defined( __WXMAC__ )
132 #define wxMulDivInt32( a , b , c ) ( (wxInt32) ( ( (wxInt64)(a) * (wxInt64)(b) ) / (wxInt64)(c) ) )
134 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
141 /* functions from common/extended.c */
142 WXDLLIMPEXP_BASE wxFloat64
wxConvertFromIeeeExtended(const wxInt8
*bytes
);
143 WXDLLIMPEXP_BASE
void wxConvertToIeeeExtended(wxFloat64 num
, wxInt8
*bytes
);
145 /* use wxConvertFromIeeeExtended() and wxConvertToIeeeExtended() instead */
146 #if WXWIN_COMPATIBILITY_2_8
147 wxDEPRECATED( WXDLLIMPEXP_BASE wxFloat64
ConvertFromIeeeExtended(const wxInt8
*bytes
) );
148 wxDEPRECATED( WXDLLIMPEXP_BASE
void ConvertToIeeeExtended(wxFloat64 num
, wxInt8
*bytes
) );
149 #endif // WXWIN_COMPATIBILITY_2_8
154 #endif /* wxUSE_APPLE_IEEE */
157 #endif /* _WX_MATH_H_ */