Applesoft: Internals--Floating Point Math Package (1 of 3) Applesoft's floating point package provides a 9 digit scientific package for evaluating numeric equations. It supports trigonometric functions with arguments in radians, exponents and logarithms to base e. ABBREVIATIONS msb: most significant bit or byte lsb: least significant bit or byte eol: end of line token ($00) A: the 6502 accumulator X: the 6502 X register Y: the 6502 Y register Z: the zero flag of the 6502 status register C: the carry flag of the 6502 status register A,X is a 16 bit number where A has the msb and X the lsb. (Y,A) is the number or string whose address is in Y and A, with the msb in Y and the lsb in A. FAC: the floating point accumulator ARG: the ARGument register REAL NUMBER FORMAT The real number format used throughout Applesoft is: the exponent is a single byte signed number (EXP) in excess of $80 form (the signed value has $80 added to it); the mantissa is 4 bytes (HO,MOH,MO,LO); the binary point is to the right of the most significant bit. Since in binary floating point notation the msb is always 1, the number's sign replaces the msb when the number is stored in memory in packed form. The sign, though, is kept in a separate byte (SGN) when only bit 7 is significant. If the exponent is zero, the number is zero, although the mantissa isn't necessarily zero. Examples: EXP HO MOH MO LO SGN Packed format -10 84 A0 00 00 00 10 84 20 00 00 00 FAC format -10 84 A0 00 00 00 FF 10 84 A0 00 00 00 00 Arithmetic routine calling conventions for single argument functions (e.g., SGN, ABS or INT): On entry the argument is in the FAC. On exit the result is in the FAC. Arithmetic routine calling conventions for two argument functions (e.g., FADD and FSUB): On entry the first argument is in the ARG. On entry the second argument is in the FAC. On exit the result is in the FAC. FLOATING POINT REGISTERS NOTE: The TEMP locations may be used for other things when not used by the floating point math package. FAC ARG TEMP1 TEMP2 TEMP3 RND EXP 9D A5 93 98 8A C9 HO 9E A6 94 99 8B CA MOH 9F A7 95 9A 8C CB MO A0 A8 96 9B 8D CC LO A1 A9 97 9C 8E CD SGN A2 AA (packed format) FLOATING POINT CONSTANTS The following addresses point to useful numbers; they're packed and suitable for use by most of the arithimetic routines including CONUPK and MOVMF. RND 00C9 -32768 E0FE 1 E913 SQR (1/2) E92D SQR (2) E932 -1/2 E937 LN (2) E93C 10 EA50 1000000000 ED14 1/2 EE64 LOG (2) base e EEDB pi/2 F063 pi*2 F06B 1/4 F070 Apple Tech Notes Keywords: ================================================================== This information is from the Apple Technical Information Library. ArticleID: TECHINFO-0000074 19960724 15:55:27.00 .