LibreOffice: sal/mathconf.h Source File

LibreOffice LibreOffice 24.8 SDK C/C++ API Reference |

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