RealRTTV / chatcalc

a port of chatcalc to 1.19-1.20
Mozilla Public License 2.0
11 stars 5 forks source link

ChatCalc does not follow the Order of Operations (GEMDAS / PEMDAS) #1

Closed thecolonel63 closed 2 years ago

thecolonel63 commented 2 years ago

The order of operations (GEMDAS / PEMDAS depending on how you were taught it, either way has Grouping, then Exponents, then Multiplication/Division (whichever comes first left to right), then Addition/Subtraction (whichever comes first left to right)) indicates the proper order to process equations in. As such it should be expected that the equation 2*3+1 should result in 7, as 2*3 should be equated before the +1, resulting in 6+1 = 7.

However, chatcalc believes the answer to this is 8, as it processes it as "2 times the sum of 3 and 1", processing purely left to right regardless of the order of operations. This is fine for simple addition and subtraction but severely ruins equations that go beyond this.

An extra example: 2^1+4. As per the order of operations, this translates to ((2^1)+4) which should equal 6. However, once again chatcalc gets it wrong and calculates 1+4 first, turning the equation into 2^5, which results in 32.

One more example: 64^19/60. After passing through the order of operations, this should translate to (((64^1)*9)/60) resulting in 9.6. However, it actually gets processed into (64^(1\(9/60))), resulting in 1.87.

This is a major flaw to an otherwise flawless mod. Please consider taking the time to fix this in a later release.

Edit: Updated to correct for Github styling

RealRTTV commented 2 years ago

there are two different issues here, i first gotta fix 12+4 getting recognized as 1\(2+4), then I have to rework the system to work to use bedmas ordering

RealRTTV commented 2 years ago

wow, i procrastinated this for a month