<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>

[{'answer_id': 8535, 'author': 'fred_dot_u', 'author_id': 854, 'author_profile': 'https://3dprinting.stackexchange.com/users/854', 'pm_score': 4, 'selected': True, 'text': "<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>\n\n<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>\n\n<p>2/2 = 1, negative 1 with the minus, 2/-1 = -2</p>\n"}, {'answer_id': 8640, 'author': 'Joel Coehoorn', 'author_id': 12562, 'author_profile': 'https://3dprinting.stackexchange.com/users/12562', 'pm_score': 2, 'selected': False, 'text': '<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>\n'}]
['https://3dprinting.stackexchange.com/questions/8534', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/14914/']