Skip to navigation

Elite on the BBC Micro and NES

Maths (Arithmetic): logL

[6502 Second Processor version, I/O processor]

Name: logL [Show more] Type: Variable Category: Maths (Arithmetic) Summary: Binary logarithm table (low byte)
Context: See this variable in context in the source code Variations: See code variations for this variable in the different versions References: This variable is used as follows: * LOIN (Part 2 of 7) uses logL * LOIN (Part 5 of 7) uses logL

At byte n, the table contains the high byte of: &2000 * log10(n) / log10(2) = 32 * 256 * log10(n) / log10(2) where log10 is the logarithm to base 10. The change-of-base formula says that: log2(n) = log10(n) / log10(2) so byte n contains the low byte of: 32 * log2(n) * 256
.logL SKIP 1 FOR I%, 1, 255 EQUB INT(&2000 * LOG(I%) / LOG(2) + 0.5) MOD 256 NEXT