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

The binary64 field layout and scale bounds, the assertions that pin them, the six entry points and the fract table. More...

#include "mmgr.h"

Go to the source code of this file.

Data Structures

struct  FractioCfg
 Pins the two scale bounds to the values binary64 gives. More...
struct  FractioNs
 Type of the fract dispatch table. More...

Macros

#define MMGR_DBL_SIGN_MASK
 The binary64 field layout: three masks, the sign shift, the two field widths, the two whole field values and the exponent bias.
#define MMGR_DBL_EXP_MASK
#define MMGR_DBL_MANT_MASK
#define MMGR_DBL_SIGN_SHIFT
#define MMGR_DBL_MANT_BITS
#define MMGR_DBL_EXP_BITS
#define MMGR_DBL_SIGN_ONE
#define MMGR_DBL_EXP_ALL
#define MMGR_DBL_BIAS
#define MMGR_DBL_BITS
 The width of a double in bits, bytes and embed_word units.
#define MMGR_DBL_BYTES
#define MMGR_DBL_WORDS
#define MMGR_DBL_SCALE_MAX
 Pins the target's double to the width and storage this file assumes.
#define MMGR_DBL_SCALE_MIN

Functions

embed_u64 mmgr_fract_sign (const FractioCfg *args)
 Returns the sign bit of args->bits.
embed_u64 mmgr_fract_exp (const FractioCfg *args)
 Returns the exponent field of args->bits.
embed_u64 mmgr_fract_mant (const FractioCfg *args)
 Returns the mantissa field of args->bits.
embed_u64 mmgr_fract_merge (const FractioCfg *args)
 Packs args->sign, args->exp and args->mant into one bit pattern.
double mmgr_fract_from_bits (const FractioCfg *args)
 Reads the union as a double.
embed_u64 mmgr_fract_to_bits (const FractioCfg *args)
 Reads the union as a bit pattern.

Variables

static const FractioNs fract
 Dispatch table instance named fract, whose members are the mmgr_fract_ entries.

Detailed Description

The binary64 field layout and scale bounds, the assertions that pin them, the six entry points and the fract table.

Author
dstroy0 (Douglas Quigg) dquig.nosp@m.g123.nosp@m.@gmai.nosp@m.l.co.nosp@m.m
Date
2026-08-29
Note
Everything here is written for binary64. The assertions below are what hold the target to it, and they are EMBED_STATIC_ASSERT. A target whose double is another shape fails the build instead of reading the wrong bits.
FractioCfg carries no pointer, and so no call here follows one into a caller's buffer. The whole module is field arithmetic on the one value it is handed.
Warning
args is the single one pointer the six entry points take, and not one of them tests it. The bodies EMBED_ENTRY writes read its members straight through. A null args is dereferenced.

Definition in file fractio.h.

Macro Definition Documentation

◆ MMGR_DBL_SIGN_MASK

#define MMGR_DBL_SIGN_MASK

The binary64 field layout: three masks, the sign shift, the two field widths, the two whole field values and the exponent bias.

Note
The masks, the shift and the widths give each field's position and extent. MMGR_DBL_SIGN_ONE and MMGR_DBL_EXP_ALL are values a field can hold and not positions, and MMGR_DBL_BIAS is an amount.
The assertions below check the masks tile the word without gap or overlap.
The masks, MMGR_DBL_SIGN_ONE and MMGR_DBL_EXP_ALL carry a ull suffix, matching the embed_u64 the fields are read from. The shifts and widths carry u. MMGR_DBL_BIAS carries neither, since it is subtracted in the signed scale arithmetic below. The sign bit.

Definition at line 41 of file fractio.h.

◆ MMGR_DBL_EXP_MASK

#define MMGR_DBL_EXP_MASK

The eleven exponent bits.

Definition at line 42 of file fractio.h.

◆ MMGR_DBL_MANT_MASK

#define MMGR_DBL_MANT_MASK

The fifty-two stored mantissa bits.

Definition at line 43 of file fractio.h.

◆ MMGR_DBL_SIGN_SHIFT

#define MMGR_DBL_SIGN_SHIFT

Bit position of the sign.

Definition at line 44 of file fractio.h.

◆ MMGR_DBL_MANT_BITS

#define MMGR_DBL_MANT_BITS

Stored mantissa width, and the exponent's shift.

Definition at line 45 of file fractio.h.

◆ MMGR_DBL_EXP_BITS

#define MMGR_DBL_EXP_BITS

Exponent width.

Definition at line 46 of file fractio.h.

◆ MMGR_DBL_SIGN_ONE

#define MMGR_DBL_SIGN_ONE

A sign of one, and merge's mask for args->sign.

Definition at line 47 of file fractio.h.

◆ MMGR_DBL_EXP_ALL

#define MMGR_DBL_EXP_ALL

All ones in the exponent, and merge's mask for args->exp.

Definition at line 48 of file fractio.h.

◆ MMGR_DBL_BIAS

#define MMGR_DBL_BIAS

Amount added to the true exponent when stored.

Definition at line 49 of file fractio.h.

◆ MMGR_DBL_BITS

#define MMGR_DBL_BITS

The width of a double in bits, bytes and embed_word units.

Note
MMGR_DBL_BITS is declared and not measured. The assertion below compares it against sizeof(double) and fails the build when the target disagrees.
The 8u in MMGR_DBL_BYTES is bits per byte. That same assertion holds a target to it, since a byte of another width would leave sizeof(double) * 8u short of MMGR_DBL_BITS.
MMGR_DBL_WORDS rounds up, and the assertion below requires it to come out exact. Bits in a double.

Definition at line 60 of file fractio.h.

◆ MMGR_DBL_BYTES

#define MMGR_DBL_BYTES

Bytes in a double.

Definition at line 61 of file fractio.h.

◆ MMGR_DBL_WORDS

#define MMGR_DBL_WORDS

embed_word units per double. \

Definition at line 62 of file fractio.h.

◆ MMGR_DBL_SCALE_MAX

#define MMGR_DBL_SCALE_MAX

Pins the target's double to the width and storage this file assumes.

Note
Checks the bit width, that a double is a whole number of embed_word units, and that embed_u64 holds it.

Pins the field constants above against each other.

Note
Checks the widths sum to 64, the masks tile the word, and no two masks overlap.
Also checks each mask against the shift or width for the same field, that MMGR_DBL_EXP_ALL fills MMGR_DBL_EXP_BITS, and that MMGR_DBL_BIAS is half the exponent range less one.

The range of powers of two a double can carry once the mantissa is treated as an integer.

Note
MMGR_DBL_SCALE_MAX takes the largest finite exponent, removes the bias, and drops the mantissa width.
MMGR_DBL_SCALE_MIN starts from an exponent field of 1, the smallest normal.
Explicit casts hold both expressions in embed_iword, since MMGR_DBL_EXP_ALL and MMGR_DBL_MANT_BITS are unsigned. MMGR_DBL_SCALE_MIN is negative, and without its cast the subtraction would wrap.

Definition at line 107 of file fractio.h.

◆ MMGR_DBL_SCALE_MIN

#define MMGR_DBL_SCALE_MIN

Definition at line 108 of file fractio.h.

Function Documentation

◆ mmgr_fract_sign()

embed_u64 mmgr_fract_sign ( const FractioCfg * args)

Returns the sign bit of args->bits.

Parameters
[in]argsBit pattern in the union [BORROWS].
Returns
0 for a positive sign, 1 for a negative one.
Note
The bit is read as stored, alone is examined. A negative zero answers 1, and so does a NaN carrying the sign.

References mmgr_fract_sign().

Referenced by mmgr_fract_sign().

◆ mmgr_fract_exp()

embed_u64 mmgr_fract_exp ( const FractioCfg * args)

Returns the exponent field of args->bits.

Parameters
[in]argsBit pattern in the union [BORROWS].
Returns
The stored exponent, still carrying MMGR_DBL_BIAS.
Note
0 marks a zero or subnormal. MMGR_DBL_EXP_ALL marks an infinity or NaN.

References mmgr_fract_exp().

Referenced by mmgr_fract_exp().

◆ mmgr_fract_mant()

embed_u64 mmgr_fract_mant ( const FractioCfg * args)

Returns the mantissa field of args->bits.

Parameters
[in]argsBit pattern in the union [BORROWS].
Returns
The fifty-two stored bits, without the implicit leading one.
Note
The leading one is implicit only where the exponent field is nonzero. A zero or a subnormal has none, and there these fifty-two bits are the whole mantissa.

References mmgr_fract_mant().

Referenced by mmgr_fract_mant().

◆ mmgr_fract_merge()

embed_u64 mmgr_fract_merge ( const FractioCfg * args)

Packs args->sign, args->exp and args->mant into one bit pattern.

Parameters
[in]argsThe three fields [BORROWS].
Returns
The assembled pattern.
Note
Each field is masked to its own width. A wide input cannot reach a neighboring field.
Warning
What the mask drops is gone and nothing reports it. A sign above MMGR_DBL_SIGN_ONE, an exponent above MMGR_DBL_EXP_ALL or a mantissa above MMGR_DBL_MANT_MASK keeps only its low bits.

References mmgr_fract_merge().

Referenced by mmgr_fract_merge().

◆ mmgr_fract_from_bits()

double mmgr_fract_from_bits ( const FractioCfg * args)

Reads the union as a double.

Parameters
[in]argsUnion with its bits member filled [BORROWS].
Returns
The same storage interpreted as a double.

References mmgr_fract_from_bits().

Referenced by mmgr_fract_from_bits().

◆ mmgr_fract_to_bits()

embed_u64 mmgr_fract_to_bits ( const FractioCfg * args)

Reads the union as a bit pattern.

Parameters
[in]argsUnion with its val member filled [BORROWS].
Returns
The same storage interpreted as embed_u64.

References mmgr_fract_to_bits().

Referenced by mmgr_fract_to_bits().

Variable Documentation

◆ fract

const FractioNs fract
static

Dispatch table instance named fract, whose members are the mmgr_fract_ entries.

Note
EMBED_TABLE_STORAGE is static const, and so every translation unit including this header holds a copy of its own and the addresses differ between them. The six functions it points at are the one shared definition.
EMBED_UNUSED keeps a translation unit that includes the header without calling through the table from warning about it. It expands to nothing where the unused attribute is unavailable.

Definition at line 216 of file fractio.h.