Logarithms

This file is part of and Synchro-Sette April 1983. Download the collection to get this file.
Date: April 1983
Type: Program
Platform(s): TS 1000

This program computes the logarithm of any number X to any base Y using the change-of-base formula: log_Y(X) = LN(X) / LN(Y). After displaying the result, it accepts a dummy keypress via INPUT W$ and then loops back to the start with RUN, allowing repeated calculations. Lines 9998–9999 are utility lines for saving and restarting the program and would not be reached during normal execution. The program relies entirely on the built-in natural logarithm function LN rather than any machine code or external routines.


Program Analysis

Program Structure

The program is a simple, linear routine with an implicit loop created by RUN at line 130. There are no subroutines, no GO TO branching, and no conditional logic. Lines 99989999 are developer utility lines placed well beyond normal execution reach.

LinesPurpose
10–30Clear screen and display title/prompt
40–50Input and echo the logarithm base Y
60–80Input and echo the number X
90Calculate the logarithm using change-of-base formula
100–110Display the result
120–130Wait for user input, then restart
9998–9999SAVE utility and fallback RUN; never reached in normal flow

Core Algorithm

The change-of-base formula is implemented directly at line 90:

LET Z = LN X / LN Y

This correctly computes logY(X) for any positive base Y ≠ 1 and any positive X, relying entirely on the built-in LN (natural logarithm) function. No lookup tables or approximations are used.

Notable Techniques

  • RUN as a loop: Line 130 uses RUN to restart the program from line 10, clearing all variables and providing a clean loop without needing a GO TO. This is a common Sinclair BASIC idiom.
  • INPUT W$ as a pause: Line 120 uses INPUT W$ to hold the result on screen until the user presses ENTER, acting as a simple “press any key to continue” mechanism. Unlike PAUSE 0/INKEY$, this requires ENTER to proceed.
  • Comma positioning: Lines 20, 30, 60, 100 use double commas (,,) in PRINT statements to advance to the third print zone, providing basic centred-ish formatting without AT or TAB.
  • Echo of inputs: Lines 50 and 80 explicitly PRINT the entered values back to the screen, compensating for the fact that INPUT prompts on some Sinclair machines do not leave the entered value visible after acceptance.

Content

Appears On

Cassette to accompany the April 1983 issue of Synchro-Sette.

Related Products

Related Articles

Related Content

Image Gallery

Logarithms

Source Code

  10 CLS 
  20 PRINT ,,"LOGARITHMS OF ANY BASE"
  30 PRINT ,," INPUT BASE OF NUMBER? ";
  40 INPUT Y
  50 PRINT Y
  60 PRINT ,,"WHAT IS THE NUMBER? ";
  70 INPUT X
  80 PRINT X
  90 LET Z=LN X/LN Y
 100 PRINT ,,"LOGARITHM OF ";X
 110 PRINT "IS ";Z
 120 INPUT W$
 130 RUN 
 9998 SAVE "LOGARITHM%S"
 9999 RUN 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top