TorchLean API

FloatLib.Kernels.FixedWord.SignedMagnitude.Runtime

Shared native signed-magnitude arithmetic #

Binary interchange and posit arithmetic both decode finite values into a sign and an unsigned significand. These one- and two-word operations combine aligned magnitudes, retaining the sign of the larger magnitude on subtraction and choosing positive zero on exact cancellation.

@[inline]
def FloatLib.Numerics.FixedWord.addSignedMagnitudes (leftNegative rightNegative : Bool) (leftMagnitude rightMagnitude : UInt64) :

Add or subtract two unsigned magnitudes according to their independent signs.

Exact cancellation returns positive zero. Same-sign callers must establish separately that the sum fits in UInt64; opposite-sign subtraction cannot overflow.

Instances For
    @[inline]
    def FloatLib.Numerics.FixedWord.addSignedMagnitudes128 (leftNegative rightNegative : Bool) (leftMagnitude rightMagnitude : UInt128) :

    Add or subtract two unsigned two-limb magnitudes according to their independent signs.

    Exact cancellation returns positive zero. Same-sign addition discards the carry from add128, so callers must establish that the sum fits in UInt128; opposite-sign subtraction cannot overflow.

    Instances For