MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
transformo — decimal to binary scaling

Data Structures

struct  TransformoCfg
 Arguments for the four muto calls. More...
struct  TransformoNs
 Type of the muto dispatch table. More...

Macros

#define MMGR_MUTO_MANT_MAX
 Expands to the largest mantissa mmgr_muto_take will extend, which is (~0 - 9) / 10.
#define MMGR_MUTO_EXP_LIMIT
 Expands to 400, the count at which a parsed decimal exponent stops its growth.

Functions

static EMBED_HOST_DEVICE unsigned int mmgr_muto_digit_value (uint8_t character)
 The value of an ASCII digit in a base up to 36.
EMBED_HOST_DEVICE embed_bool mmgr_muto_take (const TransformoCfg *args)
 Appends args->digit to *args->mant as one more decimal digit.
EMBED_HOST_DEVICE double mmgr_muto_scale (const TransformoCfg *args)
 Turns *args->mant times ten raised to args->ex into a double, signed by args->neg.
EMBED_HOST_DEVICE embed_u64 mmgr_muto_scale_to_u64 (const TransformoCfg *args)
 Turns *args->mant times two raised to args->e2 times ten raised to args->ex into a rounded 64-bit integer.
EMBED_HOST_DEVICE embed_bool mmgr_muto_take_in (const TransformoCfg *args)
 Appends args->digit to *args->mant as one more digit in base args->base.

Variables

static const TransformoNs muto
 Dispatch table instance named muto, with each member set to its mmgr_muto_ function.

Detailed Description

Macro Definition Documentation

◆ MMGR_MUTO_MANT_MAX

#define MMGR_MUTO_MANT_MAX

Expands to the largest mantissa mmgr_muto_take will extend, which is (~0 - 9) / 10.

Note
Chosen so a multiply by ten and an add of a digit of nine both stay inside an embed_u64.
mmgr_muto_take returns EMBED_FALSE and appends nothing once the mantissa passes this.
Explicit casts hold both the complement and the result at embed_u64, and the 9u and 10u match that width. So the subtraction and the divide run at the mantissa's own width and not at int's.

Definition at line 37 of file transformo.h.

◆ MMGR_MUTO_EXP_LIMIT

#define MMGR_MUTO_EXP_LIMIT

Expands to 400, the count at which a parsed decimal exponent stops its growth.

Note
cellul_expo tests its running exponent against this before each multiply and add. A long run of digits cannot run the count away with the embed_iword that holds it.
400 is past the 308 a double reaches. Anything the clamp holds back has already gone to a signed infinity or a signed zero. An early stop of the count cannot change the result.
The literal is a plain number, as the embed_iword exponent it compares against.

Definition at line 48 of file transformo.h.

Function Documentation

◆ mmgr_muto_digit_value()

EMBED_HOST_DEVICE unsigned int mmgr_muto_digit_value ( uint8_t character)
inlinestatic

The value of an ASCII digit in a base up to 36.

Parameters
[in]characterThe byte.
Returns
0 to 9 for '0' to '9', 10 to 35 for a letter of either case, and 36 for any other byte.
Note
A value at or past the base says the byte is no digit of that base, and 36 is past every base.

Definition at line 91 of file transformo.h.

References mmgr_muto_digit_value().

Referenced by mmgr_muto_digit_value().

◆ mmgr_muto_take()

EMBED_HOST_DEVICE embed_bool mmgr_muto_take ( const TransformoCfg * args)

Appends args->digit to *args->mant as one more decimal digit.

Parameters
[in]argsThe mantissa to extend and the digit to append [BORROWS].
Returns
EMBED_TRUE when the digit went on, EMBED_FALSE when *args->mant already passed MMGR_MUTO_MANT_MAX.
Note
On EMBED_FALSE the mantissa stays as it was. A caller can count the digits it had to drop.
Warning
args->digit must be an ASCII decimal digit, since the value added is args->digit minus '0'.
Writes through args->mant [BORROWS].

References mmgr_muto_take().

Referenced by mmgr_muto_take().

◆ mmgr_muto_scale()

EMBED_HOST_DEVICE double mmgr_muto_scale ( const TransformoCfg * args)

Turns *args->mant times ten raised to args->ex into a double, signed by args->neg.

Parameters
[in]argsThe mantissa, the decimal exponent, the dropped bits and the sign [BORROWS].
Returns
The nearest double, with ties to even.
Note
Set args->rest when digits fell off the mantissa, and so the round still accounts for them.
Takes a plain double path when nothing fell off, the mantissa is under 2^53 and args->ex is within 22.
Does not read args->e2, and so the mantissa counts as a plain integer.
Warning
Returns a signed infinity for an args->ex above MMGR_POW5_MAX and a signed zero below its negative.

References mmgr_muto_scale().

Referenced by mmgr_muto_scale().

◆ mmgr_muto_scale_to_u64()

EMBED_HOST_DEVICE embed_u64 mmgr_muto_scale_to_u64 ( const TransformoCfg * args)

Turns *args->mant times two raised to args->e2 times ten raised to args->ex into a rounded 64-bit integer.

Parameters
[in]argsThe mantissa, its binary exponent and the decimal exponent [BORROWS].
Returns
The nearest integer with a half taken up, 0 when the value rounds below one, or all ones when too large.
Note
Reads args->e2, which mmgr_muto_scale leaves alone, and so the mantissa may carry a binary exponent here.
A half goes up whatever lies below it, and so the result is the magnitude rounded away from zero. mmgr_muto_scale rounds its own halves to even, as a double wants and what this deliberately does not do.
Reads neither args->rest, args->above nor args->neg, and so the result is always unsigned.
Warning
Does not bound args->ex against MMGR_POW5_MAX the way mmgr_muto_scale does. Only MMGR_POW5_STEPS bits of the magnitude take part in the walk. A larger exponent loses its high bits and the value scaled is not the one asked for.

References mmgr_muto_scale_to_u64().

Referenced by mmgr_muto_scale_to_u64().

◆ mmgr_muto_take_in()

EMBED_HOST_DEVICE embed_bool mmgr_muto_take_in ( const TransformoCfg * args)

Appends args->digit to *args->mant as one more digit in base args->base.

Parameters
[in]argsThe mantissa to extend, the digit to append and its base [BORROWS].
Returns
EMBED_TRUE when the digit went on. EMBED_FALSE when the base is outside 2 to 36, when the byte is no digit of the base, or when the digit would carry the mantissa past all ones.
Note
On EMBED_FALSE the mantissa stays as it was. A caller tells an overflow from a byte that is no digit with mmgr_muto_digit_value.
A digit is '0' to '9', then a letter of either case for 10 to 35.
Warning
Writes through args->mant [BORROWS].

References mmgr_muto_take_in().

Referenced by mmgr_muto_take_in().

Variable Documentation

◆ muto

const TransformoNs muto
static

Dispatch table instance named muto, with each member set to its mmgr_muto_ function.

Definition at line 156 of file transformo.h.