BDE 4.39.x 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.
136///
137/// See @ref bdldfp_decimalutil
139
140 // CLASS METHODS
141
142 // Creators functions
143
144 /// Create a `Decimal32` object representing a decimal floating point
145 /// number consisting of the specified `significand` and `exponent`,
146 /// with the sign given by the `significand` (if signed).
147 ///
148 /// \pre The behavior is undefined unless `-9,999,999 <= significand <= 9,999,999` and
149 /// `-101 <= exponent <= 90`.
150 static Decimal32 makeDecimalRaw32 (int significand, int exponent);
151
152 /// Create a `Decimal64` object representing a decimal floating point
153 /// number consisting of the specified `significand` and `exponent`,
154 /// with the sign given by the `significand` (if signed).
155 ///
156 /// \pre The behavior is undefined unless
157 /// `-9,999,999,999,999,999 <= significand <= 9,999,999,999,999,999` and
158 /// `-398 <= exponent <= 369`.
159 static Decimal64 makeDecimalRaw64(int significand,
160 int exponent);
161 static Decimal64 makeDecimalRaw64(unsigned int significand,
162 int exponent);
163 static Decimal64 makeDecimalRaw64(long long significand,
164 int exponent);
165 static Decimal64 makeDecimalRaw64(unsigned long long significand,
166 int exponent);
167
168 /// Create a `Deciaml128` object representing a decimal floating point
169 /// number consisting of the specified `significand` and specified
170 /// `exponent`, with the sign given by the `significand` (if signed).
171 ///
172 /// \pre The behavior is undefined unless `-6176 <= exponent <= 6111`.
173 static Decimal128 makeDecimalRaw128(int significand,
174 int exponent);
175 static Decimal128 makeDecimalRaw128(unsigned int significand,
176 int exponent);
177 static Decimal128 makeDecimalRaw128(long long significand,
178 int exponent);
179 static Decimal128 makeDecimalRaw128(unsigned long long significand,
180 int exponent);
181
182 /// Return a `DecimalNN` object that has the specified `significand` and
183 /// `exponent`, rounded according to the current decimal rounding mode,
184 /// if necessary. If an overflow condition occurs, store the value of
185 /// the macro `ERANGE` into `errno` and return infinity with the
186 /// appropriate sign.
187 static Decimal64 makeDecimal64(int significand,
188 int exponent);
189 static Decimal64 makeDecimal64(unsigned int significand,
190 int exponent);
191 static Decimal64 makeDecimal64(long long significand,
192 int exponent);
193 static Decimal64 makeDecimal64(unsigned long long significand,
194 int exponent);
195
196 static int parseDecimal32(Decimal32 *out, const char *str);
197 static int parseDecimal64(Decimal64 *out, const char *str);
198 static int parseDecimal128(Decimal128 *out, const char *str);
199 template <class STRING_TYPE>
200 static int parseDecimal32(Decimal32 *out, const STRING_TYPE& str);
201 template <class STRING_TYPE>
202 static int parseDecimal64(Decimal64 *out, const STRING_TYPE& str);
203
204 /// Load into the specified `out` the decimal floating point number
205 /// described by the specified `str`; return zero if the conversion was
206 /// successful and non-zero otherwise. The value of `out` is
207 /// unspecified if the function returns a non-zero value. The
208 /// parameterized `STRING_TYPE` must be one of `bsl::string`,
209 /// `std::string`, `std::pmr::string` (if supported), or
210 /// `bslstl::StringRef`.
211 template <class STRING_TYPE>
212 static int parseDecimal128(Decimal128 *out, const STRING_TYPE& str);
213
214 static int parseDecimal32Exact(Decimal32 *out, const char *str);
215 static int parseDecimal64Exact(Decimal64 *out, const char *str);
216 static int parseDecimal128Exact(Decimal128 *out, const char *str);
217 template <class STRING_TYPE>
218 static int parseDecimal32Exact(Decimal32 *out, const STRING_TYPE& str);
219 template <class STRING_TYPE>
220 static int parseDecimal64Exact(Decimal64 *out, const STRING_TYPE& str);
221
222 /// Load into the specified `out` the decimal floating point number
223 /// described by the specified `str`. Return 0 if `out` is an exact
224 /// representation of `str`, a positive value if `str` is an
225 /// approximation of `str` (i.e., `str` could not be represented
226 /// exactly), and a negative value if `str` could not be parsed. The
227 /// value of `out` is unspecified if the function returns a negative
228 /// value. The parameterized `STRING_TYPE` must be one of
229 /// `bsl::string`, `std::string`, `std::pmr::string` (if supported), or
230 /// `bslstl::StringRef`.
231 template <class STRING_TYPE>
232 static int parseDecimal128Exact(Decimal128 *out, const STRING_TYPE& str);
233
234 // math
235
236 /// Return a decimal value with the magnitude of the specifed `x` and
237 /// the sign of the specified `y`. If `x` is NaN, then NaN with the
238 /// sign of `y` is returned.
239 ///
240 /// Examples: `copySign( 5.0, -2.0)` ==> -5.0;
241 /// `copySign(-5.0, -2.0)` ==> 5.0
245
246 /// Return `e` (Euler's number, 2.7182818) raised to the specified power
247 /// `x`.
248 ///
249 /// Special value handling:
250 /// * If `x` is +/-0, 1 is returned.
251 /// * If `x` is negative infinity, +0 is returned.
252 /// * If `x` is +infinity, +infinity is returned.
253 /// * If `x` is quiet NaN, quiet NaN is returned.
254 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
255 /// the macro `EDOM` is stored into `errno`.
256 /// * If `x` is finite, but the result value is outside the range of
257 /// the return type, store the value of the macro `ERANGE` into
258 /// `errno` and +infinity value is returned.
259 static Decimal32 exp(Decimal32 x);
260 static Decimal64 exp(Decimal64 x);
261 static Decimal128 exp(Decimal128 x);
262
263 /// Return the natural (base `e`) logarithm of the specified `x`.
264 ///
265 /// Special value handling:
266 /// * If `x` is +/-0, -infinity is returned and the value of the macro
267 /// `ERANGE` is stored into `errno`.
268 /// * If `x` is 1, +0 is returned.
269 /// * If `x` is negative, quiet NaN is returned and the value of the
270 /// macro `EDOM` is stored into `errno`.
271 /// * If `x` is +infinity, +infinity is returned.
272 /// * If `x` is quiet NaN, quiet NaN is returned.
273 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
274 /// the macro `EDOM` is stored into `errno`.
275 static Decimal32 log(Decimal32 x);
276 static Decimal64 log(Decimal64 x);
277 static Decimal128 log(Decimal128 x);
278
279 /// Return the FLT_RADIX-based logarithm (i.e., base 10) of the absolute
280 /// value of the specified `x`.
281 ///
282 /// Special value handling:
283 /// * If `x` is +/-0, -infinity is returned and the value of the macro
284 /// `ERANGE` is stored into `errno`.
285 /// * If `x` is 1, +0 is returned.
286 /// * If `x` is +/-infinity, +infinity is returned.
287 /// * If `x` is quiet NaN, quiet NaN is returned.
288 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
289 /// the macro `EDOM` is stored into `errno`.
290 ///
291 /// Examples: `logB( 10.0)` ==> 1.0;
292 /// `logB(-100.0)` ==> 2.0
293 static Decimal32 logB(Decimal32 x);
294 static Decimal64 logB(Decimal64 x);
295 static Decimal128 logB(Decimal128 x);
296
297 /// Return the common (base-10) logarithm of the specified `x`.
298 ///
299 /// Special value handling:
300 /// * If `x` is +/-0, -infinity is returned and the value of the macro
301 /// `ERANGE` is stored into `errno`.
302 /// * If `x` is 1, +0 is returned.
303 /// * If `x` is negative, quiet NaN is returned and the value of the
304 /// macro `EDOM` is stored into `errno`.
305 /// * If `x` is +infinity, +infinity is returned.
306 /// * If `x` is quiet NaN, quiet NaN is returned.
307 /// * If `x` is signaling NaN, NaN is returned and the value of the
308 /// macro `EDOM` is stored into `errno`.
309 static Decimal32 log10(Decimal32 x);
310 static Decimal64 log10(Decimal64 x);
311 static Decimal128 log10(Decimal128 x);
312
313 /// Return the remainder of the division of the specified `x` by the
314 /// specified `y`. The returned value has the same sign as `x` and is
315 /// less than `y` in magnitude.
316 ///
317 /// Special value handling:
318 /// * If either argument is quiet NaN, quiet NaN is returned.
319 /// * If either argument is signaling NaN, quiet NaN is returned, and
320 /// the value of the macro `EDOM` is stored into `errno`.
321 /// * If `x` is +/-infnity and `y` is not NaN, quiet NaN is returned
322 /// and the value of the macro `EDOM` is stored into `errno`.
323 /// * If `x` is +/-0 and `y` is not zero, +/-0 is returned.
324 /// * If `y` is +/-0, quite NaN is returned and the value of the macro
325 /// `EDOM` is stored into `errno`.
326 /// * If `x` is finite and `y` is +/-infnity, `x` is returned.
327 static Decimal32 fmod(Decimal32 x, Decimal32 y);
328 static Decimal64 fmod(Decimal64 x, Decimal64 y);
330
331 /// Return the remainder of the division of the specified `x` by the
332 /// specified `y`. The remainder of the division operation `x/y`
333 /// calculated by this function is exactly the value `x - n*y`, where
334 /// `n` s the integral value nearest the exact value `x/y`. When
335 /// `|n - x/y| == 0.5`, the value `n` is chosen to be even.
336 ///
337 /// \note Note that in contrast to `DecimalImpUtil::fmod()`, the returned value is not
338 /// guaranteed to have the same sign as `x`.
339 ///
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.
353
354 static long int lrint(Decimal32 x);
355 static long int lrint(Decimal64 x);
356 static long int lrint(Decimal128 x);
357
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 long long int llrint(Decimal32 x);
364 static long long int llrint(Decimal64 x);
365 static long long int llrint(Decimal128 x);
366
367 static Decimal32 nextafter( Decimal32 from, Decimal32 to);
368 static Decimal64 nextafter( Decimal64 from, Decimal64 to);
369 static Decimal128 nextafter( Decimal128 from, Decimal128 to);
370
371 /// Return the next representable value of the specified `from` in the
372 /// direction of the specified `to`.
373 ///
374 /// Special value handling:
375 /// * If `from` equals `to`, `to` is returned.
376 /// * If either argument is quiet NaN, quiet NaN is returned.
377 /// * If either argument is signaling NaN, quiet NaN is returned and
378 /// the value of the macro `EDOM` is stored into `errno`.
379 /// * If `from` is finite, but the expected result is an infinity,
380 /// infinity is returned and the value of the macro `ERANGE` is
381 /// stored into `errno`.
382 /// * If `from` does not equal `to` and the result is subnormal or
383 /// zero, the value of the macro `ERANGE` is stored into `errno`.
384 static Decimal32 nexttoward(Decimal32 from, Decimal128 to);
385 static Decimal64 nexttoward(Decimal64 from, Decimal128 to);
387
388 /// Return the value of the specified `base` raised to the power of the
389 /// specified `exp`.
390 ///
391 /// Special value handling:
392 /// * If `base` is finite and negative and `exp` is finite and
393 /// non-integer, quiet NaN is returned and the value of the macro
394 /// `EDOM` is stored into `errno`.
395 /// * If the mathematical result of this function is infinity or
396 /// undefined or a range error due to overflow occurs, infinity is
397 /// returned and the value of the macro `ERANGE` is stored into
398 /// `errno`.
399 /// * If a range error occurs due to underflow, the correct result
400 /// (after rounding) is returned and the value of the macro `ERANGE`
401 /// is stored into `errno`.
402 /// * If either argument is signaling NaN, quiet NaN is returned and
403 /// the value of the macro `EDOM` is stored into `errno`.
404 static Decimal32 pow(Decimal32 base, Decimal32 exp);
405 static Decimal64 pow(Decimal64 base, Decimal64 exp);
406 static Decimal128 pow(Decimal128 base, Decimal128 exp);
407
408 /// Return, using the specified `x`, `y`, and `z`, the value of the
409 /// expression `x * y + z`, rounded as one ternary operation according
410 /// to the current decimal floating point rounding mode.
411 ///
412 /// Special value handling:
413 /// * If `x` or `y` are quiet NaN, quiet NaN is returned.
414 /// * If any argument is signaling NaN, quiet NaN is returned and the
415 /// value of the macro `EDOM` is stored into `errno`.
416 /// * If `x*y` is an exact infinity and `z` is an infinity with the
417 /// opposite sign, quiet NaN is returned and the value of the macro
418 /// `EDOM` is stored into `errno`.
419 /// * If `x` is zero and `y` is infinite or if `x` is infinite and `y`
420 /// is zero, and `z` is not a NaN, then quiet NaN is returned and the
421 /// value of the macro `EDOM` is stored into `errno`.
422 /// * If `x` is zero and `y` is infinite or if `x` is infinite and `y`
423 /// is zero, and `z` is NaN, then quiet NaN is returned.
424 static Decimal32 fma(Decimal32 x, Decimal32 y, Decimal32 z);
425 static Decimal64 fma(Decimal64 x, Decimal64 y, Decimal64 z);
427
428 // Selecting, converting functions
429
430 /// Return the absolute value of the specified `x`.
431 ///
432 /// Special value handling:
433 /// * if `x` is NaN (either signaling or quiet), quiet NaN is returned.
434 /// * if `x` is +/-infinity or +/-0, it is returned unmodified.
435 static Decimal32 fabs(Decimal32 value);
436 static Decimal64 fabs(Decimal64 value);
437 static Decimal128 fabs(Decimal128 value);
438
439 /// Return the square root of the specified `x`.
440 ///
441 /// Special value handling:
442 /// * If `x` is NaN, NaN is returned.
443 /// * If `x` is less than -0, NaN is returned and the value of the
444 /// macro `EDOM` is stored into `errno`.
445 /// * If `x` is +/-infinity or +/-0, it is returned unmodified.
446 static Decimal32 sqrt(Decimal32 x);
447 static Decimal64 sqrt(Decimal64 x);
448 static Decimal128 sqrt(Decimal128 x);
449
450 // classification
451
452 // Names are camelCase so they do not collide with macros of 'math.h'.
453
454 /// Return the integer value that respresents the floating point
455 /// classification of the specified `x` value as follows:
456 ///
457 /// * if `x` is NaN, return FP_NAN;
458 /// * otherwise if `x` is positive or negative infinity, return
459 /// `FP_INFINITE`;
460 /// * otherwise if `x` is a subnormal value, return `FP_SUBNORMAL`
461 /// * otherwise if `x` is a zero value, return `FP_ZERO`
462 /// * otherwise return `FP_NORMAL`
463 ///
464 ///
465 /// \note Note that the mention `FP_XXX` constants are C99 standard macros and
466 /// they are defined in the math.h (cmath) standard header. On systems
467 /// that fail to define those standard macros we define the in this
468 /// component as public macros.
469 static int classify(Decimal32 x);
470 static int classify(Decimal64 x);
471 static int classify(Decimal128 x);
472
473
474 /// Return `true` if the specified `x` is not an infinity value or NaN and `false` otherwise.
475 ///
476 /// \note Note that this is equivalent to
477 /// `classify(x) != FP_INFINITE && classify(x) != FP_NAN`.
478 static bool isFinite(Decimal32 x);
479 static bool isFinite(Decimal64 x);
480 static bool isFinite(Decimal128 x);
481
482 /// Return `true` if the specified `x` is an infinity value and `false` otherwise.
483 ///
484 /// \note Note that this is equivalent to
485 /// `classify(x) == FP_INFINITE`.
486 static bool isInf(Decimal32 x);
487 static bool isInf(Decimal64 x);
488 static bool isInf(Decimal128 x);
489
490 /// Return `true` if the specified `x` is NaN and `false` otherwise.
491 ///
492 /// \note Note that this is equivalent to `classify(x) == FP_NAN`.
493 static bool isNan(Decimal32 x);
494 static bool isNan(Decimal64 x);
495 static bool isNan(Decimal128 x);
496
497 /// Return `true` if the specified `x` is a normal value and `false` otherwise.
498 ///
499 /// \note Note that this is equivalent to
500 /// `classify(x) == FP_NORMAL`.
501 static bool isNormal(Decimal32 x);
502 static bool isNormal(Decimal64 x);
503 static bool isNormal(Decimal128 x);
504
505 // Comparison functions
506
507 /// Return `true` if either (or both) of the specified `x` and `y`
508 /// arguments is a NaN, or `false` otherwise.
509 static bool isUnordered(Decimal32 x, Decimal32 y);
510 static bool isUnordered(Decimal64 x, Decimal64 y);
512
513
514 // Rounding functions
515
516 /// Return the smallest integral value that is not less than the
517 /// specified `x`.
518 ///
519 /// Special value handling:
520 /// * if `x` is quiet NaN, quiet NaN is returned.
521 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
522 /// the macro `EDOM` is stored into `errno`.
523 /// * if `x` is +/-infinity or +/-0, it is returned unmodified.
524 ///
525 /// Examples: `ceil(0.5)` ==> 1.0; `ceil(-0.5)` ==> 0.0
526 static Decimal32 ceil(Decimal32 x);
527 static Decimal64 ceil(Decimal64 x);
528 static Decimal128 ceil(Decimal128 x);
529
530 /// Return the largest integral value that is not greater than the
531 /// specified `x`.
532 ///
533 /// Special value handling:
534 /// * if `x` is quiet NaN, quiet NaN is returned.
535 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
536 /// the macro `EDOM` is stored into `errno`.
537 /// * if `x` is +/-infinity or +/-0, it is returned unmodified.
538 ///
539 /// Examples: `floor(0.5)` ==> 0.0; `floor(-0.5)` ==> -1.0
540 static Decimal32 floor(Decimal32 x);
541 static Decimal64 floor(Decimal64 x);
542 static Decimal128 floor(Decimal128 x);
543
544 /// Return the integral value nearest to the specified `x`. Round
545 /// halfway cases away from zero, regardless of the current decimal
546 /// floating point rounding mode.
547 ///
548 /// Special value handling:
549 /// * if `x` is quiet NaN, quiet NaN is returned.
550 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
551 /// the macro `EDOM` is stored into `errno`.
552 /// * if `x` is +/-infinity or +/-0, it is returned unmodified.
553 ///
554 /// Examples: `round(0.5)` ==> 1.0; `round(-0.5)` ==> -1.0
555 static Decimal32 round(Decimal32 x);
556 static Decimal64 round(Decimal64 x);
557 static Decimal128 round(Decimal128 x);
558
559 /// Return the integral value nearest to the specified `x`. Round
560 /// halfway cases away from zero, regardless of the current decimal
561 /// floating point rounding mode.
562 ///
563 /// Special value handling:
564 /// * if `x` is NaN (either quiet or signaling), quiet NaN is returned
565 /// and the value of the macro `EDOM` is stored into `errno`.
566 /// * if `x` is +/-infinity, quite NaN is returned and the value of the
567 /// macro `EDOM` is stored into `errno`.
568 /// * If the result of the rounding is outside the range of the return
569 /// type, the macro `EDOM` is stored into `errno`.
570 ///
571 /// Examples: `lround(0.5)` ==> 1.0; `lround(-0.5)` ==> -1.0
572 static long int lround(Decimal32 x);
573 static long int lround(Decimal64 x);
574 static long int lround(Decimal128 x);
575
576 /// Return the specified `x` value rounded to the specified `precision`
577 /// decimal places. Round halfway cases away from zero, regardless of
578 /// the current decimal floating point rounding mode. If `x` is
579 /// integral, positive zero, negative zero, NaN, or infinity then return
580 /// `x` itself.
581 ///
582 /// Examples: `round(3.14159, 3)` ==> 3.142
583 static Decimal32 round(Decimal32 x, unsigned int precision);
584 static Decimal64 round(Decimal64 x, unsigned int precision);
585 static Decimal128 round(Decimal128 x, unsigned int precision);
586
587 /// Return the nearest integral value that is not greater in absolute
588 /// value than the specified `x`.
589 ///
590 /// Special value handling:
591 /// * if `x` is quiet NaN, quiet NaN is returned.
592 /// * If `x` is signaling NaN, quiet NaN is returned and the value of
593 /// the macro `EDOM` is stored into `errno`.
594 /// * if `x` is +/-infinity or +/-0, it is returned unmodified.
595 ///
596 /// Examples: `trunc(0.5)` ==> 0.0; `trunc(-0.5)` ==> 0.0
597 static Decimal32 trunc(Decimal32 x);
598 static Decimal64 trunc(Decimal64 x);
599 static Decimal128 trunc(Decimal128 x);
600
601 /// Return the specified `x` value truncated to the specified
602 /// `precision` decimal places. Round towards zero, regardless of the
603 /// current decimal floating point rounding mode. If precision of `x`
604 /// is less than or equal the `precision` or `x` is positive zero,
605 /// negative zero, NaN, or infinity then return `x` itself.
606 ///
607 /// Examples: `trunc(3.14159, 3)` ==> 3.141
608 static Decimal32 trunc(Decimal32 x, unsigned int precision);
609 static Decimal64 trunc(Decimal64 x, unsigned int precision);
610 static Decimal128 trunc(Decimal128 x, unsigned int precision);
611
612 // Quantum functions
613
614 /// Return the result of multiplying the specified `value` by ten raised
615 /// to the specified `exponent`. The quantum of `value` is scaled
616 /// according to IEEE 754's `scaleB` operations.
617 ///
618 /// Special value handling:
619 /// * If `value` is quiet NaN, quiet NaN is returned.
620 /// * If `value` is signaling NaN, quiet NaN is returned and the value
621 /// of the macro `EDOM` is stored into `errno`.
622 /// * If `x` is infinite, then infinity is returned.
623 /// * If a range error due to overflow occurs, infinity is returned and
624 ///: the value of the macro `ERANGE` is stored into `errno`.
626 int exponent);
628 int exponent);
630 int exponent);
631
632 /// Return a number equal to the specified `value` (except for possible
633 /// rounding) having the exponent equal to the exponent of the specified
634 /// `exponent`. Rounding may occur when the exponent is greater than
635 /// the quantum of `value`. E.g., `quantize(147e-2_d32, 1e-1_d32)`
636 /// yields `15e-1_d32`. In the opposite direction, if `exponent` is
637 /// sufficiently less than the quantum of `value`, it may not be
638 /// possible to construct the requested result, and if so, `NaN` is
639 /// returned. E.g., `quantize(1234567e0_d32, 1e-1_d32)` returns `NaN`.
640 static Decimal32 quantize(Decimal32 value, Decimal32 exponent);
641 static Decimal64 quantize(Decimal64 value, Decimal64 exponent);
642 static Decimal128 quantize(Decimal128 value, Decimal128 exponent);
643
644 /// Return a number equal to the specified `value` (except for possible
645 /// rounding) having the specified `exponent`. Rounding may occur when
646 /// `exponent` is greater than the quantum of `value`. E.g.,
647 /// `quantize(147e-2_d32, -1)` yields `15e-1_d32`. In the opposite
648 /// direction, if `exponent` is sufficiently less than the quantum of
649 /// `value`, it may not be possible to construct the requested result,
650 /// and if so, `NaN` is returned. E.g., `quantize(1234567e0_d32, -1)`
651 /// returns `NaN`. Behavior is undefined unless the `exponent`
652 /// satisfies the following conditions
653 /// * for `Decimal32` type: `-101 <= exponent <= 90`
654 /// * for `Decimal64` type: `-398 <= exponent <= 369`
655 /// * for `Decimal128` type: `-6176 <= exponent <= 6111`
656 static Decimal32 quantize(Decimal32 value, int exponent);
657 static Decimal64 quantize(Decimal64 value, int exponent);
658 static Decimal128 quantize(Decimal128 value, int exponent);
659
660 /// If a floating-point number equal to the specified `y` and having the
661 /// specified `exponent` can be constructed, set that value into the
662 /// specified `x` and return 0. Otherwise, or if `y` is NaN or
663 /// infinity, leave the contents of `x` unchanged and return a non-zero value.
664 ///
665 /// \pre The behavior is undefined unless `exponent` satisfies the
666 /// following conditions
667 /// * for `Decimal32` type: `-101 <= exponent <= 90`
668 /// * for `Decimal64` type: `-398 <= exponent <= 369`
669 /// * for `Decimal128` type: `-6176 <= exponent <= 6111`
670 ///
671 /// Example:
672 /// `Decimal32 x;`
673 /// `BSLS_ASSERT(0 == quantizeEqual(&x, 123e+3_d32, 2);`
674 /// `BSLS_ASSERT(1230e+2_d32 == x);`
675 /// `BSLS_ASSERT(0 != quantizeEqual(&x, 123e+3_d32, -2);`
676 /// `BSLS_ASSERT(1230e+2_d32 == x);`
677 static int quantizeEqual(Decimal32 *x, Decimal32 y, int exponent);
678 static int quantizeEqual(Decimal64 *x, Decimal64 y, int exponent);
679 static int quantizeEqual(Decimal128 *x, Decimal128 y, int exponent);
680
681 /// Return an integer equal to the exponent field in the specified
682 /// `value`. Each decimal floating point number is a representation of
683 /// the ideal form `s * (10 ** e)`, where `s` is significand and `e` is
684 /// exponent. This function returns that exponent value.
685 ///
686 /// \pre The behavior is undefined if `value` is NaN or `value` is infinity.
687 static int quantum(Decimal32 value);
688 static int quantum(Decimal64 value);
689 static int quantum(Decimal128 value);
690
691 /// Return `true` if the specified `x` and `y` values have the same
692 /// quantum exponents, and `false` otherwise. If both arguments are NaN
693 /// or both arguments are infinity, they have the same quantum exponents.
694 ///
695 /// \note Note that if exactly one operand is NaN or exactly one
696 /// operand is infinity, they do not have the same quantum exponents.
697 static bool sameQuantum(Decimal32 x, Decimal32 y);
698 static bool sameQuantum(Decimal64 x, Decimal64 y);
699 static bool sameQuantum(Decimal128 x, Decimal128 y);
700
701 // Decompose functions
702
703 /// Decompose the specified decimal `value` into the components of
704 /// the decimal floating-point format and load the result into the
705 /// specified `sign`, `significand` and `exponent` such that
706 /// `value` is equal to `sign * significand * (10 ** exponent)`.
707 /// The special values infinity and NaNs are decomposed to `sign`,
708 /// `exponent` and `significand` parts, even though they don't have
709 /// their normal meaning (except `sign`). That is those specific values
710 /// cannot be restored using these parts, unlike the finite ones.
711 /// Return the integer value that represents the floating point
712 /// classification of the specified `value` as follows:
713 ///
714 /// * if `value` is NaN, return FP_NAN;
715 /// * if `value` is infinity, return `FP_INFINITE`;
716 /// * if `value` is a subnormal value, return `FP_SUBNORMAL`;
717 /// * if `value` is a zero value, return `FP_ZERO`;
718 /// * otherwise return `FP_NORMAL`.
719 ///
720 ///
721 /// \note Note that a decomposed representation may not be unique,
722 /// for example 10 can be represented as either `10 * (10 ** 0)`
723 /// or `1 * (10 ** 1)`. The returned `significand` and `exponent`
724 /// reflect the encoded representation of `value` (i.e., they
725 /// reflect the `quantum` of `value`).
726 static int decompose(int *sign,
727 unsigned int *significand,
728 int *exponent,
729 Decimal32 value);
730 static int decompose(int *sign,
731 bsls::Types::Uint64 *significand,
732 int *exponent,
733 Decimal64 value);
734 static int decompose(int *sign,
735 Uint128 *significand,
736 int *exponent,
737 Decimal128 value);
738
739 // Format functions
740
741 /// Format the specified `value`, placing the output in the buffer
742 /// designated by the specified `buffer` and `length`, and return the
743 /// length of the formatted value. If there is insufficient room in the
744 /// buffer, its contents will be left in an unspecified state, with the
745 /// returned value indicating the necessary size. This function does not
746 /// write a terminating null character. If `length` is not positive,
747 /// `buffer` is permitted to be null. This can be used to determine the
748 /// necessary buffer size. Optionally specify a `cfg`, indicating
749 /// formatting parameters. If `cfg` is not specified, then default
750 /// configuration instance, indicating scientific notation style with a
751 /// precision sufficient to produce all available digits is used. See the
752 /// @ref bdldfp_decimalformatconfig-attributes section for information on
753 /// the configuration attributes.
754 ///
755 ///
756 /// \note Note that for some combinations of `value` and precision provided by
757 /// `cfg` object, the number being written must first be rounded to fewer
758 /// digits than it initially contains. The number written must be as close
759 /// as possible to the initial value given the constraints on precision.
760 /// The rounding should be done as "round-half-up", i.e., round up in
761 /// magnitude when the first of the discarded digits is between 5 and 9.
762 ///
763 /// Also note that if the configuration format attribute `style` is
764 /// `e_NATURAL` then all significand digits of the `value` are output in
765 /// the buffer regardless of the value specified in configuration's
766 /// `precision` attribute.
767 static
768 int format(char *buffer,
769 int length,
770 Decimal32 value,
772 static
773 int format(char *buffer,
774 int length,
775 Decimal64 value,
777 static
778 int format(char *buffer,
779 int length,
780 Decimal128 value,
782};
783
784 // =============================
785 // class DecimalUtil_CStringUtil
786 // =============================
787
788/// This component-private utility `struct` provides a namespace for the
789/// `flatten` overload set intended to be used in concert with an overload set
790/// consisting of a function template with a deduced argument and an
791/// non-template overload accepting a `const char *`. The actual
792/// implementation of the functionality would be in the `const char *` overload
793/// whereas the purpose of the function template is to invoke the `const char
794/// *` overload with a null-terminated string.
795///
796/// The function template achieves null-termination by recursively calling the
797/// function and supplying it with the result of `flatten` invoked on the
798/// deduced argument. This `flatten` invocation will call `c_str()` on various
799/// supported `string` types, will produce a temporary `bsl::string` for
800/// possibly non-null-terminated `bslstl::StringRef`, and will result in a
801/// `BSLMF_ASSERT` for any unsupported type. Calling the function with the
802/// temporary `bsl::string` produced from `bslstl::StringRef` will result in a
803/// second invocation of `flatten`, this time producing `const char *`, and
804/// finally calling the function with a null-terminated string.
805///
806///
807/// \note Note that the `bslstl::StringRef` overload for `flatten` is provided for
808/// backwards compatibility. Without it, the `bsl::string` and `std::string`
809/// overloads would be ambiguous. In new code, it is preferable to not provide
810/// `bslstl::StringRef` overload in a similar facility and require the clients
811/// to explicitly state the string type in their code, making a potential
812/// allocation obvious. The `bsl::string_view` overload is not provided for
813/// the same reason.
814///
815/// See @ref bdldfp_decimalutil
817
818 // CLASS METHODS
819
820 /// Return the specified `cString`.
821 static const char *flatten(const char *cString);
822 static const char *flatten(char *cString);
823
824 /// Return the result of invoking 'c_str()' on the specified 'string'.
825 static const char *flatten(const bsl::string& string);
826 static const char *flatten(const std::string& string);
827#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
828 static const char *flatten(const std::pmr::string& string);
829#endif
830
831 /// Return a temporary `bsl::string` constructed from the specified
832 /// `stringRef`.
833 static bsl::string flatten(const bslstl::StringRef& stringRef);
834
835 /// Produce a compile-time error informing the caller that the
836 /// parameterized `TYPE` is not supported as the parameter for the call.
837 template <class TYPE>
838 static const char *flatten(const TYPE&);
839};
840
841// ============================================================================
842// INLINE FUNCTION DEFINITIONS
843// ============================================================================
844
845 // -----------------
846 // class DecimalUtil
847 // -----------------
848
849// CLASS METHODS
850inline
851Decimal32 DecimalUtil::makeDecimalRaw32(int significand, int exponent)
852{
853 return DecimalImpUtil::makeDecimalRaw32(significand, exponent);
854}
855inline
856Decimal64 DecimalUtil::makeDecimalRaw64(int significand, int exponent)
857{
858 return DecimalImpUtil::makeDecimalRaw64(significand, exponent);
859}
860inline
861Decimal64 DecimalUtil::makeDecimalRaw64(unsigned int significand, int exponent)
862{
863 return DecimalImpUtil::makeDecimalRaw64(significand, exponent);
864}
865inline
866Decimal64 DecimalUtil::makeDecimalRaw64(long long significand, int exponent)
867{
868 return DecimalImpUtil::makeDecimalRaw64(significand, exponent);
869}
870inline
872DecimalUtil::makeDecimalRaw64(unsigned long long significand, int exponent)
873{
874 return DecimalImpUtil::makeDecimalRaw64(significand, exponent);
875}
876inline
877Decimal128 DecimalUtil::makeDecimalRaw128(int significand, int exponent)
878{
879 return DecimalImpUtil::makeDecimalRaw128(significand, exponent);
880}
881inline
883 int exponent)
884{
885 return DecimalImpUtil::makeDecimalRaw128(significand, exponent);
886}
887inline
888Decimal128 DecimalUtil::makeDecimalRaw128(long long significand, int exponent)
889{
890 return DecimalImpUtil::makeDecimalRaw128(significand, exponent);
891}
892inline
894DecimalUtil::makeDecimalRaw128(unsigned long long significand, int exponent)
895{
896 return DecimalImpUtil::makeDecimalRaw128(significand, exponent);
897}
898
899inline
900Decimal64 DecimalUtil::makeDecimal64(int significand, int exponent)
901{
902 return DecimalImpUtil::makeDecimal64(significand, exponent);
903}
904inline
905Decimal64 DecimalUtil::makeDecimal64(unsigned int significand, int exponent)
906{
907 return DecimalImpUtil::makeDecimal64(significand, exponent);
908}
909inline
910Decimal64 DecimalUtil::makeDecimal64(long long significand, int exponent)
911{
912 return DecimalImpUtil::makeDecimal64(significand, exponent);
913}
914inline
915Decimal64 DecimalUtil::makeDecimal64(unsigned long long significand,
916 int exponent)
917{
918 return DecimalImpUtil::makeDecimal64(significand, exponent);
919}
920
921template <class STRING_TYPE>
922inline
923int DecimalUtil::parseDecimal32(Decimal32 *out, const STRING_TYPE& str)
924{
927}
928
929template <class STRING_TYPE>
930inline
931int DecimalUtil::parseDecimal64(Decimal64 *out, const STRING_TYPE& str)
932{
935}
936
937template <class STRING_TYPE>
938inline
939int DecimalUtil::parseDecimal128(Decimal128 *out, const STRING_TYPE& str)
940{
943}
944
945template <class STRING_TYPE>
946inline
947int DecimalUtil::parseDecimal32Exact(Decimal32 *out, const STRING_TYPE& str)
948{
950 out,
952}
953
954template <class STRING_TYPE>
955inline
956int DecimalUtil::parseDecimal64Exact(Decimal64 *out, const STRING_TYPE& str)
957{
959 out,
961}
962
963template <class STRING_TYPE>
964inline
965int DecimalUtil::parseDecimal128Exact(Decimal128 *out, const STRING_TYPE& str)
966{
968 out,
970}
971
972 // Quantum functions
973
974inline
976{
977 return bdldfp::DecimalImpUtil::scaleB(*value.data(), exponent);
978}
979
980inline
982{
983 return bdldfp::DecimalImpUtil::scaleB(*value.data(), exponent);
984}
985
986inline
988{
989 return bdldfp::DecimalImpUtil::scaleB(*value.data(), exponent);
990}
991
992inline
994{
995 return DecimalImpUtil::quantize(*value.data(), *exponent.data());
996}
997
998inline
1000{
1001 return DecimalImpUtil::quantize(*value.data(), *exponent.data());
1002}
1003
1004inline
1006{
1007 return DecimalImpUtil::quantize(*value.data(), *exponent.data());
1008}
1009
1010inline
1012{
1013 BSLS_ASSERT(-101 <= exponent);
1014 BSLS_ASSERT( exponent <= 90);
1015 return DecimalImpUtil::quantize(*value.data(), exponent);
1016}
1017
1018inline
1020{
1021 BSLS_ASSERT(-398 <= exponent);
1022 BSLS_ASSERT( exponent <= 369);
1023 return DecimalImpUtil::quantize(*value.data(), exponent);
1024}
1025
1026inline
1028{
1029 BSLS_ASSERT(-6176 <= exponent);
1030 BSLS_ASSERT( exponent <= 6111);
1031 return DecimalImpUtil::quantize(*value.data(), exponent);
1032}
1033
1034inline
1036{
1037 BSLS_ASSERT(x);
1038 BSLS_ASSERT(-101 <= exponent);
1039 BSLS_ASSERT( exponent <= 90);
1040 return DecimalImpUtil::quantizeEqual(x->data(), *y.data(), exponent);
1041}
1042
1043inline
1045{
1046 BSLS_ASSERT(x);
1047 BSLS_ASSERT(-398 <= exponent);
1048 BSLS_ASSERT( exponent <= 369);
1049 return DecimalImpUtil::quantizeEqual(x->data(), *y.data(), exponent);
1050}
1051
1052inline
1054{
1055 BSLS_ASSERT(x);
1056 BSLS_ASSERT(-6176 <= exponent);
1057 BSLS_ASSERT( exponent <= 6111);
1058 return DecimalImpUtil::quantizeEqual(x->data(), *y.data(), exponent);
1059}
1060
1061inline
1066
1067inline
1072
1073inline
1078
1079inline
1084
1085inline
1090
1091inline
1096
1097inline
1102
1103inline
1108
1109inline
1114
1115inline
1120
1121inline
1126
1127inline
1132
1133inline
1138
1139inline
1144
1145inline
1150
1151inline
1156
1157inline
1162
1163inline
1168
1169inline
1174
1175inline
1180
1181inline
1186
1187inline
1192
1193inline
1198
1199inline
1204
1205inline
1207{
1209}
1210
1211inline
1213{
1215}
1216
1217inline
1219{
1221}
1222
1223inline
1225{
1227}
1228
1229inline
1231{
1233}
1234
1235inline
1237{
1239}
1240
1241inline
1246
1247inline
1252
1253inline
1258
1259inline
1264
1265inline
1270
1271inline
1276
1277inline
1282
1283inline
1288
1289inline
1294
1295inline
1300
1301inline
1306
1307inline
1312
1313inline
1318
1319inline
1324
1325inline
1330
1331inline
1336
1337inline
1342
1343inline
1348
1349inline
1351{
1353}
1354
1355inline
1357{
1359}
1360
1361inline
1363{
1365}
1366
1367inline
1368Decimal32 DecimalUtil::round(Decimal32 x, unsigned int decimalPlaces)
1369{
1370 return bdldfp::DecimalImpUtil::round(*x.data(), decimalPlaces);
1371}
1372
1373inline
1374Decimal64 DecimalUtil::round(Decimal64 x, unsigned int decimalPlaces)
1375{
1376 return bdldfp::DecimalImpUtil::round(*x.data(), decimalPlaces);
1377}
1378
1379inline
1380Decimal128 DecimalUtil::round(Decimal128 x, unsigned int decimalPlaces)
1381{
1382 return bdldfp::DecimalImpUtil::round(*x.data(), decimalPlaces);
1383}
1384
1385inline
1390
1391inline
1396
1397inline
1402
1403inline
1408
1409inline
1414
1415inline
1420
1421inline
1426
1427inline
1432
1433inline
1438
1439inline
1444
1445inline
1450
1451inline
1456
1457 // -----------------------------
1458 // class DecimalUtil_CStringUtil
1459 // -----------------------------
1460
1461// CLASS METHODS
1462inline
1463const char *DecimalUtil_CStringUtil::flatten(const char *cString)
1464{
1465 return cString;
1466}
1467
1468inline
1469const char *DecimalUtil_CStringUtil::flatten(char *cString)
1470{
1471 return cString;
1472}
1473
1474inline
1476{
1477 return string.c_str();
1478}
1479
1480inline
1481const char *DecimalUtil_CStringUtil::flatten(const std::string& string)
1482{
1483 return string.c_str();
1484}
1485
1486#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1487inline
1488const char *DecimalUtil_CStringUtil::flatten(const std::pmr::string& string)
1489{
1490 return string.c_str();
1491}
1492#endif
1493
1494inline
1496 const bslstl::StringRef& stringRef)
1497{
1498 return stringRef;
1499}
1500
1501template <class TYPE>
1502inline
1503const char *DecimalUtil_CStringUtil::flatten(const TYPE&)
1504{
1505 BSLMF_ASSERT(("Unsupported parameter type." && !sizeof(TYPE)));
1506 return 0;
1507}
1508
1509} // close package namespace
1510
1511
1512#endif
1513
1514// ----------------------------------------------------------------------------
1515// Copyright 2014 Bloomberg Finance L.P.
1516//
1517// Licensed under the Apache License, Version 2.0 (the "License");
1518// you may not use this file except in compliance with the License.
1519// You may obtain a copy of the License at
1520//
1521// http://www.apache.org/licenses/LICENSE-2.0
1522//
1523// Unless required by applicable law or agreed to in writing, software
1524// distributed under the License is distributed on an "AS IS" BASIS,
1525// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1526// See the License for the specific language governing permissions and
1527// limitations under the License.
1528// ----------------------------- END-OF-FILE ----------------------------------
1529
1530/** @} */
1531/** @} */
1532/** @} */
Definition bdldfp_decimalformatconfig.h:120
static ValueType32 remainder(ValueType32 x, ValueType32 y)
Definition bdldfp_decimalimputil.h:2645
static ValueType32 trunc(ValueType32 x)
Definition bdldfp_decimalimputil.h:2265
static ValueType32 log(ValueType32 x)
Definition bdldfp_decimalimputil.h:2471
static ValueType128 makeDecimalRaw128(unsigned long long int significand, int exponent)
static ValueType32 fma(ValueType32 x, ValueType32 y, ValueType32 z)
Definition bdldfp_decimalimputil.h:2302
static ValueType32 scaleB(ValueType32 value, int exponent)
Definition bdldfp_decimalimputil.h:3051
static ValueType32 pow(ValueType32 base, ValueType32 exp)
Definition bdldfp_decimalimputil.h:2066
static long long int llrint(ValueType32 x)
Definition bdldfp_decimalimputil.h:1924
static ValueType32 floor(ValueType32 x)
Definition bdldfp_decimalimputil.h:2160
static ValueType32 copySign(ValueType32 x, ValueType32 y)
Definition bdldfp_decimalimputil.h:2399
static ValueType32 round(ValueType32 x)
Definition bdldfp_decimalimputil.h:2196
static ValueType32 fabs(ValueType32 x)
Definition bdldfp_decimalimputil.h:2339
static ValueType32 fmod(ValueType32 x, ValueType32 y)
Definition bdldfp_decimalimputil.h:2606
static ValueType32 log10(ValueType32 x)
Definition bdldfp_decimalimputil.h:2561
static ValueType32 makeDecimalRaw32(int significand, int exponent)
Definition bdldfp_decimalimputil.h:2956
static ValueType32 logB(ValueType32 x)
Definition bdldfp_decimalimputil.h:2516
static ValueType64 makeDecimal64(int significand, int exponent)
static long int lround(ValueType32 x)
Definition bdldfp_decimalimputil.h:2232
static ValueType32 quantize(ValueType32 value, ValueType32 exponent)
Definition bdldfp_decimalimputil.h:1727
static ValueType32 sqrt(ValueType32 x)
Definition bdldfp_decimalimputil.h:2363
static int quantizeEqual(ValueType32 *x, ValueType32 y, int exponent)
Definition bdldfp_decimalimputil.h:1811
static ValueType64 makeDecimalRaw64(unsigned long long int significand, int exponent)
static ValueType32 nexttoward(ValueType32 from, ValueType128 to)
Definition bdldfp_decimalimputil.h:2012
static ValueType32 nextafter(ValueType32 from, ValueType32 to)
Definition bdldfp_decimalimputil.h:1958
static ValueType32 exp(ValueType32 x)
Definition bdldfp_decimalimputil.h:2426
static long int lrint(ValueType32 x)
Definition bdldfp_decimalimputil.h:1891
static bool sameQuantum(ValueType32 x, ValueType32 y)
Definition bdldfp_decimalimputil.h:1870
static ValueType32 ceil(ValueType32 x)
Definition bdldfp_decimalimputil.h:2123
Definition bdldfp_decimal.h:3101
DecimalImpUtil::ValueType128 * data()
Return a modifiable pointer to the underlying implementation.
Definition bdldfp_decimal.h:6792
Definition bdldfp_decimal.h:765
DecimalImpUtil::ValueType32 * data()
Definition bdldfp_decimal.h:6030
Definition bdldfp_decimal.h:1890
DecimalImpUtil::ValueType64 * data()
Return a modifiable pointer to the underlying implementation.
Definition bdldfp_decimal.h:6425
Definition bdldfp_uint128.h:175
Definition bslstl_string.h:1252
Definition bslstl_stringref.h:374
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:231
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdldfp_decimal.h:747
Definition bdldfp_decimalutil.h:816
static const char * flatten(const char *cString)
Return the specified cString.
Definition bdldfp_decimalutil.h:1463
Definition bdldfp_decimalutil.h:138
static Decimal32 fabs(Decimal32 value)
Definition bdldfp_decimalutil.h:1422
static int classify(Decimal128 x)
static bool isNan(Decimal64 x)
static long int lround(Decimal32 x)
Definition bdldfp_decimalutil.h:1350
static int quantum(Decimal128 value)
static Decimal32 logB(Decimal32 x)
Definition bdldfp_decimalutil.h:1134
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:1440
static bool isNan(Decimal32 x)
static Decimal32 multiplyByPowerOf10(Decimal32 value, int exponent)
Definition bdldfp_decimalutil.h:975
static Decimal32 exp(Decimal32 x)
Definition bdldfp_decimalutil.h:1098
static int decompose(int *sign, unsigned int *significand, int *exponent, Decimal32 value)
static Decimal128 trunc(Decimal128 x, unsigned int precision)
static int parseDecimal128Exact(Decimal128 *out, const char *str)
static bool isUnordered(Decimal32 x, Decimal32 y)
static Decimal32 log(Decimal32 x)
Definition bdldfp_decimalutil.h:1116
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:851
static int quantum(Decimal64 value)
static Decimal128 makeDecimalRaw128(int significand, int exponent)
Definition bdldfp_decimalutil.h:877
static int parseDecimal32Exact(Decimal32 *out, const char *str)
static int classify(Decimal64 x)
static Decimal32 quantize(Decimal32 value, Decimal32 exponent)
Definition bdldfp_decimalutil.h:993
static bool isFinite(Decimal64 x)
static long long int llrint(Decimal32 x)
Definition bdldfp_decimalutil.h:1224
static Decimal32 ceil(Decimal32 x)
Definition bdldfp_decimalutil.h:1296
static int quantizeEqual(Decimal32 *x, Decimal32 y, int exponent)
Definition bdldfp_decimalutil.h:1035
static int parseDecimal32(Decimal32 *out, const char *str)
static Decimal64 makeDecimalRaw64(int significand, int exponent)
Definition bdldfp_decimalutil.h:856
static Decimal32 round(Decimal32 x)
Definition bdldfp_decimalutil.h:1332
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:1404
static int quantum(Decimal32 value)
static Decimal64 makeDecimal64(int significand, int exponent)
Definition bdldfp_decimalutil.h:900
static bool isFinite(Decimal128 x)
static int parseDecimal64Exact(Decimal64 *out, const char *str)
static Decimal32 trunc(Decimal32 x)
Definition bdldfp_decimalutil.h:1386
static bool isFinite(Decimal32 x)
static long int lrint(Decimal32 x)
Definition bdldfp_decimalutil.h:1206
static bool isInf(Decimal32 x)
static Decimal32 copySign(Decimal32 x, Decimal32 y)
Definition bdldfp_decimalutil.h:1080
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:1152
static Decimal32 pow(Decimal32 base, Decimal32 exp)
Definition bdldfp_decimalutil.h:1278
static Decimal32 fmod(Decimal32 x, Decimal32 y)
Definition bdldfp_decimalutil.h:1170
static bool sameQuantum(Decimal32 x, Decimal32 y)
Definition bdldfp_decimalutil.h:1062
static Decimal32 nextafter(Decimal32 from, Decimal32 to)
Definition bdldfp_decimalutil.h:1242
static Decimal32 floor(Decimal32 x)
Definition bdldfp_decimalutil.h:1314
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:1188
static Decimal32 nexttoward(Decimal32 from, Decimal128 to)
Definition bdldfp_decimalutil.h:1260
static int parseDecimal128(Decimal128 *out, const char *str)
unsigned long long Uint64
Definition bsls_types.h:139