Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Harlowe does math wrong

edited May 2015 in Chit-Chat
Take the following math expression:
3 * 3 + 3

You would multiply 3 by 3 first and then add the 3, giving 12.

In Harlowe
(set: $a = 3 * 3 + 3)
(set: $b = 3 + 3 * 3)
$a
$b
Will show as
18
12
Which looks like Harlowe solves math expressions from right to left.

In case you were curious SugerCube and Snowman both works fine with this example:
Snowman
<%
$a = 3 * 3 + 3; print($a + "<br>");
$b = 3 + 3 * 3; print($b);
%> 
12
12
Sugercube
<<set $a to 3 * 3 + 3>>
<<set $b to 3 + 3 * 3>>
$a
$b
12
12

Versions tested:
Harlowe 1.0.1
Snowman 1.0
SugarCube 1.0.23

Comments

  • edited May 2015
    Isn't this why braces are always recommended by default in equations?
  • This is a recognized issue and changed in the 1.1 beta.
  • Ah I see, so all will be good and well.
  • edited May 2015
    Isn't this why braces are always recommended by default in equations?

    Operator precedence is a standard feature in every language. Why would you want to force parenthesis around every single operation when it's not necessary...?
  • AvaJarvis wrote: »
    Isn't this why braces are always recommended by default in equations?

    Operator precedence is a standard feature in every language. Why would you want to force parenthesis around every single operation when it's not necessary...?

    I was always taught never to leave math open for interpretation.
  • I think that operator precedence is like default values for variables, it should not be left up to the language to hopefully get right. I was also taught that if you want to make sure something is definitely correct then you do it yourself. lol
Sign In or Register to comment.