BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdldfp_decimalutil.h
Go to the documentation of this file.
1/// @file bdldfp_decimalutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdldfp_decimalutil.h -*-C++-*-
8#ifndef INCLUDED_BDLDFP_DECIMALUTIL
9#define INCLUDED_BDLDFP_DECIMALUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id$")
13
14/// @defgroup bdldfp_decimalutil bdldfp_decimalutil
15/// @brief Provide utilities dealing with floating point decimal objects.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdldfp
19/// @{
20/// @addtogroup bdldfp_decimalutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdldfp_decimalutil-purpose"> Purpose</a>
25/// * <a href="#bdldfp_decimalutil-classes"> Classes </a>
26/// * <a href="#bdldfp_decimalutil-macros"> Macros </a>
27/// * <a href="#bdldfp_decimalutil-description"> Description </a>
28/// * <a href="#bdldfp_decimalutil-usage"> Usage </a>
29/// * <a href="#bdldfp_decimalutil-example-1-building-decimals-from-integer-parts"> Example 1: Building Decimals From Integer Parts </a>
30///
31/// # Purpose {#bdldfp_decimalutil-purpose}
32/// Provide utilities dealing with floating point decimal objects.
33///
34/// # Classes {#bdldfp_decimalutil-classes}
35///
36/// - bdldfp::DecimalUtil: decimal floating point utility functions.
37///
38/// # Macros {#bdldfp_decimalutil-macros}
39///
40/// - FP_SUBNORMAL: subnormal floating-point classification identifier constant
41/// - FP_NORMAL: normal floating-point classification identifier constant
42/// - FP_ZERO: zero floating-point classification identifier constant
43/// - FP_INFINITE: infinity floating-point classification identifier constant
44/// - FP_NAN: NaN floating-point classification identifier constant
45///
46/// Note that these macros may *not* be defined in this header. They are C99
47/// standard macros and this component defines them only for those platforms
48/// that have failed to implement C99 (such as Microsoft).
49///
50/// @see bdldfp_decimal, bdldfp_decimalplatform
51///
52/// # Description {#bdldfp_decimalutil-description}
53/// The `bdldfp::DecimalUtil` component provides utility functions
54/// for the decimal floating-point types defined in @ref bdldfp_decimal :
55///
56/// * `FP_XXX`, C99 standard floating-point classification macros
57/// * the `makeDecimal` functions building a decimal floating-point value out
58/// of a coefficient and exponent.
59/// * the `parseDecimal` functions that convert text to decimal value.
60/// * `fma`, `fabs`, `ceil`, `floor`, `trunc`, `round` - math functions
61/// * `classify` and the `isXxxx` floating-point value classification functions
62///
63/// The `FP_XXX` C99 floating-point classification macros may also be provided
64/// by this header for platforms where C99 support is still not provided.
65///
66/// ## Usage {#bdldfp_decimalutil-usage}
67///
68///
69/// This section shows the intended use of this component.
70///
71/// ### Example 1: Building Decimals From Integer Parts {#bdldfp_decimalutil-example-1-building-decimals-from-integer-parts}
72///
73///
74/// Floating-point numbers are built from a sign, a significand and an exponent.
75/// All those 3 are integers (of various sizes), therefore it is possible to
76/// build decimals from integers:
77/// @code
78/// long long coefficient = 42; // Yet another name for significand
79/// int exponent = -1;
80///
81/// Decimal32 d32 = makeDecimal32( coefficient, exponent);
82/// Decimal64 d64 = makeDecimal64( coefficient, exponent);
83/// Decimal128 d128 = makeDecimal128(coefficient, exponent);
84///
85/// assert(BDLDFP_DECIMAL_DF(4.2) == d32);
86/// assert(BDLDFP_DECIMAL_DD(4.2) == d64);
87/// assert(BDLDFP_DECIMAL_DL(4.2) == d128);
88/// @endcode
89/// @}
90/** @} */
91/** @} */
92
93/** @addtogroup bdl
94 * @{
95 */
96/** @addtogroup bdldfp
97 * @{
98 */
99/** @addtogroup bdldfp_decimalutil
100 * @{
101 */
102
103// TODO TBD Priority description:
104//
105// 1 - these are already implemented so you should not see TBD/TODO for them
106// E - implement when the thread-local Environment/Context is implemented
107// 2 - implement as second priority (most probably after the 'E')
108// N - Do not implement unless explicitly requested
109
110#include <bdlscm_version.h>
111
112#include <bdldfp_decimal.h>
116#include <bdldfp_uint128.h>
117
118#include <bsls_assert.h>
119#include <bsls_libraryfeatures.h>
120#include <bsls_platform.h>
121#include <bsls_types.h>
122
123#include <bsl_optional.h>
124#include <bsl_string.h>
125
126#include <string> // 'std::string', 'std::pmr::string'
127
128
129namespace bdldfp {
130 // =================
131 // class DecimalUtil
132 // =================
133
134/// This utility `struct` provides a namespace for functions using the
135/// decimal floating point types defined in the @ref bdldfp_decimal package.
137
138 // CLASS METHODS
139
140 // Creators functions
141
142 /// Create a `Decimal32` object representing a decimal floating point
143 /// number consisting of the specified `significand` and `exponent`,
144 /// with the sign given by the `significand` (if signed). The behavior
145 /// is undefined unless `-9,999,999 <= significand <= 9,999,999` and
146 /// `-101 <= exponent <= 90`.
147 static Decimal32 makeDecimalRaw32 (int significand, int exponent);
148
149 static Decimal64 makeDecimalRaw64(int significand,
150 int exponent);
151 static Decimal64 makeDecimalRaw64(unsigned int significand,
152 int exponent);
153 static Decimal64 makeDecimalRaw64(long long significand,
154 int exponent);
155 /// Create a `Decimal64` object representing a decimal floating point
156 /// number consisting of the specified `significand` and `exponent`,
157 /// with the sign given by the `significand` (if signed). The behavior
158 /// is undefined unless
159 /// `-9,999,999,999,999,999 <= significand <= 9,999,999,999,999,999` and
160 /// `-398 <= exponent <= 369`.
161 static Decimal64 makeDecimalRaw64(unsigned long long significand,
162 int exponent);
163
164 static Decimal128 makeDecimalRaw128(int significand,
165 int exponent);
166 static Decimal128 makeDecimalRaw128(unsigned int significand,
167 int exponent);
168 static Decimal128 makeDecimalRaw128(long long significand,
169 int exponent);
170 /// Create a `Deciaml128` object representing a decimal floating point
171 /// number consisting of the specified `significand` and specified
172 /// `exponent`, with the sign given by the `significand` (if signed).
173 /// The behavior is undefined unless `-6176 <= exponent <= 6111`.
174 static Decimal128 makeDecimalRaw128(unsigned long long significand,
175 int exponent);
176
177 static Decimal64 makeDecimal64(int significand,
178 int exponent);
179 static Decimal64 makeDecimal64(unsigned int significand,
180 int exponent);
181 static Decimal64 makeDecimal64(long long significand,
182 int exponent);
183 static Decimal64 makeDecimal64(unsigned long long significand,
184 int exponent);
185
186 static int parseDecimal32(Decimal32 *out, const char *str);
187 static int parseDecimal64(Decimal64 *out, const char *str);
188 /// Return a `DecimalNN` object that has the specified `significand` and
189 /// `exponent`, rounded according to the current decimal rounding mode,
190 /// if necessary. If an overflow condition occurs, store the value of
191 /// the macro `ERANGE` into `errno` and return infinity with the
192 /// appropriate sign.
193 static int parseDecimal128(Decimal128 *out, const char *str);
194 template <class STRING_TYPE>
195 static int parseDecimal32(Decimal32 *out, const STRING_TYPE& str);
196 template <class STRING_TYPE>
197 static int parseDecimal64(Decimal64 *out, const STRING_TYPE& str);
198
199 /// Load into the specified `out` the decimal floating point number
200 /// described by the specified `str`; return zero if the conversion was
201 /// successful and non-zero otherwise. The value of `out` is
202 /// unspecified if the function returns a non-zero value. The
203 /// parameterized `STRING_TYPE` must be one of `bsl::string`,
204 /// `std::string`, `std::pmr::string` (if supported), or
205 /// `bslstl::StringRef`.
206 template <class STRING_TYPE>
207 static int parseDecimal128(Decimal128 *out, const STRING_TYPE& str);
208
209 static int parseDecimal32Exact(Decimal32 *out, const char *str);
210 static int parseDecimal64Exact(Decimal64 *out, const char *str);
211 static int parseDecimal128Exact(Decimal128 *out, const char *str);
212 template <class STRING_TYPE>
213 static int parseDecimal32Exact(Decimal32 *out, const STRING_TYPE& str);
214 template <class STRING_TYPE>
215 static int parseDecimal64Exact(Decimal64 *out, const STRING_TYPE& str);
216
217 /// Load into the specified `out` the decimal floating point number
218 /// described by the specified `str`. Return 0 if `out` is an exact
219 /// representation of `str`, a positive value if `str` is an
220 /// approximation of `str` (i.e., `str` could not be represented
221 /// exactly), and a negative value if `str` could not be parsed. The
222 /// value of `out` is unspecified if the function returns a negative
223 /// value. The parameterized `STRING_TYPE` must be one of
224 /// `bsl::string`, `std::string`, `std::pmr::string` (if supported), or
225 /// `bslstl::StringRef`.
226 template <class STRING_TYPE>
227 static int parseDecimal128Exact(Decimal128 *out, const STRING_TYPE& str);
228
229 // math
230
231 /// Return a decimal value with the magnitude of the specifed `x` and
232 /// the sign of the specified `y`. If `x` is NaN, then NaN with the
233 /// sign of `y` is returned.
234 ///
237 /// Examples: `copySign( 5.0, -2.0)` ==> -5.0;
238 /// `copySign(-5.0, -2.0)` ==> 5.0
240
241 /// Return `e` (Euler's number, 2.7182818) raised to the specified power
242 /// `x`.
243 ///
244 static Decimal32 exp(Decimal32 x);
245 static Decimal64 exp(Decimal64 x);
246 /// Special value handling:
247 /// * If `x` is +/-0, 1 is returned.
248 /// * If `x` is negative infinity, +0 is returned.
249 /// * If `x` is +infinity, +infinity is returned.
250 /// * If `x` is quiet NaN, quiet NaN is returned.
251 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
252 /// the macro `EDOM` is stored into `errno`.
253 /// * If `x` is finite, but the result value is outside the range of
254 /// the return type, store the value of the macro `ERANGE` into
255 /// `errno` and +infinity value is returned.
256 static Decimal128 exp(Decimal128 x);
257
258 /// Return the natural (base `e`) logarithm of the specified `x`.
259 ///
260 static Decimal32 log(Decimal32 x);
261 static Decimal64 log(Decimal64 x);
262 /// Special value handling:
263 /// * If `x` is +/-0, -infinity is returned and the value of the macro
264 /// `ERANGE` is stored into `errno`.
265 /// * If `x` is 1, +0 is returned.
266 /// * If `x` is negative, quiet NaN is returned and the value of the
267 /// macro `EDOM` is stored into `errno`.
268 /// * If `x` is +infinity, +infinity is returned.
269 /// * If `x` is quiet NaN, quiet NaN is returned.
270 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
271 /// the macro `EDOM` is stored into `errno`.
272 static Decimal128 log(Decimal128 x);
273
274 /// Return the FLT_RADIX-based logarithm (i.e., base 10) of the absolute
275 /// value of the specified `x`.
276 ///
277 /// Special value handling:
278 /// * If `x` is +/-0, -infinity is returned and the value of the macro
279 /// `ERANGE` is stored into `errno`.
280 /// * If `x` is 1, +0 is returned.
281 /// * If `x` is +/-infinity, +infinity is returned.
282 /// * If `x` is quiet NaN, quiet NaN is returned.
283 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
284 /// the macro `EDOM` is stored into `errno`.
285 ///
286 static Decimal32 logB(Decimal32 x);
287 static Decimal64 logB(Decimal64 x);
288 /// Examples: `logB( 10.0)` ==> 1.0;
289 /// `logB(-100.0)` ==> 2.0
290 static Decimal128 logB(Decimal128 x);
291
292 /// Return the common (base-10) logarithm of the specified `x`.
293 ///
294 static Decimal32 log10(Decimal32 x);
295 static Decimal64 log10(Decimal64 x);
296 /// Special value handling:
297 /// * If `x` is +/-0, -infinity is returned and the value of the macro
298 /// `ERANGE` is stored into `errno`.
299 /// * If `x` is 1, +0 is returned.
300 /// * If `x` is negative, quiet NaN is returned and the value of the
301 /// macro `EDOM` is stored into `errno`.
302 /// * If `x` is +infinity, +infinity is returned.
303 /// * If `x` is quiet NaN, quiet NaN is returned.
304 /// * If `x` is signaling NaN, NaN is returned and the value of the
305 /// macro `EDOM` is stored into `errno`.
306 static Decimal128 log10(Decimal128 x);
307
308 /// Return the remainder of the division of the specified `x` by the
309 /// specified `y`. The returned value has the same sign as `x` and is
310 /// less than `y` in magnitude.
311 ///
312 static Decimal32 fmod(Decimal32 x, Decimal32 y);
313 static Decimal64 fmod(Decimal64 x, Decimal64 y);
314 /// Special value handling:
315 /// * If either argument is quiet NaN, quiet NaN is returned.
316 /// * If either argument is signaling NaN, quiet NaN is returned, and
317 /// the value of the macro `EDOM` is stored into `errno`.
318 /// * If `x` is +/-infnity and `y` is not NaN, quiet NaN is returned
319 /// and the value of the macro `EDOM` is stored into `errno`.
320 /// * If `x` is +/-0 and `y` is not zero, +/-0 is returned.
321 /// * If `y` is +/-0, quite NaN is returned and the value of the macro
322 /// `EDOM` is stored into `errno`.
323 /// * If `x` is finite and `y` is +/-infnity, `x` is returned.
325
326 /// Return the remainder of the division of the specified `x` by the
327 /// specified `y`. The remainder of the division operation `x/y`
328 /// calculated by this function is exactly the value `x - n*y`, where
329 /// `n` s the integral value nearest the exact value `x/y`. When
330 /// `|n - x/y| == 0.5`, the value `n` is chosen to be even. Note that
331 /// in contrast to `DecimalImpUtil::fmod()`, the returned value is not
332 /// guaranteed to have the same sign as `x`.
333 ///
337
338 static long int lrint(Decimal32 x);
339 static long int lrint(Decimal64 x);
340 /// Special value handling:
341 /// * The current rounding mode has no effect.
342 /// * If either argument is quiet NaN, quiet NaN is returned.
343 /// * If either argument is signaling NaN, quiet NaN is returned, and
344 /// the value of the macro `EDOM` is stored into `errno`.
345 /// * If `y` is +/-0, quiet NaN is returned and the value of the macro
346 /// `EDOM` is stored into `errno`.
347 /// * If `x` is +/-infnity and `y` is not NaN, quiet NaN is returned
348 /// and the value of the macro `EDOM` is stored into `errno`.
349 /// * If `x` is finite and `y` is +/-infnity, `x` is returned.
350 static long int lrint(Decimal128 x);
351
352 static long long int llrint(Decimal32 x);
353 static long long int llrint(Decimal64 x);
354 static long long int llrint(Decimal128 x);
355
356 static Decimal32 nextafter( Decimal32 from, Decimal32 to);
357 static Decimal64 nextafter( Decimal64 from, Decimal64 to);
358 /// Return an integer value nearest to the specified `x`. Round `x`
359 /// using the current rounding mode. If `x` is +/-infnity, NaN (either
360 /// signaling or quiet) or the rounded value is outside the range of the
361 /// return type, store the value of the macro `EDOM` into `errno` and
362 /// return implementation-defined value.
363 static Decimal128 nextafter( Decimal128 from, Decimal128 to);
364
365 /// Return the next representable value of the specified `from` in the
366 /// direction of the specified `to`.
367 ///
368 static Decimal32 nexttoward(Decimal32 from, Decimal128 to);
369 static Decimal64 nexttoward(Decimal64 from, Decimal128 to);
370 /// Special value handling:
371 /// * If `from` equals `to`, `to` is returned.
372 /// * If either argument is quiet NaN, quiet NaN is returned.
373 /// * If either argument is signaling NaN, quiet NaN is returned and
374 /// the value of the macro `EDOM` is stored into `errno`.
375 /// * If `from` is finite, but the expected result is an infinity,
376 /// infinity is returned and the value of the macro `ERANGE` is
377 /// stored into `errno`.
378 /// * If `from` does not equal `to` and the result is subnormal or
379 /// zero, the value of the macro `ERANGE` is stored into `errno`.
381
382 /// Return the value of the specified `base` raised to the power of the
383 /// specified `exp`.
384 ///
385 static Decimal32 pow(Decimal32 base, Decimal32 exp);
386 static Decimal64 pow(Decimal64 base, Decimal64 exp);
387 /// Special value handling:
388 /// * If `base` is finite and negative and `exp` is finite and
389 /// non-integer, quiet NaN is returned and the value of the macro
390 /// `EDOM` is stored into `errno`.
391 /// * If the mathematical result of this function is infinity or
392 /// undefined or a range error due to overflow occurs, infinity is
393 /// returned and the value of the macro `ERANGE` is stored into
394 /// `errno`.
395 /// * If a range error occurs due to underflow, the correct result
396 /// (after rounding) is returned and the value of the macro `ERANGE`
397 /// is stored into `errno`.
398 /// * If either argument is signaling NaN, quiet NaN is returned and
399 /// the value of the macro `EDOM` is stored into `errno`.
400 static Decimal128 pow(Decimal128 base, Decimal128 exp);
401
402 /// Return, using the specified `x`, `y`, and `z`, the value of the
403 /// expression `x * y + z`, rounded as one ternary operation according
404 /// to the current decimal floating point rounding mode.
405 ///
406 static Decimal32 fma(Decimal32 x, Decimal32 y, Decimal32 z);
407 static Decimal64 fma(Decimal64 x, Decimal64 y, Decimal64 z);
408 /// Special value handling:
409 /// * If `x` or `y` are quiet NaN, quiet NaN is returned.
410 /// * If any argument is signaling NaN, quiet NaN is returned and the
411 /// value of the macro `EDOM` is stored into `errno`.
412 /// * If `x*y` is an exact infinity and `z` is an infinity with the
413 /// opposite sign, quiet NaN is returned and the value of the macro
414 /// `EDOM` is stored into `errno`.
415 /// * If `x` is zero and `y` is infinite or if `x` is infinite and `y`
416 /// is zero, and `z` is not a NaN, then quiet NaN is returned and the
417 /// value of the macro `EDOM` is stored into `errno`.
418 /// * If `x` is zero and `y` is infinite or if `x` is infinite and `y`
419 /// is zero, and `z` is NaN, then quiet NaN is returned.
421
422 // Selecting, converting functions
423
424 /// Return the absolute value of the specified `x`.
425 ///
426 static Decimal32 fabs(Decimal32 value);
427 static Decimal64 fabs(Decimal64 value);
428 /// Special value handling:
429 /// * if `x` is NaN (either signaling or quiet), quiet NaN is returned.
430 /// * if `x` is +/-infinity or +/-0, it is returned unmodified.
431 static Decimal128 fabs(Decimal128 value);
432
433 /// Return the square root of the specified `x`.
434 ///
435 static Decimal32 sqrt(Decimal32 x);
436 static Decimal64 sqrt(Decimal64 x);
437 /// Special value handling:
438 /// * If `x` is NaN, NaN is returned.
439 /// * If `x` is less than -0, NaN is returned and the value of the
440 /// macro `EDOM` is stored into `errno`.
441 /// * If `x` is +/-infinity or +/-0, it is returned unmodified.
442 static Decimal128 sqrt(Decimal128 x);
443
444 // classification
445
446 // Names are camelCase so they do not collide with macros of 'math.h'.
447
448 /// Return the integer value that respresents the floating point
449 /// classification of the specified `x` value as follows:
450 ///
451 /// * if `x` is NaN, return FP_NAN;
452 /// * otherwise if `x` is positive or negative infinity, return
453 /// `FP_INFINITE`;
454 /// * otherwise if `x` is a subnormal value, return `FP_SUBNORMAL`
455 /// * otherwise if `x` is a zero value, return `FP_ZERO`
456 /// * otherwise return `FP_NORMAL`
457 ///
458 static int classify(Decimal32 x);
459 static int classify(Decimal64 x);
460 /// Note that the mention `FP_XXX` constants are C99 standard macros and
461 /// they are defined in the math.h (cmath) standard header. On systems
462 /// that fail to define those standard macros we define the in this
463 /// component as public macros.
464 static int classify(Decimal128 x);
465
466
467 static bool isFinite(Decimal32 x);
468 static bool isFinite(Decimal64 x);
469 /// Return `true` if the specified `x` is not an infinity value or NaN
470 /// and `false` otherwise. Note that this is equivalent to
471 /// `classify(x) != FP_INFINITE && classify(x) != FP_NAN`.
472 static bool isFinite(Decimal128 x);
473
474 static bool isInf(Decimal32 x);
475 static bool isInf(Decimal64 x);
476 /// Return `true` if the specified `x` is an infinity value and `false`
477 /// otherwise. Note that this is equivalent to
478 /// `classify(x) == FP_INFINITE`.
479 static bool isInf(Decimal128 x);
480
481 static bool isNan(Decimal32 x);
482 static bool isNan(Decimal64 x);
483 /// Return `true` if the specified `x` is NaN and `false` otherwise.
484 /// Note that this is equivalent to `classify(x) == FP_NAN`.
485 static bool isNan(Decimal128 x);
486
487 static bool isNormal(Decimal32 x);
488 static bool isNormal(Decimal64 x);
489 /// Return `true` if the specified `x` is a normal value and `false`
490 /// otherwise. Note that this is equivalent to
491 /// `classify(x) == FP_NORMAL`.
492 static bool isNormal(Decimal128 x);
493
494 // Comparison functions
495
496 static bool isUnordered(Decimal32 x, Decimal32 y);
497 static bool isUnordered(Decimal64 x, Decimal64 y);
498 /// Return `true` if either (or both) of the specified `x` and `y`
499 /// arguments is a NaN, or `false` otherwise.
501
502
503 // Rounding functions
504
505 /// Return the smallest integral value that is not less than the
506 /// specified `x`.
507 ///
508 /// Special value handling:
509 /// * if `x` is quiet NaN, quiet NaN is returned.
510 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
511 /// the macro `EDOM` is stored into `errno`.
512 /// * if `x` is +/-infinity or +/-0, it is returned unmodified.
513 ///
514 static Decimal32 ceil(Decimal32 x);
515 static Decimal64 ceil(Decimal64 x);
516 /// Examples: `ceil(0.5)` ==> 1.0; `ceil(-0.5)` ==> 0.0
517 static Decimal128 ceil(Decimal128 x);
518
519 /// Return the largest integral value that is not greater than the
520 /// specified `x`.
521 ///
522 /// Special value handling:
523 /// * if `x` is quiet NaN, quiet NaN is returned.
524 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
525 /// the macro `EDOM` is stored into `errno`.
526 /// * if `x` is +/-infinity or +/-0, it is returned unmodified.
527 ///
528 static Decimal32 floor(Decimal32 x);
529 static Decimal64 floor(Decimal64 x);
530 /// Examples: `floor(0.5)` ==> 0.0; `floor(-0.5)` ==> -1.0
531 static Decimal128 floor(Decimal128 x);
532
533 /// Return the integral value nearest to the specified `x`. Round
534 /// halfway cases away from zero, regardless of the current decimal
535 /// floating point rounding mode.
536 ///
537 /// Special value handling:
538 /// * if `x` is quiet NaN, quiet NaN is returned.
539 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
540 /// the macro `EDOM` is stored into `errno`.
541 /// * if `x` is +/-infinity or +/-0, it is returned unmodified.
542 ///
543 static Decimal32 round(Decimal32 x);
544 static Decimal64 round(Decimal64 x);
545 /// Examples: `round(0.5)` ==> 1.0; `round(-0.5)` ==> -1.0
546 static Decimal128 round(Decimal128 x);
547
548 /// Return the integral value nearest to the specified `x`. Round
549 /// halfway cases away from zero, regardless of the current decimal
550 /// floating point rounding mode.
551 ///
552 /// Special value handling:
553 /// * if `x` is NaN (either quiet or signaling), quiet NaN is returned
554 /// and the value of the macro `EDOM` is stored into `errno`.
555 /// * if `x` is +/-infinity, quite NaN is returned and the value of the
556 /// macro `EDOM` is stored into `errno`.
557 /// * If the result of the rounding is outside the range of the return
558 /// type, the macro `EDOM` is stored into `errno`.
559 ///
560 static long int lround(Decimal32 x);
561 static long int lround(Decimal64 x);
562 /// Examples: `lround(0.5)` ==> 1.0; `lround(-0.5)` ==> -1.0
563 static long int lround(Decimal128 x);
564
565 /// Return the specified `x` value rounded to the specified `precision`
566 /// decimal places. Round halfway cases away from zero, regardless of
567 /// the current decimal floating point rounding mode. If `x` is
568 /// integral, positive zero, negative zero, NaN, or infinity then return
569 /// `x` itself.
570 ///
571 static Decimal32 round(Decimal32 x, unsigned int precision);
572 static Decimal64 round(Decimal64 x, unsigned int precision);
573 /// Examples: `round(3.14159, 3)` ==> 3.142
574 static Decimal128 round(Decimal128 x, unsigned int precision);
575
576 /// Return the nearest integral value that is not greater in absolute
577 /// value than the specified `x`.
578 ///
579 /// Special value handling:
580 /// * if `x` is quiet NaN, quiet NaN is returned.
581 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
582 /// the macro `EDOM` is stored into `errno`.
583 /// * if `x` is +/-infinity or +/-0, it is returned unmodified.
584 ///
585 static Decimal32 trunc(Decimal32 x);
586 static Decimal64 trunc(Decimal64 x);
587 /// Examples: `trunc(0.5)` ==> 0.0; `trunc(-0.5)` ==> 0.0
588 static Decimal128 trunc(Decimal128 x);
589
590 /// Return the specified `x` value truncated to the specified
591 /// `precision` decimal places. Round towards zero, regardless of the
592 /// current decimal floating point rounding mode. If precision of `x`
593 /// is less than or equal the `precision` or `x` is positive zero,
594 /// negative zero, NaN, or infinity then return `x` itself.
595 ///
596 static Decimal32 trunc(Decimal32 x, unsigned int precision);
597 static Decimal64 trunc(Decimal64 x, unsigned int precision);
598 /// Examples: `trunc(3.14159, 3)` ==> 3.141
599 static Decimal128 trunc(Decimal128 x, unsigned int precision);
600
601 // Quantum functions
602
603 /// Return the result of multiplying the specified `value` by ten raised
604 /// to the specified `exponent`. The quantum of `value` is scaled
605 /// according to IEEE 754's `scaleB` operations.
606 ///
608 int exponent);
610 int exponent);
611 /// Special value handling:
612 /// * If `value` is quiet NaN, quiet NaN is returned.
613 /// * If `value` is signaling NaN, quiet NaN is returned and the value
614 /// of the macro `EDOM` is stored into `errno`.
615 /// * If `x` is infinite, then infinity is returned.
616 /// * If a range error due to overflow occurs, infinity is returned and
617 ///: the value of the macro `ERANGE` is stored into `errno`.
619 int exponent);
620
621 static Decimal32 quantize(Decimal32 value, Decimal32 exponent);
622 static Decimal64 quantize(Decimal64 value, Decimal64 exponent);
623 /// Return a number equal to the specified `value` (except for possible
624 /// rounding) having the exponent equal to the exponent of the specified
625 /// `exponent`. Rounding may occur when the exponent is greater than
626 /// the quantum of `value`. E.g., `quantize(147e-2_d32, 1e-1_d32)`
627 /// yields `15e-1_d32`. In the opposite direction, if `exponent` is
628 /// sufficiently less than the quantum of `value`, it may not be
629 /// possible to construct the requested result, and if so, `NaN` is
630 /// returned. E.g., `quantize(1234567e0_d32, 1e-1_d32)` returns `NaN`.
631 static Decimal128 quantize(Decimal128 value, Decimal128 exponent);
632
633 static Decimal32 quantize(Decimal32 value, int exponent);
634 static Decimal64 quantize(Decimal64 value, int exponent);
635 /// Return a number equal to the specified `value` (except for possible
636 /// rounding) having the specified `exponent`. Rounding may occur when
637 /// `exponent` is greater than the quantum of `value`. E.g.,
638 /// `quantize(147e-2_d32, -1)` yields `15e-1_d32`. In the opposite
639 /// direction, if `exponent` is sufficiently less than the quantum of
640 /// `value`, it may not be possible to construct the requested result,
641 /// and if so, `NaN` is returned. E.g., `quantize(1234567e0_d32, -1)`
642 /// returns `NaN`. Behavior is undefined unless the `exponent`
643 /// satisfies the following conditions
644 /// * for `Decimal32` type: `-101 <= exponent <= 90`
645 /// * for `Decimal64` type: `-398 <= exponent <= 369`
646 /// * for `Decimal128` type: `-6176 <= exponent <= 6111`
647 static Decimal128 quantize(Decimal128 value, int exponent);
648
649 /// If a floating-point number equal to the specified `y` and having the
650 /// specified `exponent` can be constructed, set that value into the
651 /// specified `x` and return 0. Otherwise, or if `y` is NaN or
652 /// infinity, leave the contents of `x` unchanged and return a non-zero
653 /// value. The behavior is undefined unless `exponent` satisfies the
654 /// following conditions
655 /// * for `Decimal32` type: `-101 <= exponent <= 90`
656 /// * for `Decimal64` type: `-398 <= exponent <= 369`
657 /// * for `Decimal128` type: `-6176 <= exponent <= 6111`
658 ///
659 static int quantizeEqual(Decimal32 *x, Decimal32 y, int exponent);
660 static int quantizeEqual(Decimal64 *x, Decimal64 y, int exponent);
661 /// Example:
662 /// `Decimal32 x;`
663 /// `BSLS_ASSERT(0 == quantizeEqual(&x, 123e+3_d32, 2);`
664 /// `BSLS_ASSERT(1230e+2_d32 == x);`
665 /// `BSLS_ASSERT(0 != quantizeEqual(&x, 123e+3_d32, -2);`
666 /// `BSLS_ASSERT(1230e+2_d32 == x);`
667 static int quantizeEqual(Decimal128 *x, Decimal128 y, int exponent);
668
669 static int quantum(Decimal32 value);
670 static int quantum(Decimal64 value);
671 /// Return an integer equal to the exponent field in the specified
672 /// `value`. Each decimal floating point number is a representation of
673 /// the ideal form `s * (10 ** e)`, where `s` is significand and `e` is
674 /// exponent. This function returns that exponent value. The behavior
675 /// is undefined if `value` is NaN or `value` is infinity.
676 static int quantum(Decimal128 value);
677
678 static bool sameQuantum(Decimal32 x, Decimal32 y);
679 static bool sameQuantum(Decimal64 x, Decimal64 y);
680 /// Return `true` if the specified `x` and `y` values have the same
681 /// quantum exponents, and `false` otherwise. If both arguments are NaN
682 /// or both arguments are infinity, they have the same quantum
683 /// exponents. Note that if exactly one operand is NaN or exactly one
684 /// operand is infinity, they do not have the same quantum exponents.
685 static bool sameQuantum(Decimal128 x, Decimal128 y);
686
687 // Decompose functions
688
689 /// Decompose the specified decimal `value` into the components of
690 /// the decimal floating-point format and load the result into the
691 /// specified `sign`, `significand` and `exponent` such that
692 /// `value` is equal to `sign * significand * (10 ** exponent)`.
693 /// The special values infinity and NaNs are decomposed to `sign`,
694 /// `exponent` and `significand` parts, even though they don't have
695 /// their normal meaning (except `sign`). That is those specific values
696 /// cannot be restored using these parts, unlike the finite ones.
697 /// Return the integer value that represents the floating point
698 /// classification of the specified `value` as follows:
699 ///
700 /// * if `value` is NaN, return FP_NAN;
701 /// * if `value` is infinity, return `FP_INFINITE`;
702 /// * if `value` is a subnormal value, return `FP_SUBNORMAL`;
703 /// * if `value` is a zero value, return `FP_ZERO`;
704 /// * otherwise return `FP_NORMAL`.
705 ///
706 static int decompose(int *sign,
707 unsigned int *significand,
708 int *exponent,
709 Decimal32 value);
710 static int decompose(int *sign,
711 bsls::Types::Uint64 *significand,
712 int *exponent,
713 Decimal64 value);
714 /// Note that a decomposed representation may not be unique,
715 /// for example 10 can be represented as either `10 * (10 ** 0)`
716 /// or `1 * (10 ** 1)`. The returned `significand` and `exponent`
717 /// reflect the encoded representation of `value` (i.e., they
718 /// reflect the `quantum` of `value`).
719 static int decompose(int *sign,
720 Uint128 *significand,
721 int *exponent,
722 Decimal128 value);
723
724 // Format functions
725
726 static
727 int format(char *buffer,
728 int length,
729 Decimal32 value,
731
732 static
733 int format(char *buffer,
734 int length,
735 Decimal64 value,
737
738 /// Format the specified `value`, placing the output in the buffer
739 /// designated by the specified `buffer` and `length`, and return the
740 /// length of the formatted value. If there is insufficient room in the
741 /// buffer, its contents will be left in an unspecified state, with the
742 /// returned value indicating the necessary size. This function does not
743 /// write a terminating null character. If `length` is not positive,
744 /// `buffer` is permitted to be null. This can be used to determine the
745 /// necessary buffer size. Optionally specify a `cfg`, indicating
746 /// formatting parameters. If `cfg` is not specified, then default
747 /// configuration instance, indicating scientific notation style with a
748 /// precision sufficient to produce all available digits is used. See the
749 /// @ref bdldfp_decimalformatconfig-attributes section for information on
750 /// the configuration attributes.
751 ///
752 /// Note that for some combinations of `value` and precision provided by
753 /// `cfg` object, the number being written must first be rounded to fewer
754 /// digits than it initially contains. The number written must be as close
755 /// as possible to the initial value given the constraints on precision.
756 /// The rounding should be done as "round-half-up", i.e., round up in
757 /// magnitude when the first of the discarded digits is between 5 and 9.
758 ///
759 /// Also note that if the configuration format attribute `style` is
760 /// `e_NATURAL` then all significand digits of the `value` are output in
761 /// the buffer regardless of the value specified in configuration's
762 /// `precision` attribute.
763 static
764 int format(char *buffer,
765 int length,
766 Decimal128 value,
768};
769
770 // =============================
771 // class DecimalUtil_CStringUtil
772 // =============================
773
774/// This component-private utility `struct` provides a namespace for the
775/// `flatten` overload set intended to be used in concert with an overload set
776/// consisting of a function template with a deduced argument and an
777/// non-template overload accepting a `const char *`. The actual
778/// implementation of the functionality would be in the `const char *` overload
779/// whereas the purpose of the function template is to invoke the `const char
780/// *` overload with a null-terminated string.
781///
782/// The function template achieves null-termination by recursively calling the
783/// function and supplying it with the result of `flatten` invoked on the
784/// deduced argument. This `flatten` invocation will call `c_str()` on various
785/// supported `string` types, will produce a temporary `bsl::string` for
786/// possibly non-null-terminated `bslstl::StringRef`, and will result in a
787/// `BSLMF_ASSERT` for any unsupported type. Calling the function with the
788/// temporary `bsl::string` produced from `bslstl::StringRef` will result in a
789/// second invocation of `flatten`, this time producing `const char *`, and
790/// finally calling the function with a null-terminated string.
791///
792/// Note that the `bslstl::StringRef` overload for `flatten` is provided for
793/// backwards compatibility. Without it, the `bsl::string` and `std::string`
794/// overloads would be ambiguous. In new code, it is preferable to not provide
795/// `bslstl::StringRef` overload in a similar facility and require the clients
796/// to explicitly state the string type in their code, making a potential
797/// allocation obvious. The `bsl::string_view` overload is not provided for
798/// the same reason.
800
801 // CLASS METHODS
802
803 /// Return the specified `cString`.
804 static const char *flatten(const char *cString);
805 static const char *flatten(char *cString);
806
807 /// Return the result of invoking 'c_str()' on the specified 'string'.
808 static const char *flatten(const bsl::string& string);
809 static const char *flatten(const std::string& string);
810#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
811 static const char *flatten(const std::pmr::string& string);
812#endif
813
814 /// Return a temporary `bsl::string` constructed from the specified
815 /// `stringRef`.
816 static bsl::string flatten(const bslstl::StringRef& stringRef);
817
818 /// Produce a compile-time error informing the caller that the
819 /// parameterized `TYPE` is not supported as the parameter for the call.
820 template <class TYPE>
821 static const char *flatten(const TYPE&);
822};
823
824// ============================================================================
825// INLINE FUNCTION DEFINITIONS
826// ============================================================================
827
828 // -----------------
829 // class DecimalUtil
830 // -----------------
831
832// CLASS METHODS
833inline
834Decimal32 DecimalUtil::makeDecimalRaw32(int significand, int exponent)
835{
836 return DecimalImpUtil::makeDecimalRaw32(significand, exponent);
837}
838inline
839Decimal64 DecimalUtil::makeDecimalRaw64(int significand, int exponent)
840{
841 return DecimalImpUtil::makeDecimalRaw64(significand, exponent);
842}
843inline
844Decimal64 DecimalUtil::makeDecimalRaw64(unsigned int significand, int exponent)
845{
846 return DecimalImpUtil::makeDecimalRaw64(significand, exponent);
847}
848inline
849Decimal64 DecimalUtil::makeDecimalRaw64(long long significand, int exponent)
850{
851 return DecimalImpUtil::makeDecimalRaw64(significand, exponent);
852}
853inline
855DecimalUtil::makeDecimalRaw64(unsigned long long significand, int exponent)
856{
857 return DecimalImpUtil::makeDecimalRaw64(significand, exponent);
858}
859inline
860Decimal128 DecimalUtil::makeDecimalRaw128(int significand, int exponent)
861{
862 return DecimalImpUtil::makeDecimalRaw128(significand, exponent);
863}
864inline
866 int exponent)
867{
868 return DecimalImpUtil::makeDecimalRaw128(significand, exponent);
869}
870inline
871Decimal128 DecimalUtil::makeDecimalRaw128(long long significand, int exponent)
872{
873 return DecimalImpUtil::makeDecimalRaw128(significand, exponent);
874}
875inline
877DecimalUtil::makeDecimalRaw128(unsigned long long significand, int exponent)
878{
879 return DecimalImpUtil::makeDecimalRaw128(significand, exponent);
880}
881
882inline
883Decimal64 DecimalUtil::makeDecimal64(int significand, int exponent)
884{
885 return DecimalImpUtil::makeDecimal64(significand, exponent);
886}
887inline
888Decimal64 DecimalUtil::makeDecimal64(unsigned int significand, int exponent)
889{
890 return DecimalImpUtil::makeDecimal64(significand, exponent);
891}
892inline
893Decimal64 DecimalUtil::makeDecimal64(long long significand, int exponent)
894{
895 return DecimalImpUtil::makeDecimal64(significand, exponent);
896}
897inline
898Decimal64 DecimalUtil::makeDecimal64(unsigned long long significand,
899 int exponent)
900{
901 return DecimalImpUtil::makeDecimal64(significand, exponent);
902}
903
904template <class STRING_TYPE>
905inline
906int DecimalUtil::parseDecimal32(Decimal32 *out, const STRING_TYPE& str)
907{
910}
911
912template <class STRING_TYPE>
913inline
914int DecimalUtil::parseDecimal64(Decimal64 *out, const STRING_TYPE& str)
915{
918}
919
920template <class STRING_TYPE>
921inline
922int DecimalUtil::parseDecimal128(Decimal128 *out, const STRING_TYPE& str)
923{
926}
927
928template <class STRING_TYPE>
929inline
930int DecimalUtil::parseDecimal32Exact(Decimal32 *out, const STRING_TYPE& str)
931{
933 out,
935}
936
937template <class STRING_TYPE>
938inline
939int DecimalUtil::parseDecimal64Exact(Decimal64 *out, const STRING_TYPE& str)
940{
942 out,
944}
945
946template <class STRING_TYPE>
947inline
948int DecimalUtil::parseDecimal128Exact(Decimal128 *out, const STRING_TYPE& str)
949{
951 out,
953}
954
955 // Quantum functions
956
957inline
959{
960 return bdldfp::DecimalImpUtil::scaleB(*value.data(), exponent);
961}
962
963inline
965{
966 return bdldfp::DecimalImpUtil::scaleB(*value.data(), exponent);
967}
968
969inline
971{
972 return bdldfp::DecimalImpUtil::scaleB(*value.data(), exponent);
973}
974
975inline
977{
978 return DecimalImpUtil::quantize(*value.data(), *exponent.data());
979}
980
981inline
983{
984 return DecimalImpUtil::quantize(*value.data(), *exponent.data());
985}
986
987inline
989{
990 return DecimalImpUtil::quantize(*value.data(), *exponent.data());
991}
992
993inline
995{
996 BSLS_ASSERT(-101 <= exponent);
997 BSLS_ASSERT( exponent <= 90);
998 return DecimalImpUtil::quantize(*value.data(), exponent);
999}
1000
1001inline
1003{
1004 BSLS_ASSERT(-398 <= exponent);
1005 BSLS_ASSERT( exponent <= 369);
1006 return DecimalImpUtil::quantize(*value.data(), exponent);
1007}
1008
1009inline
1011{
1012 BSLS_ASSERT(-6176 <= exponent);
1013 BSLS_ASSERT( exponent <= 6111);
1014 return DecimalImpUtil::quantize(*value.data(), exponent);
1015}
1016
1017inline
1019{
1020 BSLS_ASSERT(x);
1021 BSLS_ASSERT(-101 <= exponent);
1022 BSLS_ASSERT( exponent <= 90);
1023 return DecimalImpUtil::quantizeEqual(x->data(), *y.data(), exponent);
1024}
1025
1026inline
1028{
1029 BSLS_ASSERT(x);
1030 BSLS_ASSERT(-398 <= exponent);
1031 BSLS_ASSERT( exponent <= 369);
1032 return DecimalImpUtil::quantizeEqual(x->data(), *y.data(), exponent);
1033}
1034
1035inline
1037{
1038 BSLS_ASSERT(x);
1039 BSLS_ASSERT(-6176 <= exponent);
1040 BSLS_ASSERT( exponent <= 6111);
1041 return DecimalImpUtil::quantizeEqual(x->data(), *y.data(), exponent);
1042}
1043
1044inline
1049
1050inline
1055
1056inline
1061
1062inline
1067
1068inline
1073
1074inline
1079
1080inline
1085
1086inline
1091
1092inline
1097
1098inline
1103
1104inline
1109
1110inline
1115
1116inline
1121
1122inline
1127
1128inline
1133
1134inline
1139
1140inline
1145
1146inline
1151
1152inline
1157
1158inline
1163
1164inline
1169
1170inline
1175
1176inline
1181
1182inline
1187
1188inline
1190{
1192}
1193
1194inline
1196{
1198}
1199
1200inline
1202{
1204}
1205
1206inline
1208{
1210}
1211
1212inline
1214{
1216}
1217
1218inline
1220{
1222}
1223
1224inline
1229
1230inline
1235
1236inline
1241
1242inline
1247
1248inline
1253
1254inline
1259
1260inline
1265
1266inline
1271
1272inline
1277
1278inline
1283
1284inline
1289
1290inline
1295
1296inline
1301
1302inline
1307
1308inline
1313
1314inline
1319
1320inline
1325
1326inline
1331
1332inline
1334{
1336}
1337
1338inline
1340{
1342}
1343
1344inline
1346{
1348}
1349
1350inline
1351Decimal32 DecimalUtil::round(Decimal32 x, unsigned int decimalPlaces)
1352{
1353 return bdldfp::DecimalImpUtil::round(*x.data(), decimalPlaces);
1354}
1355
1356inline
1357Decimal64 DecimalUtil::round(Decimal64 x, unsigned int decimalPlaces)
1358{
1359 return bdldfp::DecimalImpUtil::round(*x.data(), decimalPlaces);
1360}
1361
1362inline
1363Decimal128 DecimalUtil::round(Decimal128 x, unsigned int decimalPlaces)
1364{
1365 return bdldfp::DecimalImpUtil::round(*x.data(), decimalPlaces);
1366}
1367
1368inline
1373
1374inline
1379
1380inline
1385
1386inline
1391
1392inline
1397
1398inline
1403
1404inline
1409
1410inline
1415
1416inline
1421
1422inline
1427
1428inline
1433
1434inline
1439
1440 // -----------------------------
1441 // class DecimalUtil_CStringUtil
1442 // -----------------------------
1443
1444// CLASS METHODS
1445inline
1446const char *DecimalUtil_CStringUtil::flatten(const char *cString)
1447{
1448 return cString;
1449}
1450
1451inline
1452const char *DecimalUtil_CStringUtil::flatten(char *cString)
1453{
1454 return cString;
1455}
1456
1457inline
1459{
1460 return string.c_str();
1461}
1462
1463inline
1464const char *DecimalUtil_CStringUtil::flatten(const std::string& string)
1465{
1466 return string.c_str();
1467}
1468
1469#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1470inline
1471const char *DecimalUtil_CStringUtil::flatten(const std::pmr::string& string)
1472{
1473 return string.c_str();
1474}
1475#endif
1476
1477inline
1479 const bslstl::StringRef& stringRef)
1480{
1481 return stringRef;
1482}
1483
1484template <class TYPE>
1485inline
1486const char *DecimalUtil_CStringUtil::flatten(const TYPE&)
1487{
1488 BSLMF_ASSERT(("Unsupported parameter type." && !sizeof(TYPE)));
1489 return 0;
1490}
1491
1492} // close package namespace
1493
1494
1495#endif
1496
1497// ----------------------------------------------------------------------------
1498// Copyright 2014 Bloomberg Finance L.P.
1499//
1500// Licensed under the Apache License, Version 2.0 (the "License");
1501// you may not use this file except in compliance with the License.
1502// You may obtain a copy of the License at
1503//
1504// http://www.apache.org/licenses/LICENSE-2.0
1505//
1506// Unless required by applicable law or agreed to in writing, software
1507// distributed under the License is distributed on an "AS IS" BASIS,
1508// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1509// See the License for the specific language governing permissions and
1510// limitations under the License.
1511// ----------------------------- END-OF-FILE ----------------------------------
1512
1513/** @} */
1514/** @} */
1515/** @} */
Definition bdldfp_decimalformatconfig.h:118
static ValueType32 remainder(ValueType32 x, ValueType32 y)
Definition bdldfp_decimalimputil.h:2639
static ValueType32 trunc(ValueType32 x)
Definition bdldfp_decimalimputil.h:2259
static ValueType32 log(ValueType32 x)
Definition bdldfp_decimalimputil.h:2465
static ValueType128 makeDecimalRaw128(unsigned long long int significand, int exponent)
static ValueType32 fma(ValueType32 x, ValueType32 y, ValueType32 z)
Definition bdldfp_decimalimputil.h:2296
static ValueType32 scaleB(ValueType32 value, int exponent)
Definition bdldfp_decimalimputil.h:3045
static ValueType32 pow(ValueType32 base, ValueType32 exp)
Definition bdldfp_decimalimputil.h:2060
static long long int llrint(ValueType32 x)
Definition bdldfp_decimalimputil.h:1918
static ValueType32 floor(ValueType32 x)
Definition bdldfp_decimalimputil.h:2154
static ValueType32 copySign(ValueType32 x, ValueType32 y)
Definition bdldfp_decimalimputil.h:2393
static ValueType32 round(ValueType32 x)
Definition bdldfp_decimalimputil.h:2190
static ValueType32 fabs(ValueType32 x)
Definition bdldfp_decimalimputil.h:2333
static ValueType32 fmod(ValueType32 x, ValueType32 y)
Definition bdldfp_decimalimputil.h:2600
static ValueType32 log10(ValueType32 x)
Definition bdldfp_decimalimputil.h:2555
static ValueType32 makeDecimalRaw32(int significand, int exponent)
Definition bdldfp_decimalimputil.h:2950
static ValueType32 logB(ValueType32 x)
Definition bdldfp_decimalimputil.h:2510
static ValueType64 makeDecimal64(int significand, int exponent)
static long int lround(ValueType32 x)
Definition bdldfp_decimalimputil.h:2226
static ValueType32 quantize(ValueType32 value, ValueType32 exponent)
Definition bdldfp_decimalimputil.h:1721
static ValueType32 sqrt(ValueType32 x)
Definition bdldfp_decimalimputil.h:2357
static int quantizeEqual(ValueType32 *x, ValueType32 y, int exponent)
Definition bdldfp_decimalimputil.h:1805
static ValueType64 makeDecimalRaw64(unsigned long long int significand, int exponent)
static ValueType32 nexttoward(ValueType32 from, ValueType128 to)
Definition bdldfp_decimalimputil.h:2006
static ValueType32 nextafter(ValueType32 from, ValueType32 to)
Definition bdldfp_decimalimputil.h:1952
static ValueType32 exp(ValueType32 x)
Definition bdldfp_decimalimputil.h:2420
static long int lrint(ValueType32 x)
Definition bdldfp_decimalimputil.h:1885
static bool sameQuantum(ValueType32 x, ValueType32 y)
Definition bdldfp_decimalimputil.h:1864
static ValueType32 ceil(ValueType32 x)
Definition bdldfp_decimalimputil.h:2117
Definition bdldfp_decimal.h:3023
DecimalImpUtil::ValueType128 * data()
Return a modifiable pointer to the underlying implementation.
Definition bdldfp_decimal.h:6430
Definition bdldfp_decimal.h:730
DecimalImpUtil::ValueType32 * data()
Definition bdldfp_decimal.h:5668
Definition bdldfp_decimal.h:1834
DecimalImpUtil::ValueType64 * data()
Return a modifiable pointer to the underlying implementation.
Definition bdldfp_decimal.h:6063
Definition bdldfp_uint128.h:175
Definition bslstl_string.h:1281
Definition bslstl_stringref.h:372
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdldfp_decimal.h:712
Definition bdldfp_decimalutil.h:799
static const char * flatten(const char *cString)
Return the specified cString.
Definition bdldfp_decimalutil.h:1446
Definition bdldfp_decimalutil.h:136
static Decimal32 fabs(Decimal32 value)
Definition bdldfp_decimalutil.h:1405
static int classify(Decimal128 x)
static bool isNan(Decimal64 x)
static long int lround(Decimal32 x)
Definition bdldfp_decimalutil.h:1333
static int quantum(Decimal128 value)
static Decimal32 logB(Decimal32 x)
Definition bdldfp_decimalutil.h:1117
static int classify(Decimal32 x)
static bool isNan(Decimal128 x)
static int format(char *buffer, int length, Decimal128 value, const DecimalFormatConfig &cfg=DecimalFormatConfig())
static int parseDecimal64(Decimal64 *out, const char *str)
static Decimal32 trunc(Decimal32 x, unsigned int precision)
static bool isInf(Decimal64 x)
static bool isUnordered(Decimal64 x, Decimal64 y)
static Decimal64 trunc(Decimal64 x, unsigned int precision)
static Decimal32 sqrt(Decimal32 x)
Definition bdldfp_decimalutil.h:1423
static bool isNan(Decimal32 x)
static Decimal32 multiplyByPowerOf10(Decimal32 value, int exponent)
Definition bdldfp_decimalutil.h:958
static Decimal32 exp(Decimal32 x)
Definition bdldfp_decimalutil.h:1081
static int decompose(int *sign, unsigned int *significand, int *exponent, Decimal32 value)
static Decimal128 trunc(Decimal128 x, unsigned int precision)
Examples: trunc(3.14159, 3) ==> 3.141.
static int parseDecimal128Exact(Decimal128 *out, const char *str)
static bool isUnordered(Decimal32 x, Decimal32 y)
static Decimal32 log(Decimal32 x)
Definition bdldfp_decimalutil.h:1099
static bool isInf(Decimal128 x)
static bool isNormal(Decimal32 x)
static bool isUnordered(Decimal128 x, Decimal128 y)
static int decompose(int *sign, Uint128 *significand, int *exponent, Decimal128 value)
static Decimal32 makeDecimalRaw32(int significand, int exponent)
Definition bdldfp_decimalutil.h:834
static int quantum(Decimal64 value)
static Decimal128 makeDecimalRaw128(int significand, int exponent)
Definition bdldfp_decimalutil.h:860
static int parseDecimal32Exact(Decimal32 *out, const char *str)
static int classify(Decimal64 x)
static Decimal32 quantize(Decimal32 value, Decimal32 exponent)
Definition bdldfp_decimalutil.h:976
static bool isFinite(Decimal64 x)
static long long int llrint(Decimal32 x)
Definition bdldfp_decimalutil.h:1207
static Decimal32 ceil(Decimal32 x)
Definition bdldfp_decimalutil.h:1279
static int quantizeEqual(Decimal32 *x, Decimal32 y, int exponent)
Definition bdldfp_decimalutil.h:1018
static int parseDecimal32(Decimal32 *out, const char *str)
static Decimal64 makeDecimalRaw64(int significand, int exponent)
Definition bdldfp_decimalutil.h:839
static Decimal32 round(Decimal32 x)
Definition bdldfp_decimalutil.h:1315
static int format(char *buffer, int length, Decimal32 value, const DecimalFormatConfig &cfg=DecimalFormatConfig())
static Decimal32 fma(Decimal32 x, Decimal32 y, Decimal32 z)
Definition bdldfp_decimalutil.h:1387
static int quantum(Decimal32 value)
static Decimal64 makeDecimal64(int significand, int exponent)
Definition bdldfp_decimalutil.h:883
static bool isFinite(Decimal128 x)
static int parseDecimal64Exact(Decimal64 *out, const char *str)
static Decimal32 trunc(Decimal32 x)
Definition bdldfp_decimalutil.h:1369
static bool isFinite(Decimal32 x)
static long int lrint(Decimal32 x)
Definition bdldfp_decimalutil.h:1189
static bool isInf(Decimal32 x)
static Decimal32 copySign(Decimal32 x, Decimal32 y)
Definition bdldfp_decimalutil.h:1063
static bool isNormal(Decimal64 x)
static int decompose(int *sign, bsls::Types::Uint64 *significand, int *exponent, Decimal64 value)
static Decimal32 log10(Decimal32 x)
Definition bdldfp_decimalutil.h:1135
static Decimal32 pow(Decimal32 base, Decimal32 exp)
Definition bdldfp_decimalutil.h:1261
static Decimal32 fmod(Decimal32 x, Decimal32 y)
Definition bdldfp_decimalutil.h:1153
static bool sameQuantum(Decimal32 x, Decimal32 y)
Definition bdldfp_decimalutil.h:1045
static Decimal32 nextafter(Decimal32 from, Decimal32 to)
Definition bdldfp_decimalutil.h:1225
static Decimal32 floor(Decimal32 x)
Definition bdldfp_decimalutil.h:1297
static int format(char *buffer, int length, Decimal64 value, const DecimalFormatConfig &cfg=DecimalFormatConfig())
static bool isNormal(Decimal128 x)
static Decimal32 remainder(Decimal32 x, Decimal32 y)
Definition bdldfp_decimalutil.h:1171
static Decimal32 nexttoward(Decimal32 from, Decimal128 to)
Definition bdldfp_decimalutil.h:1243
static int parseDecimal128(Decimal128 *out, const char *str)
unsigned long long Uint64
Definition bsls_types.h:137