SuperBASIC Quirks
SuperBASIC Quirks
Hi all,
When displaying coordinates with central positioning, sometimes requires exchange of sequential values ie. 1 to 40 with +/- values ie. 20< >0< >-20
I use variable ‘wz’ for PRINT out of values 20< >2 0 -2< > -20. The calculation are with variable ‘vs’ ranging from ‘0.4’ to ‘2.4’ in STEPS of ‘.1’ vs=1.4 equates to ‘0’
Coding (1) IF vs=1.4 : wz=0 : ELSE wz=(vs*20)-28 comes up with invalid parameter when vs=1.4 (ie. ‘0’)
I assume the Interpreter still calculates (1.4 * 20) -28 as floating-point maths causing the ‘0’ Error?
SuperBASIC has the ability to convert Integers and Floating-point values to Strings and back so I used this
Coding (2) Z$=vs*20 : wz=Z$-28 with success! Gives wz values 20 < > 2..0..-2 < > -20 in STEPS of ‘2’
Que: QL Experts. Are my assumptions correct about ‘0’ error and will my Coding (2) Compile OK.
Norman - if you what to add Assembly code for this I dare say it wouldn’t go a miss for some.
QBITS
When displaying coordinates with central positioning, sometimes requires exchange of sequential values ie. 1 to 40 with +/- values ie. 20< >0< >-20
I use variable ‘wz’ for PRINT out of values 20< >2 0 -2< > -20. The calculation are with variable ‘vs’ ranging from ‘0.4’ to ‘2.4’ in STEPS of ‘.1’ vs=1.4 equates to ‘0’
Coding (1) IF vs=1.4 : wz=0 : ELSE wz=(vs*20)-28 comes up with invalid parameter when vs=1.4 (ie. ‘0’)
I assume the Interpreter still calculates (1.4 * 20) -28 as floating-point maths causing the ‘0’ Error?
SuperBASIC has the ability to convert Integers and Floating-point values to Strings and back so I used this
Coding (2) Z$=vs*20 : wz=Z$-28 with success! Gives wz values 20 < > 2..0..-2 < > -20 in STEPS of ‘2’
Que: QL Experts. Are my assumptions correct about ‘0’ error and will my Coding (2) Compile OK.
Norman - if you what to add Assembly code for this I dare say it wouldn’t go a miss for some.
QBITS
- NormanDunbar
- Forum Moderator
- Posts: 2477
- Joined: Tue Dec 14, 2010 9:04 am
- Location: Buckie, Scotland
- Contact:
Re: SuperBASIC Quirks
I might be able to, but I'm afraid I have absolutely no idea what you are meaning in your post. Sorry.qbits wrote:Norman - if you what to add Assembly code for this I dare say it wouldn’t go a miss for some.

Cheers,
Norm.
Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Re: SuperBASIC Quirks
Comparing floating point variables against floating point constants is always dangerous and shouldn't be done. The computer (not just the QL, but basically any computer) has difficulties hitting the exact value. Try the following:qbits wrote: Fri May 09, 2025 8:00 am Hi all,
When displaying coordinates with central positioning, sometimes requires exchange of sequential values ie. 1 to 40 with +/- values ie. 20< >0< >-20
I use variable ‘wz’ for PRINT out of values 20< >2 0 -2< > -20. The calculation are with variable ‘vs’ ranging from ‘0.4’ to ‘2.4’ in STEPS of ‘.1’ vs=1.4 equates to ‘0’
Coding (1) IF vs=1.4 : wz=0 : ELSE wz=(vs*20)-28 comes up with invalid parameter when vs=1.4 (ie. ‘0’)
I assume the Interpreter still calculates (1.4 * 20) -28 as floating-point maths causing the ‘0’ Error?
SuperBASIC has the ability to convert Integers and Floating-point values to Strings and back so I used this
Coding (2) Z$=vs*20 : wz=Z$-28 with success! Gives wz values 20 < > 2..0..-2 < > -20 in STEPS of ‘2’
Que: QL Experts. Are my assumptions correct about ‘0’ error and will my Coding (2) Compile OK.
Norman - if you what to add Assembly code for this I dare say it wouldn’t go a miss for some.
QBITS
Code: Select all
PRINT (1.4 * 20) = 28
This returns 0 on all my QLs, while common sense would assume it should return 1. That is caused my minimal inaccuracies in floating point (some decimal values simply cannot be exactly reproduced in the computer's floating point format). And that is why S*BASIC has the "==" operator, which does an "approximate comparison" (as in "close to")
Code: Select all
PRINT (1.4 * 20) == 28
Returns 1, as it should. Simply replace your "=" comparisons with "==" ones and it should work.
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Re: SuperBASIC Quirks
S*BASIC is a little unique in having the "approximately equal" (double =), for both floats and strings in their respective ways.
It's really useful for float comparisons when tiny calculation inequalities become obvious in cases like this for such numbers.
It's really useful for float comparisons when tiny calculation inequalities become obvious in cases like this for such numbers.
--
All things QL - https://dilwyn.theqlforum.com
All things QL - https://dilwyn.theqlforum.com
-
- Aurora
- Posts: 890
- Joined: Mon Nov 24, 2014 2:03 pm
Re: SuperBASIC Quirks
Hi Folks,
Do not use the == operator if either side of the operator is zero : PRINT (1E-99)==0 returns false !
Always add 1 to either side : PRINT (1+1E-99)==1 returns true...
(This was described many years ago in documentation). Steve.
____________________________________________________________
Do not use the == operator if either side of the operator is zero : PRINT (1E-99)==0 returns false !
Always add 1 to either side : PRINT (1+1E-99)==1 returns true...
(This was described many years ago in documentation). Steve.
____________________________________________________________
Re: SuperBASIC Quirks
Hi,
My Simples solution to avoid the ‘0’ problem with floating point calculations was an
IF statement to catch the variable vs value of 1.4 equating to the ‘0’
ELSE all other calculation for wz=(vs*20)-28 provides the output scale of -20 to +20.
Is there a more sophisticate coding method or does SIMPLES suffice!
From members experience do we have any more quirky use of SuperBASIC code.
QBITS
My Simples solution to avoid the ‘0’ problem with floating point calculations was an
IF statement to catch the variable vs value of 1.4 equating to the ‘0’
ELSE all other calculation for wz=(vs*20)-28 provides the output scale of -20 to +20.
Is there a more sophisticate coding method or does SIMPLES suffice!
From members experience do we have any more quirky use of SuperBASIC code.
QBITS
Re: SuperBASIC Quirks
It had never quite sunk in with me about what Steve said about == 0, although it is mentioned in the Jan Jones BASIC guide:
X == Y will be true if [X-Y] <= [Y*1E-7] , where [X-Y] means the absolute, or positive, value of X-Y.
Note : It may not be immediately obvious to you that no value will ever be == 0. If, in the above equation, Y is zero, then the check reduces to [X] <= 0, clearly impossible when X is non-zero. If you make X zero instead of Y, then the test becomes [Y] <= [Y * 1E-7], also somewhat unfeasible. To test for a quantity being very close to zero therefore, adding one to both sides gives the desired result, e.g. (X+1) == 1
--
All things QL - https://dilwyn.theqlforum.com
All things QL - https://dilwyn.theqlforum.com
Re: SuperBASIC Quirks
In QBits' example that translates to simply "don't subtract before compare"), and that's why I wrotedilwyn wrote: Fri May 23, 2025 5:58 pm It had never quite sunk in with me about what Steve said about == 0, although it is mentioned in the Jan Jones BASIC guide:
X == Y will be true if [X-Y] <= [Y*1E-7] , where [X-Y] means the absolute, or positive, value of X-Y.
Note : It may not be immediately obvious to you that no value will ever be == 0. If, in the above equation, Y is zero, then the check reduces to [X] <= 0, clearly impossible when X is non-zero. If you make X zero instead of Y, then the test becomes [Y] <= [Y * 1E-7], also somewhat unfeasible. To test for a quantity being very close to zero therefore, adding one to both sides gives the desired result, e.g. (X+1) == 1
Code: Select all
(1.4 * 20) == 28

ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Re: SuperBASIC Quirks
It works, but remember INT is word sized in SuperBASIC, long in SBASIC.bwinkel67 wrote: Sat May 24, 2025 1:35 am This is a bit costly, but couldn't you just do this:
IF INT (ABS (X)) = 0
Per
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen