MMgr v1.0.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
transformo.h File Reference

Decimal to binary conversion, the limits, the arguments, and the muto dispatch table. More...

#include "fractio/fractio.h"
#include "mmgr.h"
#include "pow5/pow5.h"

Go to the source code of this file.

Data Structures

struct  TransformoCfg
 Arguments for the three 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 accumulating.

Functions

embed_bool mmgr_muto_take (const TransformoCfg *args)
 Appends args->digit to *args->mant as one more decimal digit.
double mmgr_muto_scale (const TransformoCfg *args)
 Turns *args->mant times ten raised to args->ex into a double, signed by args->neg.
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.

Variables

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

Detailed Description

Decimal to binary conversion, the limits, the arguments, and the muto dispatch table.

Author
dstroy0 (Douglas Quigg) dquig.nosp@m.g123.nosp@m.@gmai.nosp@m.l.co.nosp@m.m
Date
2026-08-29
Note
take builds a mantissa one digit at a time.
scale turns one into a double, and scale_to_u64 turns one into an integer.

Definition in file transformo.h.

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 multiplying by ten and adding a digit of nine both stay inside an embed_u64.
mmgr_muto_take returns EMBED_FALSE instead of appending once the mantissa passes this.
Explicit casts hold both the complement and the result at embed_u64, and the 9u and 10u are suffixed to match, and so the subtraction and the divide are done at the mantissa's own width and not at int's.

Definition at line 34 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 accumulating.

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 it is kept in.
400 is past the 308 a double reaches. Anything the clamp holds back has already gone to a signed infinity or a signed zero, and stopping the count early cannot change the result.
The literal is untyped, matching the embed_iword exponent it is compared against.

Definition at line 45 of file transformo.h.

Function Documentation

◆ mmgr_muto_take()

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 was appended, EMBED_FALSE when *args->mant already passed MMGR_MUTO_MANT_MAX.
Note
On EMBED_FALSE the mantissa is left 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()

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 going to even.
Note
Set args->rest when digits were dropped from the mantissa, and so the rounding still accounts for them.
Takes a plain double path when nothing was dropped, the mantissa is under 2^53 and args->ex is within 22.
Does not read args->e2, and so the mantissa is taken 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_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 going 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 is taken 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 are walked. 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().

Variable Documentation

◆ muto

const TransformoNs muto
static

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

Definition at line 123 of file transformo.h.