<p>Within OpenSCAD expressions, the order of precedence is:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Operators</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>() []</td>
<td>group, vector, or range</td>
</tr>
<tr>
<td>() [] .</td>
<td>function call, indexing, member lookup</td>
</tr>
<tr>
<td>^</td>
<td>exponentiation</td>
</tr>
<tr>
<td>! + -</td>
<td>unary operations</td>
</tr>
<tr>
<td>* / %</td>
<td>multiplication</td>
</tr>
<tr>
<td>+ -</td>
<td>addition</td>
</tr>
<tr>
<td>&lt; &lt;= &gt;= &gt;</td>
<td>ordering</td>
</tr>
<tr>
<td>== !=</td>
<td>equality</td>
</tr>
<tr>
<td>&amp;&amp;</td>
<td>logical AND</td>
</tr>
<tr>
<td>||</td>
<td>logical OR</td>
</tr>
<tr>
<td>?: function() let() assert() echo()</td>
<td>ternary operator and unary pseudo-operators</td>
</tr>
</tbody>
</table>
</div>
<p>There are no bit-wise operators, and neither comma nor &quot;=&quot; are operators.</p>
<p>Source: <a href="https://github.com/openscad/openscad/blob/master/src/parser.y" rel="noreferrer">openscad/src/parser.y</a></p>

CC BY-SA 4.0
2022-01-03T23:13:40.290Z
2022-01-03T23:19:48.943Z
2022-01-03T23:19:48.943Z
Curt
<p><a href="https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Mathematical_Operators" rel="noreferrer">OpenSCAD User Manual's section on operators</a> does not mention precedence. Quick Web searches found nothing. I assume the usual order of exponentiation, then multiplication, then addition does hold, but how does e.g. a conditional operator or unary minus interact with these? Is there an official document describing the precedence of operators in OpenSCAD?</p>

CC BY-SA 4.0
2021-09-28T02:12:07.730Z
I'm not sure if/where it's documented but I think largely they follow C or C++ precedent for precedence.
R.. GitHub STOP HELPING ICE
CC BY-SA 4.0
2021-09-28T11:39:14.023Z
If you aren't sure, use parenthesis to force precedence.
0scar
CC BY-SA 4.0
2021-09-28T12:55:32.877Z
@0scar That's what I'm doing, but it would be nice to know.
user31389
<openscad>
What is the operator precedence in OpenSCAD?
user31389
# What is the operator precedence in OpenSCAD?

(Asked by: username_0 on 2021-09-27)

[OpenSCAD User Manual's section on operators](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Mathematical_Operators) does not mention precedence. Quick Web searches found nothing. I assume the usual order of exponentiation, then multiplication, then addition does hold, but how does e.g. a conditional operator or unary minus interact with these? Is there an official document describing the precedence of operators in OpenSCAD?

**Tags:** openscad
> **Comments:**
> **username_1**: I'm not sure if/where it's documented but I think largely they follow C or C++ precedent for precedence.  
> **username_2**: If you aren't sure, use parenthesis to force precedence.  
> **username_0**: @0scar That's what I'm doing, but it would be nice to know.  

---

## 1 answers

### Answer by username_3 on 2022-01-03. Score: 6 | Accepted answer

Within OpenSCAD expressions, the order of precedence is:

| Operators | Description |
| --- | --- |
| () [] | group, vector, or range |
| () [] . | function call, indexing, member lookup |
| ^ | exponentiation |
| ! + - | unary operations |
| \* / % | multiplication |
| + - | addition |
| < <= >= > | ordering |
| == != | equality |
| && | logical AND |
| || | logical OR |
| ?: function() let() assert() echo() | ternary operator and unary pseudo-operators |

There are no bit-wise operators, and neither comma nor "=" are operators.

Source: [openscad/src/parser.y](https://github.com/openscad/openscad/blob/master/src/parser.y)


---

