UDK 3.2.7 C/C++ API Reference
|
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /************************************************************************* 00003 * 00004 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 00005 * 00006 * Copyright 2000, 2010 Oracle and/or its affiliates. 00007 * 00008 * OpenOffice.org - a multi-platform office productivity suite 00009 * 00010 * This file is part of OpenOffice.org. 00011 * 00012 * OpenOffice.org is free software: you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 3 00014 * only, as published by the Free Software Foundation. 00015 * 00016 * OpenOffice.org is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License version 3 for more details 00020 * (a copy is included in the LICENSE file that accompanied this code). 00021 * 00022 * You should have received a copy of the GNU Lesser General Public License 00023 * version 3 along with OpenOffice.org. If not, see 00024 * <http://www.openoffice.org/license.html> 00025 * for a copy of the LGPLv3 License. 00026 * 00027 ************************************************************************/ 00028 00029 #if !defined INCLUDED_SAL_MATHCONF_H 00030 #define INCLUDED_SAL_MATHCONF_H 00031 00032 #include "osl/endian.h" 00033 00034 #include <float.h> 00035 00036 #if defined SOLARIS 00037 #include <ieeefp.h> 00038 #endif /* SOLARIS */ 00039 00040 #if defined(__cplusplus) && ( defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L ) 00041 #include <cmath> 00042 #endif 00043 00044 #if defined __cplusplus 00045 extern "C" { 00046 #endif /* __cplusplus */ 00047 00048 00049 /* Generally, the C standard guarantees that at program startup, "trapping or 00050 stopping (if supported) is disabled on all [floating-point] exceptions" 00051 (F.7.3/1 of the August 3, 1998 draft of C99), and that during program 00052 execution, "a programmer can safely assume default modes (or be unaware of 00053 them)" (7.6/2, footnote 161 of the August 3, 1998 draft of C99). Reportedly, 00054 on Windows there are printer drivers that switch on exceptions. To avoid 00055 problems, the SAL_MATH_FPEXCEPTIONS_OFF macro can be used to explicitly 00056 switch off exceptions (on Windows). 00057 */ 00058 #if defined WNT 00059 #define SAL_MATH_FPEXCEPTIONS_OFF() _control87( _MCW_EM, _MCW_EM ) 00060 #else /* WNT */ 00061 #define SAL_MATH_FPEXCEPTIONS_OFF() 00062 #endif /* WNT */ 00063 00064 00065 /* SAL_MATH_FINITE(d): test double d on INFINITY, NaN et al. */ 00066 #if defined(__cplusplus) && ( defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L ) 00067 #define SAL_MATH_FINITE(d) std::isfinite(d) 00068 #elif defined( WNT) 00069 #define SAL_MATH_FINITE(d) _finite(d) 00070 #elif defined IOS 00071 /* C++ is so nice. This is the only way I could come up with making 00072 * this actually work in all cases (?), even when <cmath> has been 00073 * included which #undefs isfinite: copy the definition of isfinite() 00074 * from <architecture/arm/math.h> 00075 */ 00076 #define SAL_MATH_FINITE(d) \ 00077 ( sizeof (d) == sizeof(float ) ? __inline_isfinitef((float)(d)) \ 00078 : sizeof (d) == sizeof(double) ? __inline_isfinited((double)(d)) \ 00079 : __inline_isfinite ((long double)(d))) 00080 #elif defined LINUX || defined UNX 00081 #define SAL_MATH_FINITE(d) finite(d) 00082 #else /* WNT, LINUX, UNX */ 00083 #error "SAL_MATH_FINITE not defined" 00084 #endif /* WNT, LINUX, UNX */ 00085 00086 00087 /* This needs to be fixed for non--IEEE-754 platforms: */ 00088 #if 1 /* IEEE 754 supported */ 00089 #if defined OSL_BIGENDIAN 00090 00091 /* IEEE 754 double structures for BigEndian */ 00092 union sal_math_Double 00093 { 00094 struct 00095 { 00096 unsigned sign : 1; 00097 unsigned exponent :11; 00098 unsigned fraction_hi :20; 00099 unsigned fraction_lo :32; 00100 } inf_parts; 00101 struct 00102 { 00103 unsigned sign : 1; 00104 unsigned exponent :11; 00105 unsigned qnan_bit : 1; 00106 unsigned bits :19; 00107 unsigned fraction_lo :32; 00108 } nan_parts; 00109 struct 00110 { 00111 unsigned msw :32; 00112 unsigned lsw :32; 00113 } w32_parts; 00114 double value; 00115 }; 00116 00117 #elif defined OSL_LITENDIAN 00118 00119 /* IEEE 754 double structures for LittleEndian */ 00120 union sal_math_Double 00121 { 00122 struct { 00123 unsigned fraction_lo :32; 00124 unsigned fraction_hi :20; 00125 unsigned exponent :11; 00126 unsigned sign : 1; 00127 } inf_parts; 00128 struct { 00129 unsigned fraction_lo :32; 00130 unsigned bits :19; 00131 unsigned qnan_bit : 1; 00132 unsigned exponent :11; 00133 unsigned sign : 1; 00134 } nan_parts; 00135 struct 00136 { 00137 unsigned lsw :32; 00138 unsigned msw :32; 00139 } w32_parts; 00140 double value; 00141 }; 00142 00143 #else /* OSL_BIGENDIAN, OSL_LITENDIAN */ 00144 00145 #error "neither OSL_BIGENDIAN nor OSL_LITENDIAN" 00146 00147 #endif /* OSL_BIGENDIAN, OSL_LITENDIAN */ 00148 #else /* IEEE 754 supported */ 00149 00150 #error "don't know how to handle IEEE 754" 00151 00152 #endif /* IEEE 754 supported */ 00153 00154 00155 #if defined __cplusplus 00156 } 00157 #endif /* __cplusplus */ 00158 00159 #endif /* INCLUDED_SAL_MATHCONF_H */ 00160 00161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */