Overview
/
KCL Language Reference
/
Arithmetic and logic

Arithmetic and logic

KCL supports the usual arithmetic operators on numbers and logic operators on booleans:

OperatorMeaning
+Addition
-Subtraction or unary negation
*Multiplication
/Division
%Modulus aka remainder
^Power, e.g., x ^ 2 means x squared
&Logical 'and'
|Logical 'or'
!Unary logical 'not'

KCL also supports comparison operators which produce booleans. Ordering comparisons operate on numbers, while == and != operate on numbers or strings:

OperatorMeaning
==Equal
!=Not equal
<Less than
>Greater than
<=Less than or equal
>=Greater than or equal

String equality is exact and case-sensitive. It does not perform Unicode normalization.

Arithmetics and logic expressions can be arbitrairly combined with the usual rules of associativity and precedence, e.g.,

You can also nest expressions in parenthesis:

KCL numbers are implemented using floating point numbers. This means that there are occasionally representation and rounding issues, and some oddities such as supporting positive and negative zero.

Some operators can be applied to other types:

  • + can be used to concatenate strings, e.g., 'hello' + ' ' + 'world!'
  • Unary - can be used with planes or line-like objects such as axes to produce an object with opposite orientation, e.g., -XY is a plain which is aligned with XY but whose normal aligns with the negative Z axis.
  • The following operators can be used with solids as shorthand for CSG operations: