User Tools

Site Tools


base:kernal_floating_point_mathematics

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
base:kernal_floating_point_mathematics [2016-02-06 01:05] – [Movement] malcontentbase:kernal_floating_point_mathematics [2016-03-14 16:54] – fixed the mantissa range litwr2
Line 3: Line 3:
 [[http://en.wikipedia.org/wiki/Floating_point|Floating point]] numbers are handled by the C64's BASIC and Kernal ROMs. Called directly from machine language programs, they execute faster than when burdened by the BASIC interpreter. The difficulty lies in the variety of ways you must prepare the registers and zero-page before calling certain routines. Macros are recommended when dealing with FP in assembly.\\ [[http://en.wikipedia.org/wiki/Floating_point|Floating point]] numbers are handled by the C64's BASIC and Kernal ROMs. Called directly from machine language programs, they execute faster than when burdened by the BASIC interpreter. The difficulty lies in the variety of ways you must prepare the registers and zero-page before calling certain routines. Macros are recommended when dealing with FP in assembly.\\
  
-Floating point numbers are stored with 5 bytes. The first byte is the exponent, stored in excess $80 format (E = E - $80). Second byte holds the sign of the mantissa in its uppermost bit. The normalised mantissa (=< M < 2) is assumed to have a leading 1, and the following bits hold the fraction. If the exponent is 0, the number is interpreted as 0 regardless of the contents of the mantissa. +Floating point numbers are stored with 5 bytes. The first byte is the exponent, stored in excess $80 format (E = E - $80). Second byte holds the sign of the mantissa in its uppermost bit. The normalized mantissa (=< M < 1) is assumed to have a leading 1, and the following bits hold the fraction. If the exponent is 0, the number is interpreted as 0 regardless of the contents of the mantissa. 
  
 81 00 00 00 00 =   1 =  2<sup>1</sup> x %1.000...\\  81 00 00 00 00 =   1 =  2<sup>1</sup> x %1.000...\\ 
Line 249: Line 249:
  
 ====== Optimising ====== ====== Optimising ======
 +
 +===== Multiply =====
 +
 +Numerous advantages are gained improving the speed of the multiply. Routines that rely on it can be copied from the ROM and pointed to the new routine to improve performance. The following example relies on the Steve Judd's fast multiplication and reduces the number of cycles to multiply from around 2300 to little over 1400.
 +
 +[[Fast Floating Point Multiply]]
  
 ===== Movement ===== ===== Movement =====
Line 396: Line 402:
 Doing log(exp(8)) = 7.99999624\\ Doing log(exp(8)) = 7.99999624\\
    
-If we do exponentiation with our new routines like the Kernal does (y<sup>x</sup> = exp(x*log(y))) for 8<sup>8</sup> we get 16777148.6, while the Kernal routines return 16777216, which is a little closer to the true value of 16777224.+If we do exponentiation with our new routines like the Kernal does (y<sup>x</sup> = exp(x*log(y))) for 8<sup>8</sup> we get 16777148.6, while the true value is 16777224.
  
 ===== Faster Square Root ===== ===== Faster Square Root =====
base/kernal_floating_point_mathematics.txt · Last modified: 2020-12-06 20:48 by pararaum