[#BloombergLP-bdljsn-NumberUtil] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdljsn.adoc[bdljsn]::NumberUtil :relfileprefix: ../../ :mrdocs: This `struct` provides a namespace for a suite of functions that convert between a JSON formated numeric value and various numerical types. The valid syntax for a JSON formatted numeric value is spelled out in `https://www.rfc‐editor.org/rfc/rfc8259#section‐6`. == Synopsis Declared in `<bdljsn_numberutil.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- struct NumberUtil; ---- == Type Aliases [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdljsn/NumberUtil/Int64.adoc[`Int64`] | This `typedef` is an alias to `bsls::Types::Int64`. | xref:BloombergLP/bdljsn/NumberUtil/Uint64.adoc[`Uint64`] | This `typedef` is an alias to `bsls::Types::Uint64`. |=== == Enums [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdljsn/NumberUtil/_04enum.adoc[`Unnamed enum`] | Special integer conversion status values. |=== == Static Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdljsn/NumberUtil/areEqual.adoc[`areEqual`] | Return `true` if the specified `lhs` and `rhs` represent the same numeric value, and `false` otherwise. This function will return `true` for differing representations of the same number (e.g., `1.0`, "1", "0.1e+1" are all equivalent) _except_ in cases where the exponent cannot be represented by a 64‐bit integer. If the exponent is outside the range of a 64‐bit integer, `true` will be returned if `lhs == rhs`. For example, comparing "1e18446744073709551615" with itself will return `true`, but comparing it to "10e18446744073709551614" will return `false`. The behavior is undefined unless `isValidNumber(lhs)` and `isValidNumber(rhs)`. | xref:BloombergLP/bdljsn/NumberUtil/asDecimal64.adoc[`asDecimal64`] | Return the closest floating point representation to the specified `value`. If `value` is outside the representable range, return +INF or ‐INF (as appropriate). The behavior is undefined unless `isValidNumber(value)` is `true`. | xref:BloombergLP/bdljsn/NumberUtil/asDecimal64Exact.adoc[`asDecimal64Exact`] | Load the specified `result` with the specified `value`, even if a non‐zero status is returned. Return 0 if `value` can be represented exactly, and return `k_INEXACT` and load `result` with the closest approximation of `value` if `value` cannot be represented exactly. A `value` can be represented exactly as a `Decimal64` if, for the significand and exponent of `value`, `abs(significand) <= 9,999,999,999,999,999` and `‐398 <= exponent <= 369`. The behavior is undefined unless `isValidNumber(value)` is `true`. | xref:BloombergLP/bdljsn/NumberUtil/asDouble.adoc[`asDouble`] | Same as the related overload above for `asDouble`. | xref:BloombergLP/bdljsn/NumberUtil/asFloat.adoc[`asFloat`] | Return the closest floating point representation to the specified `value`. If `value` is outside the representable range, return +INF or ‐INF (as appropriate). The behavior is undefined unless `isValidNumber(value)` is `true`. | xref:BloombergLP/bdljsn/NumberUtil/asInt.adoc[`asInt`] | Same as the related overload above for `asInt`. | xref:BloombergLP/bdljsn/NumberUtil/asInt64.adoc[`asInt64`] | Same as the related overload above for `asInt64`. | xref:BloombergLP/bdljsn/NumberUtil/asInteger.adoc[`asInteger`] | Load into the specified `result` (of the template parameter type `t_INTEGER_TYPE`) with the specified `value`, even if a non‐zero status is returned (truncating fractional digits if necessary). Return 0 on success, `k_OVERFLOW` if `value` is larger than can be represented by `result`, `k_UNDERFLOW` if `value` is smaller than can be represented by `result`, and `k_NOT_INTEGRAL` if `value` is not an integral number (i.e., there is a fractional part). For underflow, `result` will be loaded with the minimum representable value, for overflow, `result` will be loaded with the maximum representable value, for non‐integral values `result` will be loaded with the integer part of `value` (truncating the value to the nearest integer). If the result is not an integer and also either overflows or underflows, it is treated as an overflow or underflow (respectively). The (template parameter) `t_INTEGER_TYPE` shall be either a signed or unsigned integer type (that is not `bool`) where `sizeof(t_INTEGER_TYPE) <= 8`. The behavior is undefined unless `isValidNumber(value)` is `true`. Note that this operation will correctly handle exponents (e.g., a `value` of "0.00000000000000000001e20" will produce a `result` of 1). | xref:BloombergLP/bdljsn/NumberUtil/asLong.adoc[`asLong`] | Same as the related overload above for `asLong`. | xref:BloombergLP/bdljsn/NumberUtil/asLonglong.adoc[`asLonglong`] | Same as the related overload above for `asLonglong`. | xref:BloombergLP/bdljsn/NumberUtil/asShort.adoc[`asShort`] | Load the specified `result` with the specified `value`, even if a non‐zero status is returned (truncating fractional digits if necessary). Return 0 on success, `k_OVERFLOW` if `value` is larger than can be represented by `result`, `k_UNDERFLOW` if `value` is smaller than can be represented by `result`, and `k_NOT_INTEGRAL` if `value` is not an integral number (i.e., there is a fractional part). For underflow, `result` will be loaded with the minimum representable value, for overflow, `result` will be loaded with the maximum representable value, for non‐integral values `result` will be loaded with the integer part of `value` (truncating the fractional part of `value`). The behavior is undefined unless `isValidNumber(value)` is `true`. Note that this operation will correctly handle exponents (e.g., a `value` of "0.00000000000000000001e20" will produce a `result` of 1). | xref:BloombergLP/bdljsn/NumberUtil/asUint.adoc[`asUint`] | Same as the related overload above for `asUint`. | xref:BloombergLP/bdljsn/NumberUtil/asUint64.adoc[`asUint64`] | Same as the related overload above for `asUint64`. | xref:BloombergLP/bdljsn/NumberUtil/asUlong.adoc[`asUlong`] | Load the specified `result` with the specified `value`, even if a non‐zero status is returned (truncating fractional digits if necessary). Return 0 on success, `k_OVERFLOW` if `value` is larger than can be represented by `result`, `k_UNDERFLOW` if `value` is smaller than can be represented by `result`, and `k_NOT_INTEGRAL` if `value` is not an integral number (i.e., there is a fractional part). The behavior is undefined unless `isValidNumber(value)` is `true`. | xref:BloombergLP/bdljsn/NumberUtil/asUlonglong.adoc[`asUlonglong`] | Same as the related overload above for `asUlonglong`. | xref:BloombergLP/bdljsn/NumberUtil/asUshort.adoc[`asUshort`] | Same as the related overload above for `asUshort`. | xref:BloombergLP/bdljsn/NumberUtil/isIntegralNumber.adoc[`isIntegralNumber`] | Return `true` if the specified `value` is a valid integral JSON number. Note that this function may return `true` even if `value` cannot be represented in a fundamental integral type. The behavior is undefined unless `isValidNumber(value)` is `true`. | xref:BloombergLP/bdljsn/NumberUtil/isValidNumber.adoc[`isValidNumber`] | Return `true` if the specified `value` is a valid JSON number. Note that this function may return `true` even if `value` cannot be represented in any particular number type. | xref:BloombergLP/bdljsn/NumberUtil/stringify-0c.adoc[`stringify`] | `stringify` overloads |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#