LibreOffice: sal/mathconf.h Source File

LibreOffice LibreOffice 7.1 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#if defined __sun
26#include <ieeefp.h>
27#endif /* __sun */
28
29#if defined(__cplusplus) && ( defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L )
30#include <cmath>
31#endif
32
33#if defined(IOS)
34#if defined(__cplusplus)
35#include <cmath>
36#else
37#include <math.h>
38#endif
39#endif
40
41#if defined __cplusplus
42extern "C" {
43#endif /* __cplusplus */
44
45
46/* Generally, the C standard guarantees that at program startup, "trapping or
47 stopping (if supported) is disabled on all [floating-point] exceptions"
48 (F.7.3/1 of the August 3, 1998 draft of C99), and that during program
49 execution, "a programmer can safely assume default modes (or be unaware of
50 them)" (7.6/2, footnote 161 of the August 3, 1998 draft of C99). Reportedly,
51 on Windows there are printer drivers that switch on exceptions. To avoid
52 problems, the SAL_MATH_FPEXCEPTIONS_OFF macro can be used to explicitly
53 switch off exceptions (on Windows).
54 */
55#if defined(_WIN32)
56#define SAL_MATH_FPEXCEPTIONS_OFF() _control87( _MCW_EM, _MCW_EM )
57#else /* WNT */
58#define SAL_MATH_FPEXCEPTIONS_OFF()
59#endif /* WNT */
60
61
62/* SAL_MATH_FINITE(d): test double d on INFINITY, NaN et al. */
63#if !defined __sun && !defined ANDROID \
64 && defined(__cplusplus) \
65 && ( defined(__GXX_EXPERIMENTAL_CXX0X__) \
66 || __cplusplus >= 201103L \
67 || defined(IOS) )
68#define SAL_MATH_FINITE(d) std::isfinite(d)
69#elif defined( IOS )
70#define SAL_MATH_FINITE(d) isfinite(d)
71#elif defined( WNT)
72#define SAL_MATH_FINITE(d) _finite(d)
73#elif defined(ANDROID) || defined LINUX || defined UNX
74#define SAL_MATH_FINITE(d) finite(d)
75#else /* WNT, LINUX, UNX */
76#error "SAL_MATH_FINITE not defined"
77#endif /* WNT, LINUX, UNX */
78
79
80/* This needs to be fixed for non--IEEE-754 platforms: */
81#if 1 /* IEEE 754 supported */
82#if defined OSL_BIGENDIAN
83
84/* IEEE 754 double structures for BigEndian */
85union sal_math_Double
86{
87 struct
88 {
89 unsigned sign : 1;
90 unsigned exponent :11;
91 unsigned fraction_hi :20;
92 unsigned fraction_lo :32;
93 } inf_parts;
94 struct
95 {
96 unsigned sign : 1;
97 unsigned exponent :11;
98 unsigned qnan_bit : 1;
99 unsigned bits :19;
100 unsigned fraction_lo :32;
101 } nan_parts;
102 struct
103 {
104 unsigned msw :32;
105 unsigned lsw :32;
106 } w32_parts;
107 struct
108 {
109 sal_uInt64 sign : 1;
110 sal_uInt64 exponent :11;
111 sal_uInt64 fraction :52;
112 } parts;
113 sal_uInt64 intrep;
114 double value;
115};
116
117#elif defined OSL_LITENDIAN
118
119/* IEEE 754 double structures for LittleEndian */
120union sal_math_Double
121{
122 struct {
123 unsigned fraction_lo :32;
124 unsigned fraction_hi :20;
125 unsigned exponent :11;
126 unsigned sign : 1;
127 } inf_parts;
128 struct {
129 unsigned fraction_lo :32;
130 unsigned bits :19;
131 unsigned qnan_bit : 1;
132 unsigned exponent :11;
133 unsigned sign : 1;
134 } nan_parts;
135 struct
136 {
137 unsigned lsw :32;
138 unsigned msw :32;
139 } w32_parts;
140 struct
141 {
142 sal_uInt64 fraction :52;
143 sal_uInt64 exponent :11;
144 sal_uInt64 sign : 1;
145 } parts;
146 sal_uInt64 intrep;
147 double value;
148};
149
150#else /* OSL_BIGENDIAN, OSL_LITENDIAN */
151
152#error "neither OSL_BIGENDIAN nor OSL_LITENDIAN"
153
154#endif /* OSL_BIGENDIAN, OSL_LITENDIAN */
155#else /* IEEE 754 supported */
156
157#error "don't know how to handle IEEE 754"
158
159#endif /* IEEE 754 supported */
160
161
162#if defined __cplusplus
163}
164#endif /* __cplusplus */
165
166#endif /* INCLUDED_SAL_MATHCONF_H */
167
168/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
math.h
endian.h