--- title: "Logarithms" id: 57568 type: "computer_media" slug: "logarithms" url: "http://localhost/computer_media/logarithms/" markdown_url: "http://localhost/computer_media/logarithms.md" published_at: "2024-10-05T22:10:13+00:00" modified_at: "2026-04-03T07:58:22+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/logarithms.png" excerpt: "A compact change-of-base logarithm calculator that accepts any base and number, then loops endlessly for repeated calculations using a neat RUN restart trick." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Mathematics" slug: "mathematics" taxonomy: "genre" url: "http://localhost/type/mathematics/" media_contents: - id: 56721 title: "Synchro-Sette April 1983" type: "computer_media" url: "http://localhost/computer_media/synchro-sette-april-1983/" media_type: "Program" mediadate: "April 1983" images: - url: "http://localhost/wp-content/uploads/2024/10/logarithms.png" media_type_tags: "Mathematics" --- # Logarithms 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 `9998`–`9999` are developer utility lines placed well beyond normal execution reach. | Lines | Purpose | | --- | --- | | 10–30 | Clear screen and display title/prompt | | 40–50 | Input and echo the logarithm base Y | | 60–80 | Input and echo the number X | | 90 | Calculate the logarithm using change-of-base formula | | 100–110 | Display the result | | 120–130 | Wait for user input, then restart | | 9998–9999 | SAVE 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. ## 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 ```