Basics · 3 of 4
Numbers and units
Lengths and angles carry units, and the compiler checks them:
| Units | For |
|---|---|
nm, um (or µm), mm | lengths |
deg, rad | angles |
The unit follows the number without a space: 500nm, 0.5um, 90deg. The same length can be written in several ways; 0.5um and 500nm are equal.
A number without a unit is not a length. (0, 10) is an error, and the compiler asks "did you mean 10um?". The one exception is a literal 0, which can stand for a zero of any kind: (0, 10um) is fine.
Arithmetic follows the units:
+,-and comparisons need the same kind of value on both sides:1um + 500nmis1.5um, but1um + 2is an error.*and/combine them:3 * 10umis a length,10um / 2umis the plain number 5, and10um * 2umis an area — fine in a calculation, but not as a coordinate.
Every value has a type: integer (3), number (0.5), size (a length), angle, string ("text"), bool (true) or point ((x, y)).
The compiler's suggestions are a starting point, not an answer: for a bare number it always proposes micrometres, which is not always what was meant.
Exercise
The program does not compile. Fix the units so that it draws the three 500 nm wide waveguides the comments describe, 10, 20 and 30 µm long.