The kernel provides functions for working with BCD-encoded floating point numbers. These are slower than binary floats but have greater accuracy in base 10. A binary floating point implementation are available in libc.

Decimal Floating Point

fpAbs View Source

Takes the absolute value of the floating point number at IX.

Inputs

IX

Pointer to operand

Outputs

IX

Pointer to result

fpAdd View Source

Adds the two floating point numbers.

Inputs

IX, IY

Pointers to operands

HL

Pointer to destination buffer

Notes

May destroy one or both operands.

fpAnd View Source

Performs a logical AND on the two floating point numbers.

Inputs

IX, IY

Pointers to operands

Outputs

NZ

Result was true

Z

Result was false

fpCompare View Source

Compares the two floating point numbers.

Inputs

IX, IY

Pointers to operands

Outputs

Flags

same as z80 CP instruction

fpFPart View Source

Calculates the fractional part of a floating point number, similar to TI-OS's fPart() command.

Inputs

IX

Pointer to operand

Outputs

IX

Pointer to result

fpIPart View Source

Calculates the integer part of a floating point number, similar to TI-OS's iPart() command.

Inputs

IX

Pointer to operand

Outputs

IX

Pointer to result

fpLdConst View Source

Loads a floating point constant specified by A into HL.

Inputs

A

Constant to load, use FP_* macros from kernel.inc

HL

Pointer to destination buffer

fpMax View Source

Finds the maximum of the two floating point numbers.

Inputs

IX, IY

Pointers to operands

Outputs

HL

Pointer to maximum

fpMin View Source

Finds the minimum of the two floating point numbers.

Inputs

IX, IY

Pointer to operands

Outputs

HL

Pointer to minimum

fpMulPow10 View Source

Multiplies the floating point number in IX by 10^E.

Inputs

IX

Pointer to operand

E

Signed exponent (i.e. 2 -> 100, -3 -> 0.001)

Outputs

IX

Pointer to result

Notes

Does not check for overflow.

fpNeg View Source

Negates the floating point number at IX.

Inputs

IX

Pointer to operand

Outputs

IX

Pointer to result

fpNot View Source

Performs a logical NOT on the floating point number.

Inputs

IX

Pointer to operand

Outputs

NZ

Result was true

Z

Result was false

fpOr View Source

Performs a logical OR on the two floating point numbers.

Inputs

IX, IY

Pointers to operands

Outputs

NZ

Result was true

Z

Result was false

fpRand View Source

Generates a random floating point number between 0 and 1, similar to TI-OS's rand command.

Inputs

HL

Pointer to output

Notes

Uses getRandom to generate the digits, so it is not cryptographically random.

fpSub View Source

Subtracts the two floating point numbers.

Inputs

IY

Pointer to operand 2 (subtrahend)

IX

Pointer to operand 1 (minuend)

HL

Pointer to destination buffer

fpXor View Source

Performs a logical XOR on the two floating point numbers.

Inputs

IX, IY

Pointers to operands

Outputs

NZ

Result was true

Z

Result was false

fptostr View Source

Converts a floating point number into an ASCII-encoded decimal string.

Inputs

A

Flags / digits

IX

Pointer to floating point number

HL

Pointer to destination buffer

Notes

The destination buffer must be at least 20 characters in length.

The most significant nibble of A should be set to flags. FP_STR_* macros in kernel.inc can be ORed and stored in A for convenience.

The least significant nibble of A is the number of digits to display after the decimal: 0-9 for that many digits, or 0xF for as many are non-zero.

Examples:

All nonzero decimals in scientific notation, with decimal as ',':

ld a, FP_STR_INV_PUNC | FP_DISP_SCIENTIFIC | 0xF

5 fixed digits grouped with ',':

ld a, FP_GROUP_DIGITS | 5

itofp View Source

Converts a 32-bit unsigned integer into a floating-point binary coded decimal format and stores it to the buffer at HL.

Inputs

HL

Pointer to 9-byte destination buffer

ACIX

Unsigned integer

Notes

The result is in the following format:

  • 1 byte flags:
  • 7: Sign bit
  • 4-6: Reserved for kernel
  • 0-3: Available for program use
  • 1 byte signed exponent, normalized to 0x80 instead of 0
  • 7 byte mantissa, BCD encoded with two digits per byte

strtofp View Source

Converts an ASCII-encoded signed decimal into a floating-point binary coded decimal format and stores it to the buffer at HL.

Inputs

IX

Pointer to string

HL

Pointer to 9-byte destination buffer

Outputs

Z

Set on success, reset on error

Notes

See itofp for the result format.

Only the first 14 significant digits are converted. The rest are truncated but still used for exponent calculation.

In case of error, the destination buffer's contents are undefined.

The destination buffer must be zeroed before calling strtofp.