BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdldfp_decimalplatform.h
Go to the documentation of this file.
1/// @file bdldfp_decimalplatform.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdldfp_decimalplatform.h -*-C++-*-
8#ifndef INCLUDED_BDLDFP_DECIMALPLATFORM
9#define INCLUDED_BDLDFP_DECIMALPLATFORM
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id$")
13
14/// @defgroup bdldfp_decimalplatform bdldfp_decimalplatform
15/// @brief Provide decimal floating-point platform information macros.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdldfp
19/// @{
20/// @addtogroup bdldfp_decimalplatform
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdldfp_decimalplatform-purpose"> Purpose</a>
25/// * <a href="#bdldfp_decimalplatform-macros"> Macros </a>
26/// * <a href="#bdldfp_decimalplatform-description"> Description </a>
27/// * <a href="#bdldfp_decimalplatform-macros-defining-the-underlying-implementation"> Macros Defining the Underlying Implementation </a>
28/// * <a href="#bdldfp_decimalplatform-macros-defining-hardware-support-vs-software-emulation"> Macros Defining Hardware Support vs. Software Emulation </a>
29/// * <a href="#bdldfp_decimalplatform-endianness"> Endianness </a>
30/// * <a href="#bdldfp_decimalplatform-encoding"> Encoding </a>
31/// * <a href="#bdldfp_decimalplatform-implementation-detail-macros"> Implementation Detail Macros </a>
32/// * <a href="#bdldfp_decimalplatform-usage"> Usage </a>
33///
34/// # Purpose {#bdldfp_decimalplatform-purpose}
35/// Provide decimal floating-point platform information macros.
36///
37/// # Macros {#bdldfp_decimalplatform-macros}
38///
39/// - BDLDFP_DECIMALPLATFORM_C99_TR: using C99 (C-language) decimal fp support
40/// - BDLDFP_DECIMALPLATFORM_INTELDFP: using the `IntelDFP` library
41/// - BDLDFP_DECIMALPLATFORM_HARDWARE: using hardware support for decimals
42/// - BDLDFP_DECIMALPLATFORM_SOFTWARE: using software only (no hardware support)
43/// - BDLDFP_DECIMALPLATFORM_BIG_ENDIAN: decimals are big endian
44/// - BDLDFP_DECIMALPLATFORM_LITTLE_ENDIAN: decimals are little endian
45/// - BDLDFP_DECIMALPLATFORM_DPD: using densely packed decimal representation
46/// - BDLDFP_DECIMALPLATFORM_BININT: binary integer significand representation
47/// - BDLDFP_DECIMALPLATFORM_SNPRINTF_BUFFER_SIZE: internal use only (remove)
48/// - BDLDFP_DECIMALPLATFORM_C99_QNAN*: internal use only, will be removed
49/// - BDLDFP_DECIMALPLATFORM_C99_SNAN*: internal use only, will be removed
50///
51/// @see bdldfp_decimal, bdldfp_decimalutil, bdldfp_decimalconvertutil
52///
53/// # Description {#bdldfp_decimalplatform-description}
54/// This component provides a suite of preprocessor macros that
55/// identify and define platform-specific compile-time attributes that are
56/// related to decimal floating-point support. The macros provided by this
57/// component are defined to the be non-zero (true) when enabled on a given
58/// platform, and are undefined on platforms where they are not enabled. Some
59/// macros are implentation details, providing platform-specific information
60/// that is not useful outside of the BDE implementation.
61///
62/// ## Macros Defining the Underlying Implementation {#bdldfp_decimalplatform-macros-defining-the-underlying-implementation}
63///
64///
65/// Only one of these macros will be defined any supported platform:
66///
67/// `BDLDFP_DECIMALPLATFORM_C99_TR` - Full ISO/IEC TR 24732 support with
68/// library.
69///
70/// `BDLDFP_DECIMALPLATFORM_INTELDFP` - Using bdl+inteldfp as emulation
71///
72/// ## Macros Defining Hardware Support vs. Software Emulation {#bdldfp_decimalplatform-macros-defining-hardware-support-vs-software-emulation}
73///
74///
75/// Only one of these macros will be defined on any supported platform:
76///
77/// `BDLDFP_DECIMALPLATFORM_HARDWARE` - Hardware support for at least one type.
78///
79/// `BDLDFP_DECIMALPLATFORM_SOFTWARE` - Software emulation for all types
80///
81/// ## Endianness {#bdldfp_decimalplatform-endianness}
82///
83///
84/// There is a chance that the endianness of integers and decimal floating
85/// point are not the same as those of integers; therefore we provide two
86/// macros here to support implementation of endianness conversions.
87///
88/// `BDLDFP_DECIMALPLATFORM_BIG_ENDIAN` - big endian storage
89///
90/// `BDLDFP_DECIMALPLATFORM_LITTLE_ENDIAN` - little endian storage
91///
92/// ## Encoding {#bdldfp_decimalplatform-encoding}
93///
94///
95/// There are two IEEE-754 sanctioned encodings for the significand: densely
96/// packed decimal and binary integer significand. We provide two macros here
97/// to support implementation of encoding conversions.
98///
99/// `BDLDFP_DECIMALPLATFORM_DPD` - Densely Packed Decimal significand
100/// representation
101///
102/// `BDLDFP_DECIMALPLATFORM_BININT` - Binary Integer significand representation
103///
104/// ## Implementation Detail Macros {#bdldfp_decimalplatform-implementation-detail-macros}
105///
106///
107/// These macros may or may not be present, depending on the platform. They are
108/// not meant for use outside of the Decimal Floating Point implementation;
109/// Therefore using them in your code will result in undefined behavior.
110///
111/// `BDLDFP_DECIMALPLATFORM_SNPRINTF_BUFFER_SIZE` - max chars to print Dec128
112///
113/// `BDLDFP_DECIMALPLATFORM_C99_QNAN32` - The expression to get a quiet NaN of
114/// `BDLDFP_DECIMALPLATFORM_C99_QNAN64` the type the number postfix refers to.
115/// `BDLDFP_DECIMALPLATFORM_C99_QNAN128`
116///
117/// `BDLDFP_DECIMALPLATFORM_C99_SNAN32` - The expression to get a signaling NaN
118/// `BDLDFP_DECIMALPLATFORM_C99_SNAN64` of the type the number postfix refers
119/// `BDLDFP_DECIMALPLATFORM_C99_SNAN128` to.
120///
121/// ## Usage {#bdldfp_decimalplatform-usage}
122///
123///
124/// In this section, we show the intended usage of this component.
125/// @code
126/// @endcode
127/// @}
128/** @} */
129/** @} */
130
131/** @addtogroup bdl
132 * @{
133 */
134/** @addtogroup bdldfp
135 * @{
136 */
137/** @addtogroup bdldfp_decimalplatform
138 * @{
139 */
140
141#include <bdlscm_version.h>
142
143#include <bsls_platform.h>
144
145#include <bslmf_assert.h>
146
147// C99 decimal support on xlC/Aix issues should be resolved (see
148// DRQS 39471014).
149
150
151// We have decided to disable IBM hardware floating point, at this time.
152
153#if 0 && defined(BSLS_PLATFORM_CMP_IBM) && defined(__IBM_DFP__) && __IBM_DFP__
154
155
156# define BDLDFP_DECIMALPLATFORM_C99_QNAN32 __d32_qNaN()
157# define BDLDFP_DECIMALPLATFORM_C99_QNAN64 __d64_qNaN()
158# define BDLDFP_DECIMALPLATFORM_C99_QNAN128 __d128_qNaN()
159# define BDLDFP_DECIMALPLATFORM_C99_SNAN32 __d32_sNaN()
160# define BDLDFP_DECIMALPLATFORM_C99_SNAN64 __d64_sNaN()
161# define BDLDFP_DECIMALPLATFORM_C99_SNAN128 __d128_sNaN()
162
163# define BDLDFP_DECIMALPLATFORM_C99_NO_FMAD64 1
164
165# if defined(__IBM_DFP_SW_EMULATION__) && __IBM_DFP_SW_EMULATION__
166# define BDLDFP_DECIMALPLATFORM_SOFTWARE 1
167# else
168# define BDLDFP_DECIMALPLATFORM_HARDWARE 1
169# endif
170# define BDLDFP_DECIMALPLATFORM_C99_TR 1
171#else
172# define BDLDFP_DECIMALPLATFORM_SOFTWARE 1
173#endif
174
175// TODO: a rough hack -- fix this.
176
177# define BDLDFP_DECIMALPLATFORM_SNPRINTF_BUFFER_SIZE 256
178
179#ifndef BDLDFP_DECIMALPLATFORM_C99_TR
180# if 1
181# define BDLDFP_DECIMALPLATFORM_INTELDFP 1
182# endif
183#endif
184
185#ifdef BDLDFP_DECIMALPLATFORM_C99_TR
186# define BDLDFP_DECIMALPLATFORM_DPD 1
187#elif defined(BDLDFP_DECIMALPLATFORM_INTELDFP)
188# define BDLDFP_DECIMALPLATFORM_BININT 1
189#else
190# error Unsupported decimal floating point platform.
191BSLMF_ASSERT(false);
192#endif
193
194// The Decimal Platform macros for endian settings allow for the possibility of
195// future implementations which have divergent integer and decimal floating
196// point byte orders.
197
198#ifdef BSLS_PLATFORM_IS_BIG_ENDIAN
199# define BDLDFP_DECIMALPLATFORM_BIG_ENDIAN 1
200#elif defined(BSLS_PLATFORM_IS_LITTLE_ENDIAN)
201# define BDLDFP_DECIMALPLATFORM_LITTLE_ENDIAN 1
202#else
203# error "Unsupported endianness"
205#endif
206
207#define BDLDFP_DECIMALPLATFORM_COMPILER_ERROR BSLMF_ASSERT(false)
208
209 // Validation
210
211// The following checks are performed to guarantee the reasonable
212// initialization of the compile time features defined in this component.
213
214
215// Verify exactly one Implementation class (Hardware or software)
216
217#if BDLDFP_DECIMALPLATFORM_HARDWARE \
218 + BDLDFP_DECIMALPLATFORM_SOFTWARE != 1
219 #error "Exactly one decimal platform implementation class must be set."
221#endif
222
223// Verify exactly one endian selection must be made
224
225#if BDLDFP_DECIMALPLATFORM_BIG_ENDIAN \
226 + BDLDFP_DECIMALPLATFORM_LITTLE_ENDIAN != 1
227 #error "Exactly one decimal platform endian selection must be set."
229#endif
230
231// Verify exactly one format selection must be made
232
233#if BDLDFP_DECIMALPLATFORM_DPD \
234 + BDLDFP_DECIMALPLATFORM_BININT != 1
235 #error "Exactly one decimal platform format selection must be set."
237#endif
238
239// Verify exactly one implementation library must be selected
240
241#if BDLDFP_DECIMALPLATFORM_INTELDFP \
242 + BDLDFP_DECIMALPLATFORM_C99_TR != 1
243 #error "Exactly one decimal implementation library must be selected."
245#endif
246
247// Under Intel implementation, SOFTWARE and BININT must be set
248#if defined(BDLDFP_DECIMALPLATFORM_INTELDFP) && \
249 !defined(BDLDFP_DECIMALPLATFORM_SOFTWARE) && \
250 !defined(BDLDFP_DECIMALPLATFORM_BININT)
251 #error "INTELDFP mode requires SOFTWARE and BININT modes to be set."
253#endif
254
255#endif
256
257// ----------------------------------------------------------------------------
258// Copyright 2014 Bloomberg Finance L.P.
259//
260// Licensed under the Apache License, Version 2.0 (the "License");
261// you may not use this file except in compliance with the License.
262// You may obtain a copy of the License at
263//
264// http://www.apache.org/licenses/LICENSE-2.0
265//
266// Unless required by applicable law or agreed to in writing, software
267// distributed under the License is distributed on an "AS IS" BASIS,
268// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
269// See the License for the specific language governing permissions and
270// limitations under the License.
271// ----------------------------- END-OF-FILE ----------------------------------
272
273/** @} */
274/** @} */
275/** @} */
#define BDLDFP_DECIMALPLATFORM_COMPILER_ERROR
Definition bdldfp_decimalplatform.h:207
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_IDENT(str)
Definition bsls_ident.h:195