Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:58 25 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Maths precedence error in MMBasic? Any maths gurus out there?

     Page 3 of 3    
Author Message
zeitfest
Guru

Joined: 31/07/2019
Location: Australia
Posts: 482
Posted: 01:19am 09 May 2024
Copy link to clipboard 
Print this post

  Quote   how many programs genuinely have code that does double consecutive exponentiations (with no parentheses to force the order) and wasn't tested to check it worked as intended?


+1

I agree, although there are "thousands built" and it might be expected that at least the initial testing would find it.

Then again, It's not as if NASA is using this stuff.
 
NPHighview

Senior Member

Joined: 02/09/2020
Location: United States
Posts: 200
Posted: 06:42pm 09 May 2024
Copy link to clipboard 
Print this post

Jim - I love that you're quoting "Numerical Recipes in C", one of my favorites. I have a couple of others that you might like:
"Numerical Methods that Usually Work" - Acton (see cover photo - a hoot!)

"Math Toolkit for Realtime Programming" - Crenshaw


...and my favorite, "Mathematical Methods in the Physical Sciences" by Mary Boas (I've worked pretty much every problem in that book, under Boas' stern tutelage)
Live in the Future. It's Just Starting Now!
 
darthvader
Regular Member

Joined: 31/01/2020
Location: France
Posts: 76
Posted: 03:23pm 12 May 2024
Copy link to clipboard 
Print this post

HP Prime G2 give me : 3.00012207031
Theory is when we know everything but nothing work ...
Practice is when everything work but no one know why ;)
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 07:44pm 12 May 2024
Copy link to clipboard 
Print this post

  Volhout said  P.S. is there a note in the GW_Basic manual for this ? Guess not....


Hi Volhout,

I have consulted my old GW-Basic 3.2 reference manual in printed form (unfortunately in German) :-)
It actually gives some information about this – everything used to be better™!

But see for yourself. It says something about the function hierarchy and the order from left to right, unless brackets are used first.

Matthias

 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1241
Posted: 01:18am 13 May 2024
Copy link to clipboard 
Print this post

Thanks Matthias!
The  English version is not quite as clear. But leads to the same result.



Two consecutive operators must be separated by parentheses.
This means that if you follow the instructions you will get correct results.

EDIT
  Quote  3-18              ALLGEMEINE EIGENSCHAFTEN VON GWBASlC
Aufeinanderfolgende Operaloren derselben Hierarchiestufe werden von links nach rechts abgearbeitet. Die Hierarchie kann durch Verwendung von Klammern aufgehoben werden. Geklammerte Ausdrücke werden grundsätzlich zuerst bearbeitet. Bei geschachtelten Klammerausdrücken werden grundsätzlich der innerste Klammerausdruck zuerst bearbeitet.

Translation:
  Quote  3-18 GENERAL CHARACTERISTICS OF GWBASlC
Consecutive operators of the same hierarchy level are processed from left to right. The hierarchy can be broken by using parentheses. Expressions in parentheses are always processed first. For nested parentheses expressions, the innermost parentheses expression is always processed first.

Edited 2024-05-13 11:30 by twofingers
causality ≠ correlation ≠ coincidence
 
zeitfest
Guru

Joined: 31/07/2019
Location: Australia
Posts: 482
Posted: 01:56am 13 May 2024
Copy link to clipboard 
Print this post

Integer math gives the answer as 3    

How is the negation operator processed in MMBasic ?

(ed) To be fair, it is a reasonable thing for Basic to test for repeated exponentiation, and flag it so as to enforce bracketing.
Edited 2024-05-13 12:14 by zeitfest
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6783
Posted: 07:02am 13 May 2024
Copy link to clipboard 
Print this post

Ah, so the answer is INT(PI). Is that a coincidence?  :)

Nothing wrong with integers. I always use them when counting on my fingers and toes.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4225
Posted: 09:58am 13 May 2024
Copy link to clipboard 
Print this post

Hi Mick,

Unfortunately I cannot use integers for fingers. 9.5 is my count. But toes are still integers...

Volhout
Edited 2024-05-13 19:59 by Volhout
PicomiteVGA PETSCII ROBOTS
 
     Page 3 of 3    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024