This was a youtube vid I saw. What's 6/2(1+2).
I thought it was one but gcb gives the "correct" answer,, needs a space to asm 6/ 2(1+2)
no wonder my code fails sometimes :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ha ha.. why didn't someone think of that before?
Quote- 42 (or forty-two) is the Answer to the Ultimate Question of Life, the Universe and Everything. This Answer was first calculated by the supercomputer Deep Thought after seven and a half million years of thought :)
GCB flash/hexed 6/ 2(1+2) and gave the "correct" answer.... 9
No 6/2(1+2) needed just a space after6/
It does 6/2=3
(1+2)=3
3 * 3=9.
like (6/2)(1+2)
Interesting and no * needed as real numbers, not vars, like var(1+2) which would be an arrary element.
Then GCBASIC has its precedence wrong.
Multiplication should proceed division so the correct result would be :
6 / (2 * ( 1 + 2) =
6 / (2 * 3) =
6 / 6 =
1
That is a prime example why parenthesis should be used extensively in programing, to ensure that the computation follows the order the programmer intended.
Last edit: Chris Roper 2022-05-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So gcb is doing sums correct.
I thought brackets (1+2)=3
2*(3)=6
6/6=1
what have I learnt? and that's using left to right evaluation.
Use braces, brackets, parenthesis so they're first in left to right order.
Then div,mult,add,subtract... is it??
Chris says 1 and I thought that but it's 9 cos div before mult.
Last edit: stan cartwright 2022-05-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That is the way I see it too.
The problem was ambiguous, hence the point I am trying to make "parenthesis should be used".
If we can't agree on the order of execution how can we expect a compiler to do it?
We are all putting the * where we think it should be but the original problem implied it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Found this https://youtu.be/Q0przEtP19s - Math Prof answers 6÷2(1+2) = ? once and for all Viral Math Problem
He is a bit long winded but basically says it can go both ways because of the ambiguity.
Last edit: Chris Roper 2022-05-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yes Chris. I just came across one video and tried it with gcb and got 9, so we know gcb uses div before mult,,yes?
I just use brackets for sums and don't do complicated stuff, I break it down to give the compiler a break,,, it's not psychic,, nor am I so don't know what the compiler "thinks" it should do.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
HP Calculators say the * has presidency over /.
TI Calculators treat them as equal precedence and calculate left to right.
Both consider an implied * if a Number is adjacent to a Brace.
So bottom line which software library are you using.
It is up to the person writing the equation to specify the intent with correct notation and not make assumptions.
That was a good couple of hours diversion, fun and educational though, now back to railway shunting problems :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yeah. I saved a prog last night using cgstudio and it's gone or wasn't saved today. Really pissed cos I was when I coded it and it was working.. plot a sprite or reversed or rotated 90 deg clockwise or 90 deg anti clockwise. It was how you read the sprite table. Is it a gcstudio prob? Yeah, more other stuff to think about.
you can't really check 6/2(1+2) with windows calculator.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Note also that in Windows you forced the Precedence by pressing the "Multiply" key.
On the HP shown it was entered as written without the Multiply symbol the HP then arranged it as shown adding the Multiply itself.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Solved - The HP Calculator has 3 modes that can be changed in the Settings Menu.
Textbook, Algebraic and RPM.
By default it is in Textbook Mode.
Changing the Mode to Algebraic produces this result:
Both results are correct because the equation is ambiguous - Always use Parentheses to force precedence when writing equations, Especially in a programing language.
AS shown above one calculator can show two different results from the same equation depending on the chosen math library.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The equation is ambiguous because there is more than one rule set/method. As I understand it the most common set of rules used after 1917 is called PEMDAS . A google search will provide details. It should not be too hard to follow PEMDAS, once understood, as this seems to be what GCB uses.
When in Rome .......
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This was a youtube vid I saw. What's 6/2(1+2).
I thought it was one but gcb gives the "correct" answer,, needs a space to asm 6/ 2(1+2)
no wonder my code fails sometimes :)
Surely,
6/2*(1+2)
works ? note the*
And, the answer is?
The answer to all of mans problems - unity
Ha ha.. why didn't someone think of that before?
Quote- 42 (or forty-two) is the Answer to the Ultimate Question of Life, the Universe and Everything. This Answer was first calculated by the supercomputer Deep Thought after seven and a half million years of thought :)
GCB flash/hexed 6/ 2(1+2) and gave the "correct" answer.... 9
No 6/2(1+2) needed just a space after6/
It does 6/2=3
(1+2)=3
3 * 3=9.
like (6/2)(1+2)
Interesting and no * needed as real numbers, not vars, like var(1+2) which would be an arrary element.
glcdprint 0,0,str((6/2) (1+2)) gives 0
glcdprint 0,0,str((6/2) * (1+2)) gives 9
Last edit: stan cartwright 2022-05-11
Then GCBASIC has its precedence wrong.
Multiplication should proceed division so the correct result would be :
6 / (2 * ( 1 + 2) =
6 / (2 * 3) =
6 / 6 =
1
That is a prime example why parenthesis should be used extensively in programing, to ensure that the computation follows the order the programmer intended.
Last edit: Chris Roper 2022-05-12
I do not think the precendence is incorrect.
See https://www.google.com/search?q=6%2F2*(1%2B2)&client=ms-android-samsung-ss&sourceid=chrome-mobile&ie=UTF-8&chrome_dse_attribution=1
I was taught BODMAS https://www.twinkl.co.uk/teaching-wiki/bodmas#:~:text=BODMAS%20rule%20is%20an%20acronym,%27
so 6/2(1+2) would be brackets (1+2)=3
division 6/2=3
multiplication 3*(3)=9
I thought mult before divide Chris.
original youtube about 6/2(1+2) https://www.youtube.com/watch?v=URcUvFIUIhQ
Interesting results because an HP 42 calculator Returns an answer of 1.
6 Enter
1 Enter
2 Plus
2 Times
Divide
Maybe I have gone rusty on my calculator use............
Must be old fingers... Excel shows 9 also. :=)
show your working.
I suspect that one of us is entering data into the calculators with the incorrect precedence based on the original post:
6/2(1+2)
is that
(6 / 2)*(1+2)
or
6/(2 * (1+2))
as I said above : "That is a prime example why parenthesis should be used".
Last edit: Chris Roper 2022-05-12
Attached is Excel... I just put the raw calc in there.
So gcb is doing sums correct.
I thought brackets (1+2)=3
2*(3)=6
6/6=1
what have I learnt? and that's using left to right evaluation.
Use braces, brackets, parenthesis so they're first in left to right order.
Then div,mult,add,subtract... is it??
Chris says 1 and I thought that but it's 9 cos div before mult.
Last edit: stan cartwright 2022-05-12
That is the way I see it too.
The problem was ambiguous, hence the point I am trying to make "parenthesis should be used".
If we can't agree on the order of execution how can we expect a compiler to do it?
We are all putting the * where we think it should be but the original problem implied it.
Found this https://youtu.be/Q0przEtP19s - Math Prof answers 6÷2(1+2) = ? once and for all Viral Math Problem
He is a bit long winded but basically says it can go both ways because of the ambiguity.
Last edit: Chris Roper 2022-05-12
yes Chris. I just came across one video and tried it with gcb and got 9, so we know gcb uses div before mult,,yes?
I just use brackets for sums and don't do complicated stuff, I break it down to give the compiler a break,,, it's not psychic,, nor am I so don't know what the compiler "thinks" it should do.
Final comment.
HP Calculators say the * has presidency over /.
TI Calculators treat them as equal precedence and calculate left to right.
Both consider an implied * if a Number is adjacent to a Brace.
So bottom line which software library are you using.
It is up to the person writing the equation to specify the intent with correct notation and not make assumptions.
That was a good couple of hours diversion, fun and educational though, now back to railway shunting problems :)
yeah. I saved a prog last night using cgstudio and it's gone or wasn't saved today. Really pissed cos I was when I coded it and it was working.. plot a sprite or reversed or rotated 90 deg clockwise or 90 deg anti clockwise. It was how you read the sprite table. Is it a gcstudio prob? Yeah, more other stuff to think about.
you can't really check 6/2(1+2) with windows calculator.
From Windows Calculator (Scientific Mode)
Try it on an HP Calculator: https://hpcalcs.com/download/
As an engineer would you trust the Math results from windows over an HP Scientific Calculator?
Note also that in Windows you forced the Precedence by pressing the "Multiply" key.
On the HP shown it was entered as written without the Multiply symbol the HP then arranged it as shown adding the Multiply itself.
Solved - The HP Calculator has 3 modes that can be changed in the Settings Menu.
Textbook, Algebraic and RPM.
By default it is in Textbook Mode.
Changing the Mode to Algebraic produces this result:
So I return to my original conclusion:
Both results are correct because the equation is ambiguous - Always use Parentheses to force precedence when writing equations, Especially in a programing language.
AS shown above one calculator can show two different results from the same equation depending on the chosen math library.
The equation is ambiguous because there is more than one rule set/method. As I understand it the most common set of rules used after 1917 is called PEMDAS . A google search will provide details. It should not be too hard to follow PEMDAS, once understood, as this seems to be what GCB uses.
When in Rome .......