Skip to content
unbibium edited this page Feb 19, 2013 · 2 revisions

Overview

The floating point package was the first one I had to port, because the startup message contained a calculated number for the free memory display. It was calculated in an integer, but the display routine converts it to float before displaying it, as turns out to be the case any time an integer is read or printed. Fortunately, this gave me a non-interactive way to see these routines in action, and also allowed me to complete much of the math ahead of time.

On the Commodore 64, floating point routines were accessible from machine language programs. In the same way, perhaps the floating point package can be separated out and used in other DCPU-16 projects, once all the major bugs are found.

The routines were ported using C64Wiki's floating point arithmetic page as a description of how the C64 handles floats. A more complete description of what's happening is described in this tutorial on IEEE floating point numbers.

Format

Numbers stored in program memory take three bytes, comprising an 8-bit exponent, 31-bit mantissa, and sign bit. The number is assumed to be normalized, so that the 32nd bit of the mantissa may be assumed to be 1.

Numbers in short-term operations are expanded, such that the sign bit is separated from the two-word mantissa. The leading one bit is restored when it is read from memory, so that the number may drift out of normalization, and only really needs to be re-normalized before storage. There's an extra "overflow" byte allocated to the mantissa, so short-term operations generally use a 48-bit mantissa, and only discard the low bits after normalization when it's time to store the number back into RAM.

In both cases, only eight bits of the exponent are used. Exponent bytes exceeding 0xFF are treated as an overflow condition.

Math logic

FADD

FSUB

FMULT

FDIV

Clone this wiki locally