Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bdldfp_decimalutil
[Package bdldfp]

Provide utilities dealing with floating point decimal objects. More...

Namespaces

namespace  bdldfp

Detailed Description

Outline
Purpose:
Provide utilities dealing with floating point decimal objects.
Classes:
bdldfp::DecimalUtil decimal floating point utility functions.
Macros:
FP_SUBNORMAL subnormal floating-point classification identifier constant
FP_NORMAL normal floating-point classification identifier constant
FP_ZERO zero floating-point classification identifier constant
FP_INFINITE infinity floating-point classification identifier constant
FP_NAN NaN floating-point classification identifier constant
Note that these macros may not be defined in this header. They are C99 standard macros and this component defines them only for those platforms that have failed to implement C99 (such as Microsoft).
See also:
Component bdldfp_decimal, Component bdldfp_decimalplatform
Description:
The bdldfp::DecimalUtil component provides utility functions for the decimal floating-point types defined in bdldfp_decimal:
  • FP_XXX, C99 standard floating-point classification macros
  • the makeDecimal functions building a decimal floating-point value out of a coefficient and exponent.
  • the parseDecimal functions that convert text to decimal value.
  • fma, fabs, ceil, floor, trunc, round - math functions
  • classify and the isXxxx floating-point value classification functions
The FP_XXX C99 floating-point classification macros may also be provided by this header for platforms where C99 support is still not provided.
Usage:
This section shows the intended use of this component.
Example 1: Building Decimals From Integer Parts:
Floating-point numbers are built from a sign, a significand and an exponent. All those 3 are integers (of various sizes), therefore it is possible to build decimals from integers:
  long long coefficient = 42; // Yet another name for significand
  int exponent          = -1;

  Decimal32  d32  = makeDecimal32( coefficient, exponent);
  Decimal64  d64  = makeDecimal64( coefficient, exponent);
  Decimal128 d128 = makeDecimal128(coefficient, exponent);

  assert(BDLDFP_DECIMAL_DF(4.2) == d32);
  assert(BDLDFP_DECIMAL_DD(4.2) == d64);
  assert(BDLDFP_DECIMAL_DL(4.2) == d128);