What is so bad about using Floating Point math in a BASIC program

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
Crayon21
Posts: 348
Joined: Sun Nov 04, 2018 2:33 am

What is so bad about using Floating Point math in a BASIC program

Post by Crayon21 »

I understand that the ZX80 and 81 are simple machines. What I do not understand is the 32768 limitation and how it affects programs. The Apple II had this issue, making it hard to program business programs. What I want to know is Why?

please help a confused novice programmer
Last edited by Crayon21 on Tue Jan 19, 2021 2:54 am, edited 1 time in total.
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: What is so bad about using Floating Point math in a BASIC program

Post by dr beep »

It is slow, even in the display of a number.

I recently coded USCII and ran the same program in pure ZX81 BASIC and with USCII which only does a different way of displaying a number.
It only accepts a positive rounded number to be printed. Even with this change only the ZX81 BASIC is twice as fast as normal BASIC.
https://www.youtube.com/watch?v=rwzcrSbIJkk
Crayon21
Posts: 348
Joined: Sun Nov 04, 2018 2:33 am

Re: What is so bad about using Floating Point math in a BASIC program

Post by Crayon21 »

but how exactly is it slow? I can see the video just fine. my question concerns the hardware. for instance, creating a business application using just FP numbers and no Integers. how would they be different, what would the change look like when run?
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
User avatar
1024MAK
Posts: 5103
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: What is so bad about using Floating Point math in a BASIC program

Post by 1024MAK »

If you had to take a child to school by road, would you use a gas guzzling posh 4x4 or a fuel efficient modern small car?

Floating point numbers are the “jack of all trades” and can cope with a very wide range of numbers. But there are some potential disadvantages. They only store approximations (because internally in a computer all numbers are stored as binary digits, and converting from/to decimal can result in rounding errors), they take up more bytes of memory than simpler integral numbers, it takes time for the computer to convert from/to a floating point number, or to carry out mathematical operations on a floating point number.

Integral numbers are more limited. They also have various disadvantages, but have some advantages. Within the range, whole (integral decimal numbers convert very easily to/from binary. They are faster to process when adding or subtracting etc. They take up less memory.

They come in a number of different types:
One byte can store a decimal number between 0 and 255, or between -128 and +127 depending on how the the operator handles the number.
Two bytes can store a decimal number between 0 and 65535, or between -32768 and +32767 depending on how the the operator handles the number.
There are larger ranges available on computers with more memory.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
Post Reply