Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

REAL and LREAL

REAL is IEEE 754 binary32 (about 7 significant digits) and LREAL binary64 (about 15), as Ed.3 Table 10 requires. Each operation rounds its result to its own type, half to even, and keeps no extra precision between operations.

Infinity and NaN are flagged, division by zero faults

A result too large for its type becomes an infinity and is flagged OVERFLOW; one that is not a number is flagged NAN. Both carry on as IEEE 754 has them: a later operation on them gives what IEEE 754 says. Division by zero — 0.0 or -0.0 — is a fault, as an integer’s is. (Implementer choices)

ExpressionTypeResultFlagNote
REAL#1.0E38 * REAL#10.0REAL+infflag OVERFLOW
REAL#-1.0E38 * REAL#10.0REAL-infflag OVERFLOW
REAL#1.0 / REAL#0.0REAL—fault DIVISION_BY_ZEROnot +inf
SQRT(REAL#-1.0)REALNaNflag NAN
LN(REAL#0.0)REAL-infflag OVERFLOW
LREAL_TO_REAL(LREAL#1.0E300)REAL+infflag OVERFLOWbeyond REAL
EXPT(REAL#2.0, 10)REAL1024.0—
REAL#2.0 ** REAL#0.5REAL1.4142135—

Precision

A REAL holds every integer up to 2²⁴ = 16777216 exactly, an LREAL up to 2⁵³; past that, a sum rounds to the nearest the type holds. Neither is flagged: it is how floating point is, not an error.

ExpressionTypeResultFlagNote
REAL#0.1 + REAL#0.2REAL0.3—the nearest REAL to each is the same
LREAL#0.1 + LREAL#0.2LREAL0.30000000000000004—not LREAL’s 0.3
REAL#16777216.0 + REAL#1.0REAL16777216.0—16777217 is no REAL
REAL#1.0 / REAL#3.0REAL0.33333334—

The functions of Ed.3 Table 28 (SQRT, LN, LOG, EXP, SIN, COS, TAN, ASIN, ACOS, ATAN, EXPT) come from the C library’s <math.h>, or from the platform’s own when it gives one (The C output §1): their last digit is the library’s.