math question

For everything that's not in any way related to PureBasic. General chat etc...
User avatar
J. Baker
Addict
Addict
Posts: 2192
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

math question

Post by J. Baker »

Going through the PureBasic help and came across this.
b = 4 * (2 - (3 - 4))
It says this equals 12 but to me it seems this should equal -4.

Could some one explain why this equals 12?

Here's how I got -4.

b = 4 * (2 - (3 - 4))
b = 4 * (2 - (1))
b = 4 * (-1)
b = -4
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Depends how you evaluate PosVal - NegVal

Maybe

b = 4 * (2 - (3 - 4))
b = 4 * (2 - ( - 1 ))
b = 4 * (2 - - 1)
b = 4 * (3)
b = 12

Edit:

Ie, like signs always add and unlike always subtract
@}--`--,-- A rose by any other name ..
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: math question

Post by jack »

b = 4 * (2 - (3 - 4))
b = 4 * (2 - (1))
b = 4 * (-1)
b = -4
(3-4) --> -1
2-(-1)--> 3
4*3-->12
User avatar
J. Baker
Addict
Addict
Posts: 2192
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

That still don't make sense.
3 - 4 = 1, now if it were 4 - 3, then it would be -1.
Also, 2 - (-1) is -3.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
J. Baker
Addict
Addict
Posts: 2192
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

AHHHHH, I'm thinking backwards. LOL
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

b = 4 * (2 - (3 - 4))

b = 4 * ( 2 - ( -1 ) ) <=>
b = 4 * ( 2 + 1 ) <=>
b = 4 * 3 <=>
b = 12
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

J. Baker wrote:AHHHHH, I'm thinking backwards. LOL
Hehe. :D Big-Endian -v- Little-endian? or FIFO -v- LIFO?
@}--`--,-- A rose by any other name ..
User avatar
J. Baker
Addict
Addict
Posts: 2192
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

LOL, I guess that'll happen when you get four hours sleep in fourty-eight hours. Oh well, it's not the first and probably won't be the last. :wink:
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Post Reply