<p>I <a href="https://github.com/openscad/openscad/issues/2894" rel="nofollow noreferrer">filed this issue as a bug with the OpenSCAD project</a>, and there is now <a href="https://github.com/openscad/openscad/pull/2895" rel="nofollow noreferrer">a fix merged into master</a>, as well as a test case to prevent regression. The latest nightly builds should handle this correctly from here on out.</p>

CC BY-SA 4.0
2019-04-07T19:56:53.150Z
2019-04-07T19:56:53.150Z
Joel Coehoorn
<p>I suspect the behavior you are seeing is an undocumented feature (aka, bug) of OpenSCAD. I've found in the latest stable release that if the - is placed on either end, the result is -0.5, but in the middle, my results are the same as yours. Surrounding the -2 with parentheses results in a correct answer, however.</p>

<p>It appears that the parentheses turns a mathematical operation into a signed integer. It follows that the operations without the parentheses is right to left:</p>

<p>2/2 = 1, negative 1 with the minus, 2/-1 = -2</p>

CC BY-SA 4.0
2019-03-25T21:17:29.683Z
Filed: https://github.com/openscad/openscad/issues/2894
Joel Coehoorn
CC BY-SA 4.0
2019-04-07T19:48:13.650Z
And there's now a [fix for the issue](https://github.com/openscad/openscad/pull/2895) merged into master. Nightly builds should handle this correctly from here on out.
Joel Coehoorn
CC BY-SA 4.0
2019-03-23T09:33:44.923Z
2019-03-23T09:33:44.923Z
fred_dot_u
<p>Recently I have been doing more complicated math in OpenSCAD and I have run into something that I find strange. Take a simple math expression: <code>2 / 2 / 2</code>. By any programming language this will equal 0.5 (1/2), and OpenSCAD agrees. Something like this: <code>2 / -2 / 2</code> should also be -0.5 for the same reason. However, OpenSCAD thinks this is -2. That is <code>echo(2 / -2 / 2);</code> gives <code>ECHO: -2</code>. My calculator, other programming languages (and myself) all say its -0.5.</p>

<p>Is this a quirk of OpenSCAD, or am I missing something obvious?</p>

CC BY-SA 4.0
2019-03-23T08:46:09.613Z
Check what (2 / -2) gets you
Trish
<openscad>
Why is 2 / -2 / 2 equal to -2 in OpenSCAD? (Mathematical Order of Operations)
AncientRoman
# Why is 2 / -2 / 2 equal to -2 in OpenSCAD? (Mathematical Order of Operations)

(Asked by: username_0 on 2019-03-23)

Recently I have been doing more complicated math in OpenSCAD and I have run into something that I find strange. Take a simple math expression: `2 / 2 / 2`. By any programming language this will equal 0.5 (1/2), and OpenSCAD agrees. Something like this: `2 / -2 / 2` should also be -0.5 for the same reason. However, OpenSCAD thinks this is -2. That is `echo(2 / -2 / 2);` gives `ECHO: -2`. My calculator, other programming languages (and myself) all say its -0.5.

Is this a quirk of OpenSCAD, or am I missing something obvious?

**Tags:** openscad

> **Comments:**
> **username_1**: Check what (2 / -2) gets you  

---

## 2 answers

### Answer by username_3 on 2019-03-23. Score: 8 | Accepted answer

I suspect the behavior you are seeing is an undocumented feature (aka, bug) of OpenSCAD. I've found in the latest stable release that if the - is placed on either end, the result is -0.5, but in the middle, my results are the same as yours. Surrounding the -2 with parentheses results in a correct answer, however.

It appears that the parentheses turns a mathematical operation into a signed integer. It follows that the operations without the parentheses is right to left:

2/2 = 1, negative 1 with the minus, 2/-1 = -2

> **Comments:**
> **username_2**: Filed: https://github.com/openscad/openscad/issues/2894  
> **username_2**: And there's now a [fix for the issue](https://github.com/openscad/openscad/pull/2895) merged into master. Nightly builds should handle this correctly from here on out.  

---

### Answer by username_2 on 2019-04-07. Score: 4

I [filed this issue as a bug with the OpenSCAD project](https://github.com/openscad/openscad/issues/2894), and there is now [a fix merged into master](https://github.com/openscad/openscad/pull/2895), as well as a test case to prevent regression. The latest nightly builds should handle this correctly from here on out.


---

