LibreOffice
LibreOffice 6.0 SDK C/C++ API Reference
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  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SAL_MATHCONF_H
21 #define INCLUDED_SAL_MATHCONF_H
22 
23 #include <osl/endian.h>
24 
25 #include <float.h>
26 
27 #if defined __sun
28 #include <ieeefp.h>
29 #endif /* __sun */
30 
31 #if defined(__cplusplus) && ( defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L )
32 #include <cmath>
33 #endif
34 
35 #if defined(IOS)
36 #if defined(__cplusplus)
37 #include <cmath>
38 #else
39 #include <math.h>
40 #endif
41 #endif
42 
43 #if defined __cplusplus
44 extern "C" {
45 #endif /* __cplusplus */
46 
47 
48 /* Generally, the C standard guarantees that at program startup, "trapping or
49  stopping (if supported) is disabled on all [floating-point] exceptions"
50  (F.7.3/1 of the August 3, 1998 draft of C99), and that during program
51  execution, "a programmer can safely assume default modes (or be unaware of
52  them)" (7.6/2, footnote 161 of the August 3, 1998 draft of C99). Reportedly,
53  on Windows there are printer drivers that switch on exceptions. To avoid
54  problems, the SAL_MATH_FPEXCEPTIONS_OFF macro can be used to explicitly
55  switch off exceptions (on Windows).
56  */
57 #if defined(_WIN32)
58 #define SAL_MATH_FPEXCEPTIONS_OFF() _control87( _MCW_EM, _MCW_EM )
59 #else /* WNT */
60 #define SAL_MATH_FPEXCEPTIONS_OFF()
61 #endif /* WNT */
62 
63 
64 /* SAL_MATH_FINITE(d): test double d on INFINITY, NaN et al. */
65 #if !defined __sun && !defined ANDROID \
66  && defined(__cplusplus) \
67  && ( defined(__GXX_EXPERIMENTAL_CXX0X__) \
68  || __cplusplus >= 201103L \
69  || defined(IOS) )
70 #define SAL_MATH_FINITE(d) std::isfinite(d)
71 #elif defined( IOS )
72 #define SAL_MATH_FINITE(d) isfinite(d)
73 #elif defined( WNT)
74 #define SAL_MATH_FINITE(d) _finite(d)
75 #elif defined(ANDROID) || defined LINUX || defined UNX
76 #define SAL_MATH_FINITE(d) finite(d)
77 #else /* WNT, LINUX, UNX */
78 #error "SAL_MATH_FINITE not defined"
79 #endif /* WNT, LINUX, UNX */
80 
81 
82 /* This needs to be fixed for non--IEEE-754 platforms: */
83 #if 1 /* IEEE 754 supported */
84 #if defined OSL_BIGENDIAN
85 
86 /* IEEE 754 double structures for BigEndian */
87 union sal_math_Double
88 {
89  struct
90  {
91  unsigned sign : 1;
92  unsigned exponent :11;
93  unsigned fraction_hi :20;
94  unsigned fraction_lo :32;
95  } inf_parts;
96  struct
97  {
98  unsigned sign : 1;
99  unsigned exponent :11;
100  unsigned qnan_bit : 1;
101  unsigned bits :19;
102  unsigned fraction_lo :32;
103  } nan_parts;
104  struct
105  {
106  unsigned msw :32;
107  unsigned lsw :32;
108  } w32_parts;
109  double value;
110 };
111 
112 #elif defined OSL_LITENDIAN
113 
114 /* IEEE 754 double structures for LittleEndian */
115 union sal_math_Double
116 {
117  struct {
118  unsigned fraction_lo :32;
119  unsigned fraction_hi :20;
120  unsigned exponent :11;
121  unsigned sign : 1;
122  } inf_parts;
123  struct {
124  unsigned fraction_lo :32;
125  unsigned bits :19;
126  unsigned qnan_bit : 1;
127  unsigned exponent :11;
128  unsigned sign : 1;
129  } nan_parts;
130  struct
131  {
132  unsigned lsw :32;
133  unsigned msw :32;
134  } w32_parts;
135  double value;
136 };
137 
138 #else /* OSL_BIGENDIAN, OSL_LITENDIAN */
139 
140 #error "neither OSL_BIGENDIAN nor OSL_LITENDIAN"
141 
142 #endif /* OSL_BIGENDIAN, OSL_LITENDIAN */
143 #else /* IEEE 754 supported */
144 
145 #error "don't know how to handle IEEE 754"
146 
147 #endif /* IEEE 754 supported */
148 
149 
150 #if defined __cplusplus
151 }
152 #endif /* __cplusplus */
153 
154 #endif /* INCLUDED_SAL_MATHCONF_H */
155 
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */