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: 75
Joined: Sun Nov 04, 2018 2:33 am

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

Post by Crayon21 » Sun Mar 24, 2019 3:18 am

I understand the ZX80 and 81 are simple machine. 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
zx81: great yet flawed
Zx spectrum: masterpiece that keeps on giving

(wish it weren't so expensive) :o

dr beep
Posts: 1190
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 » Sun Mar 24, 2019 11:58 am

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: 75
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 » Mon Mar 25, 2019 11:50 pm

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?
zx81: great yet flawed
Zx spectrum: masterpiece that keeps on giving

(wish it weren't so expensive) :o

User avatar
1024MAK
Posts: 2442
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 » Tue Mar 26, 2019 9:30 am

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

Post Reply