Logo GenPRES

RationalX Type

A two-tier exact rational packed into 24 bytes: two int64s for the reduced small-tier numerator/denominator, and a nullable BigCell reference for the rare spill tier. Big = null means small (value P/Q); a non-null Big means spilled (value Big.Value).

Hand-rolled (rather than a struct DU) so the spill reference itself is the small/big discriminator — no DU tag word, so every value is 24 bytes and the common small case is still inline and allocation-free. There is duplicate logic for handling spill/non-spill cases, however, for performance reasons this is accepted. Canonical-representation invariant: any value that fits int64 is ALWAYS stored small (Big = null), never spilled. Every constructor and arithmetic result funnels through OfLarge (which re-narrows) or normPair. This guarantees a single representation per value, so equality and hashing are consistent across the two tiers.

Record fields

Record Field Description

Big

Full Usage: Big

Field type: BigCell

big tier: null => small (use P/Q); non-null => spilled (use Big.Value)

Field type: BigCell

P

Full Usage: P

Field type: int64

small tier: reduced, Q > 0 (the zero-initialized default 0/0 is guarded)

Field type: int64

Q

Full Usage: Q

Field type: int64
Field type: int64

Instance members

Instance member Description

this.Denominator

Full Usage: this.Denominator

Returns: bigint
Returns: bigint

this.Equals

Full Usage: this.Equals

Parameters:
Returns: bool
r : RationalX
Returns: bool

this.IsSpilled

Full Usage: this.IsSpilled

Returns: bool

True when the value spilled out of the int64 fast path.

Returns: bool

this.Numerator

Full Usage: this.Numerator

Returns: bigint
Returns: bigint

Static members

Static member Description

x * y

Full Usage: x * y

Parameters:
Returns: RationalX
x : RationalX
y : RationalX
Returns: RationalX

x + y

Full Usage: x + y

Parameters:
Returns: RationalX
x : RationalX
y : RationalX
Returns: RationalX

x - y

Full Usage: x - y

Parameters:
Returns: RationalX
x : RationalX
y : RationalX
Returns: RationalX

x / y

Full Usage: x / y

Parameters:
Returns: RationalX
x : RationalX
y : RationalX
Returns: RationalX

~-x

Full Usage: ~-x

Parameters:
Returns: RationalX
x : RationalX
Returns: RationalX

RationalX.Abs(r)

Full Usage: RationalX.Abs(r)

Parameters:
Returns: RationalX
r : RationalX
Returns: RationalX

RationalX.Compare(x, y)

Full Usage: RationalX.Compare(x, y)

Parameters:
Returns: int
x : RationalX
y : RationalX
Returns: int

RationalX.FromBigInt(z)

Full Usage: RationalX.FromBigInt(z)

Parameters:
    z : bigint

Returns: RationalX
z : bigint
Returns: RationalX

RationalX.FromDecimal(d)

Full Usage: RationalX.FromDecimal(d)

Parameters:
    d : decimal

Returns: RationalX
d : decimal
Returns: RationalX

RationalX.FromInt(x)

Full Usage: RationalX.FromInt(x)

Parameters:
    x : int

Returns: RationalX
x : int
Returns: RationalX

RationalX.FromInt64Fraction(n, d)

Full Usage: RationalX.FromInt64Fraction(n, d)

Parameters:
    n : int64
    d : int64

Returns: RationalX
n : int64
d : int64
Returns: RationalX

RationalX.FromIntFraction(n, d)

Full Usage: RationalX.FromIntFraction(n, d)

Parameters:
    n : int
    d : int

Returns: RationalX
n : int
d : int
Returns: RationalX

RationalX.OfFraction(n, d)

Full Usage: RationalX.OfFraction(n, d)

Parameters:
    n : int64
    d : int64

Returns: RationalX
n : int64
d : int64
Returns: RationalX

RationalX.OfLarge(x)

Full Usage: RationalX.OfLarge(x)

Parameters:
Returns: RationalX

Re-narrow an MBR to the small tier whenever it fits int64. Linchpin of the canonical-representation invariant.

x : MBR
Returns: RationalX

RationalX.One

Full Usage: RationalX.One

Returns: RationalX
Returns: RationalX

RationalX.Parse(s)

Full Usage: RationalX.Parse(s)

Parameters:
    s : string

Returns: RationalX
s : string
Returns: RationalX

RationalX.ToBigInt(r)

Full Usage: RationalX.ToBigInt(r)

Parameters:
Returns: bigint
r : RationalX
Returns: bigint

RationalX.ToDouble(r)

Full Usage: RationalX.ToDouble(r)

Parameters:
Returns: float
r : RationalX
Returns: float

RationalX.ToInt32(r)

Full Usage: RationalX.ToInt32(r)

Parameters:
Returns: int
r : RationalX
Returns: int

RationalX.Zero

Full Usage: RationalX.Zero

Returns: RationalX
Returns: RationalX

Type something to start searching.