AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mathconf.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 
4 #ifndef INCLUDED_SAL_MATHCONF_H
5 #define INCLUDED_SAL_MATHCONF_H
6 
7 #include "osl/endian.h"
8 
9 #if defined __sun
10 #include <ieeefp.h>
11 #endif /* __sun */
12 
13 #if defined(__cplusplus) && ( defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L )
14 #include <cmath>
15 #endif
16 
17 #if defined(IOS)
18 #if defined(__cplusplus)
19 #include <cmath>
20 #else
21 #include <math.h>
22 #endif
23 #endif
24 
25 #if defined __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 
29 
30 /* Generally, the C standard guarantees that at program startup, "trapping or
31  stopping (if supported) is disabled on all [floating-point] exceptions"
32  (F.7.3/1 of the August 3, 1998 draft of C99), and that during program
33  execution, "a programmer can safely assume default modes (or be unaware of
34  them)" (7.6/2, footnote 161 of the August 3, 1998 draft of C99). Reportedly,
35  on Windows there are printer drivers that switch on exceptions. To avoid
36  problems, the SAL_MATH_FPEXCEPTIONS_OFF macro can be used to explicitly
37  switch off exceptions (on Windows).
38  */
39 #if defined(_WIN32)
40 #define SAL_MATH_FPEXCEPTIONS_OFF() _control87( _MCW_EM, _MCW_EM )
41 #else /* WNT */
42 #define SAL_MATH_FPEXCEPTIONS_OFF()
43 #endif /* WNT */
44 
45 
46 /* SAL_MATH_FINITE(d): test double d on INFINITY, NaN et al. */
47 #if !defined __sun && !defined ANDROID \
48  && defined(__cplusplus) \
49  && ( defined(__GXX_EXPERIMENTAL_CXX0X__) \
50  || __cplusplus >= 201103L \
51  || defined(IOS) )
52 #define SAL_MATH_FINITE(d) std::isfinite(d)
53 #elif defined __APPLE__ && !(defined __i386__ || defined __x86_64__)
54 #define SAL_MATH_FINITE(d) isfinite(d)
55 #elif defined( WNT)
56 #define SAL_MATH_FINITE(d) _finite(d)
57 #elif defined(ANDROID) || defined LINUX || defined UNX
58 #define SAL_MATH_FINITE(d) finite(d)
59 #else /* WNT, LINUX, UNX */
60 #error "SAL_MATH_FINITE not defined"
61 #endif /* WNT, LINUX, UNX */
62 
63 
64 /* This needs to be fixed for non--IEEE-754 platforms: */
65 #if 1 /* IEEE 754 supported */
66 #if defined OSL_BIGENDIAN
67 
68 /* IEEE 754 double structures for BigEndian */
69 union sal_math_Double
70 {
71  struct
72  {
73  unsigned sign : 1;
74  unsigned exponent :11;
75  unsigned fraction_hi :20;
76  unsigned fraction_lo :32;
77  } inf_parts;
78  struct
79  {
80  unsigned sign : 1;
81  unsigned exponent :11;
82  unsigned qnan_bit : 1;
83  unsigned bits :19;
84  unsigned fraction_lo :32;
85  } nan_parts;
86  struct
87  {
88  unsigned msw :32;
89  unsigned lsw :32;
90  } w32_parts;
91  struct
92  {
93  sal_uInt64 sign : 1;
94  sal_uInt64 exponent :11;
95  sal_uInt64 fraction :52;
96  } parts;
97  sal_uInt64 intrep;
98  double value;
99 };
100 
101 #elif defined OSL_LITENDIAN
102 
103 /* IEEE 754 double structures for LittleEndian */
104 union sal_math_Double
105 {
106  struct {
107  unsigned fraction_lo :32;
108  unsigned fraction_hi :20;
109  unsigned exponent :11;
110  unsigned sign : 1;
111  } inf_parts;
112  struct {
113  unsigned fraction_lo :32;
114  unsigned bits :19;
115  unsigned qnan_bit : 1;
116  unsigned exponent :11;
117  unsigned sign : 1;
118  } nan_parts;
119  struct
120  {
121  unsigned lsw :32;
122  unsigned msw :32;
123  } w32_parts;
124  struct
125  {
126  sal_uInt64 fraction :52;
127  sal_uInt64 exponent :11;
128  sal_uInt64 sign : 1;
129  } parts;
130  sal_uInt64 intrep;
131  double value;
132 };
133 
134 #else /* OSL_BIGENDIAN, OSL_LITENDIAN */
135 
136 #error "neither OSL_BIGENDIAN nor OSL_LITENDIAN"
137 
138 #endif /* OSL_BIGENDIAN, OSL_LITENDIAN */
139 #else /* IEEE 754 supported */
140 
141 #error "don't know how to handle IEEE 754"
142 
143 #endif /* IEEE 754 supported */
144 
145 
146 #if defined __cplusplus
147 }
148 #endif /* __cplusplus */
149 
150 #endif /* INCLUDED_SAL_MATHCONF_H */
151 
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */