UDK 3.2.7 C/C++ API Reference

sal/mathconf.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*
00003  * This file is part of the LibreOffice project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * This file incorporates work covered by the following license notice:
00010  *
00011  *   Licensed to the Apache Software Foundation (ASF) under one or more
00012  *   contributor license agreements. See the NOTICE file distributed
00013  *   with this work for additional information regarding copyright
00014  *   ownership. The ASF licenses this file to you under the Apache
00015  *   License, Version 2.0 (the "License"); you may not use this file
00016  *   except in compliance with the License. You may obtain a copy of
00017  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
00018  */
00019 
00020 #ifndef INCLUDED_SAL_MATHCONF_H
00021 #define INCLUDED_SAL_MATHCONF_H
00022 
00023 #include "osl/endian.h"
00024 
00025 #include <float.h>
00026 
00027 #if defined SOLARIS
00028 #include <ieeefp.h>
00029 #endif /* SOLARIS */
00030 
00031 #if defined(__cplusplus) && ( defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L )
00032 #include <cmath>
00033 #endif
00034 
00035 #if defined(IOS)
00036 #if defined(__cplusplus)
00037 #include <cmath>
00038 #else
00039 #include <math.h>
00040 #endif
00041 #endif
00042 
00043 #if defined __cplusplus
00044 extern "C" {
00045 #endif /* __cplusplus */
00046 
00047 
00048 /* Generally, the C standard guarantees that at program startup, "trapping or
00049    stopping (if supported) is disabled on all [floating-point] exceptions"
00050    (F.7.3/1 of the August 3, 1998 draft of C99), and that during program
00051    execution, "a programmer can safely assume default modes (or be unaware of
00052    them)" (7.6/2, footnote 161 of the August 3, 1998 draft of C99).  Reportedly,
00053    on Windows there are printer drivers that switch on exceptions.  To avoid
00054    problems, the SAL_MATH_FPEXCEPTIONS_OFF macro can be used to explicitly
00055    switch off exceptions (on Windows).
00056  */
00057 #if defined WNT
00058 #define SAL_MATH_FPEXCEPTIONS_OFF() _control87( _MCW_EM, _MCW_EM )
00059 #else /* WNT */
00060 #define SAL_MATH_FPEXCEPTIONS_OFF()
00061 #endif /* WNT */
00062 
00063 
00064 /* SAL_MATH_FINITE(d): test double d on INFINITY, NaN et al. */
00065 #if !defined SOLARIS && !defined ANDROID \
00066                      && defined(__cplusplus) \
00067                      && ( defined(__GXX_EXPERIMENTAL_CXX0X__) \
00068                           || __cplusplus >= 201103L \
00069                           || defined(IOS) )
00070 #define SAL_MATH_FINITE(d) std::isfinite(d)
00071 #elif defined( IOS )
00072 #define SAL_MATH_FINITE(d) isfinite(d)
00073 #elif defined( WNT)
00074 #define SAL_MATH_FINITE(d) _finite(d)
00075 #elif defined LINUX || defined UNX
00076 #define SAL_MATH_FINITE(d) finite(d)
00077 #else /* WNT, LINUX, UNX */
00078 #error "SAL_MATH_FINITE not defined"
00079 #endif /* WNT, LINUX, UNX */
00080 
00081 
00082 /* This needs to be fixed for non--IEEE-754 platforms: */
00083 #if 1 /* IEEE 754 supported */
00084 #if defined OSL_BIGENDIAN
00085 
00086 /* IEEE 754 double structures for BigEndian */
00087 union sal_math_Double
00088 {
00089     struct
00090     {
00091         unsigned sign         : 1;
00092         unsigned exponent     :11;
00093         unsigned fraction_hi  :20;
00094         unsigned fraction_lo  :32;
00095     } inf_parts;
00096     struct
00097     {
00098         unsigned sign         : 1;
00099         unsigned exponent     :11;
00100         unsigned qnan_bit     : 1;
00101         unsigned bits         :19;
00102         unsigned fraction_lo  :32;
00103     } nan_parts;
00104     struct
00105     {
00106         unsigned msw          :32;
00107         unsigned lsw          :32;
00108     } w32_parts;
00109     double value;
00110 };
00111 
00112 #elif defined OSL_LITENDIAN
00113 
00114 /* IEEE 754 double structures for LittleEndian */
00115 union sal_math_Double
00116 {
00117     struct {
00118         unsigned fraction_lo  :32;
00119         unsigned fraction_hi  :20;
00120         unsigned exponent     :11;
00121         unsigned sign         : 1;
00122     } inf_parts;
00123     struct {
00124         unsigned fraction_lo  :32;
00125         unsigned bits         :19;
00126         unsigned qnan_bit     : 1;
00127         unsigned exponent     :11;
00128         unsigned sign         : 1;
00129     } nan_parts;
00130     struct
00131     {
00132         unsigned lsw          :32;
00133         unsigned msw          :32;
00134     } w32_parts;
00135     double value;
00136 };
00137 
00138 #else /* OSL_BIGENDIAN, OSL_LITENDIAN */
00139 
00140 #error "neither OSL_BIGENDIAN nor OSL_LITENDIAN"
00141 
00142 #endif /* OSL_BIGENDIAN, OSL_LITENDIAN */
00143 #else /* IEEE 754 supported */
00144 
00145 #error "don't know how to handle IEEE 754"
00146 
00147 #endif /* IEEE 754 supported */
00148 
00149 
00150 #if defined __cplusplus
00151 }
00152 #endif /* __cplusplus */
00153 
00154 #endif /* INCLUDED_SAL_MATHCONF_H */
00155 
00156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines