|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Exact locale-free conversion for legacy decimal state values. More...
Go to the source code of this file.
Data Structures | |
| struct | mdl_state_big_t |
| Little-endian base-2^32 unsigned integer. More... | |
Enumerations | |
| enum | mdl_state_big_limit_t : uint8_t { k_state_big_words = 48 } |
| Fixed storage is sufficient for 17 digits multiplied or divided by 10^400. More... | |
| enum | mdl_state_decimal_limit_t : int32_t { k_state_decimal_prime = 5 , k_state_decimal_scale_max = 400 , k_state_divide_bits = 64 , k_state_binary64_fraction_bits = 52 , k_state_binary64_precision_bits = 53 , k_state_binary64_sign_shift = 63 , k_state_binary64_exponent_bias = 1023 , k_state_binary64_exponent_max = 1023 , k_state_binary64_exponent_min = -1022 , k_state_binary64_subnormal_scale = 1074 } |
| Exact decimal and binary64 representation constants. More... | |
Functions | |
| static void | internal_mdl_state_big_init (mdl_state_big_t *big, uint64_t value) |
| Initialize a fixed integer from one uint64 value. | |
| static void | internal_mdl_state_big_trim (mdl_state_big_t *big) |
| Remove unused high words while retaining one zero word. | |
| static uint16_t | internal_mdl_state_big_bits (const mdl_state_big_t *big) |
| Return the significant bit count of a fixed integer. | |
| static bool | internal_mdl_state_big_mul (mdl_state_big_t *big, uint32_t factor) |
| Multiply a fixed integer by one small factor. | |
| static bool | internal_mdl_state_big_shift (const mdl_state_big_t *src, uint16_t shift, mdl_state_big_t *dst) |
| Copy one fixed integer shifted left by an exact bit count. | |
| static int | internal_mdl_state_big_compare (const mdl_state_big_t *lhs, const mdl_state_big_t *rhs) |
| Compare two normalized fixed integers. | |
| static void | internal_mdl_state_big_subtract (mdl_state_big_t *lhs, const mdl_state_big_t *rhs) |
| Subtract a no-larger fixed integer from another. | |
| static int | internal_mdl_state_compare_power (const mdl_state_big_t *numerator, const mdl_state_big_t *denominator, int32_t binary_scale, int32_t exponent) |
| Compare a scaled rational against one exact power of two. | |
| static bool | internal_mdl_state_divide (const mdl_state_big_t *numerator, const mdl_state_big_t *denominator, int32_t binary_shift, uint64_t *out) |
| Divide one scaled rational and round to nearest-even. | |
| static bool | internal_mdl_state_build_rational (uint64_t mantissa, int32_t decimal_scale, mdl_state_big_t *numerator, mdl_state_big_t *denominator) |
| Build the odd rational factors for a decimal value. | |
| static bool | internal_mdl_state_encode (uint64_t quotient, int32_t exponent, bool negative, bool normal, double *out) |
| Encode one rounded quotient as finite binary64. | |
| bool | priv_mdl_state_decimal_to_binary64 (uint64_t mantissa, int32_t decimal_scale, bool negative, double *out) |
| Convert one exact bounded decimal rational to binary64. | |
Exact locale-free conversion for legacy decimal state values.
Uses fixed-capacity integers to round bounded schema-v2 decimals to binary64.
Definition in file mdl_state_decimal.c.
| enum mdl_state_big_limit_t : uint8_t |
Fixed storage is sufficient for 17 digits multiplied or divided by 10^400.
| Enumerator | |
|---|---|
| k_state_big_words | Capacity of one fixed unsigned integer. |
Definition at line 15 of file mdl_state_decimal.c.
| enum mdl_state_decimal_limit_t : int32_t |
Exact decimal and binary64 representation constants.
Definition at line 20 of file mdl_state_decimal.c.
|
static |
Return the significant bit count of a fixed integer.
| [in] | big | Normalized integer. |
| 0 | The integer is zero. |
big is non-NULL. Definition at line 75 of file mdl_state_decimal.c.
References RA8_INTERNAL, mdl_state_big_t::used, and mdl_state_big_t::word.
Referenced by internal_mdl_state_divide(), and priv_mdl_state_decimal_to_binary64().
|
static |
Compare two normalized fixed integers.
| [in] | lhs | Left operand. |
| [in] | rhs | Right operand. |
| 0 | Magnitudes are equal. |
Definition at line 152 of file mdl_state_decimal.c.
References RA8_INTERNAL, mdl_state_big_t::used, and mdl_state_big_t::word.
Referenced by internal_mdl_state_compare_power(), and internal_mdl_state_divide().
|
static |
Initialize a fixed integer from one uint64 value.
| [out] | big | Destination integer. |
| [in] | value | Initial magnitude. |
big is non-NULL. Definition at line 46 of file mdl_state_decimal.c.
References memset(), RA8_INTERNAL, mdl_state_big_t::used, and mdl_state_big_t::word.
Referenced by internal_mdl_state_build_rational().
|
static |
Multiply a fixed integer by one small factor.
| [in,out] | big | Integer operand. |
| [in] | factor | Small multiplier. |
| false | The product exceeds fixed storage. |
big is non-NULL. Definition at line 96 of file mdl_state_decimal.c.
References k_state_big_words, RA8_INTERNAL, mdl_state_big_t::used, and mdl_state_big_t::word.
Referenced by internal_mdl_state_build_rational().
|
static |
Copy one fixed integer shifted left by an exact bit count.
| [in] | src | Source integer. |
| [in] | shift | Bit count. |
| [out] | dst | Destination. |
| false | The shifted value does not fit. |
Definition at line 122 of file mdl_state_decimal.c.
References internal_mdl_state_big_trim(), k_state_big_words, memset(), mdl_state_big_t::used, and mdl_state_big_t::word.
Referenced by internal_mdl_state_compare_power(), and internal_mdl_state_divide().
|
static |
Subtract a no-larger fixed integer from another.
| [in,out] | lhs | Minuend and result. |
| [in] | rhs | Subtrahend. |
lhs is at least rhs. lhs stores the exact normalized difference. rhs is unchanged. Definition at line 173 of file mdl_state_decimal.c.
References internal_mdl_state_big_trim(), RA8_INTERNAL, mdl_state_big_t::used, and mdl_state_big_t::word.
Referenced by internal_mdl_state_divide().
|
static |
Remove unused high words while retaining one zero word.
| [in,out] | big | Integer to normalize. |
big is non-NULL. Definition at line 61 of file mdl_state_decimal.c.
References RA8_INTERNAL, mdl_state_big_t::used, and mdl_state_big_t::word.
Referenced by internal_mdl_state_big_shift(), and internal_mdl_state_big_subtract().
|
static |
Build the odd rational factors for a decimal value.
| [in] | mantissa | Decimal significand. |
| [in] | decimal_scale | Signed power of ten. |
| [out] | numerator | Numerator factor. |
| [out] | denominator | Denominator factor. |
| false | A factor exceeds fixed storage. |
Definition at line 272 of file mdl_state_decimal.c.
References internal_mdl_state_big_init(), internal_mdl_state_big_mul(), k_state_decimal_prime, and RA8_INTERNAL.
Referenced by priv_mdl_state_decimal_to_binary64().
|
static |
Compare a scaled rational against one exact power of two.
| [in] | numerator | Rational numerator. |
| [in] | denominator | Rational denominator. |
| [in] | binary_scale | Numerator power-of-two scale. |
| [in] | exponent | Compared exponent. |
| 0 | Values are equal. |
Definition at line 193 of file mdl_state_decimal.c.
References internal_mdl_state_big_compare(), internal_mdl_state_big_shift(), and RA8_INTERNAL.
Referenced by priv_mdl_state_decimal_to_binary64().
|
static |
Divide one scaled rational and round to nearest-even.
| [in] | numerator | Numerator. |
| [in] | denominator | Denominator. |
| [in] | binary_shift | Numerator binary scale. |
| [out] | out | Rounded quotient. |
| false | Intermediate or quotient width exceeds bounds. |
out exactly. Definition at line 219 of file mdl_state_decimal.c.
References internal_mdl_state_big_bits(), internal_mdl_state_big_compare(), internal_mdl_state_big_shift(), internal_mdl_state_big_subtract(), k_state_divide_bits, and RA8_INTERNAL.
Referenced by priv_mdl_state_decimal_to_binary64().
|
static |
Encode one rounded quotient as finite binary64.
| [in] | quotient | Rounded significand. |
| [in] | exponent | Unbiased exponent. |
| [in] | negative | Sign. |
| [in] | normal | Normal/subnormal selector. |
| [out] | out | Encoded value. |
| false | Overflow, underflow, or invalid quotient. |
out is non-NULL. Definition at line 296 of file mdl_state_decimal.c.
References k_state_binary64_exponent_bias, k_state_binary64_exponent_max, k_state_binary64_fraction_bits, k_state_binary64_precision_bits, k_state_binary64_sign_shift, memcpy(), and RA8_INTERNAL.
Referenced by priv_mdl_state_decimal_to_binary64().
| bool priv_mdl_state_decimal_to_binary64 | ( | uint64_t | mantissa, |
| int32_t | decimal_scale, | ||
| bool | negative, | ||
| double * | out ) |
Convert one exact bounded decimal rational to binary64.
Uses fixed-capacity integer division and nearest-even rounding without libc conversion.
| [in] | mantissa | Unsigned decimal significand (at most 17 digits). |
| [in] | decimal_scale | Signed power of ten applied to mantissa. |
| [in] | negative | Whether to set the binary64 sign bit. |
| [out] | out | Converted finite binary64 value. |
| false | Scale, capacity, overflow, or nonzero underflow is invalid. |
out is non-NULL and decimal_scale is in [-400, 400]. mantissa carries at most 17 decimal digits. Definition at line 330 of file mdl_state_decimal.c.
References internal_mdl_state_big_bits(), internal_mdl_state_build_rational(), internal_mdl_state_compare_power(), internal_mdl_state_divide(), internal_mdl_state_encode(), k_state_binary64_exponent_max, k_state_binary64_exponent_min, k_state_binary64_fraction_bits, k_state_binary64_sign_shift, k_state_binary64_subnormal_scale, k_state_decimal_scale_max, memcpy(), and RA8_PRIV.
Referenced by internal_mdl_state_parse_double_field().