-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
kwikius edited this page Sep 7, 2025
·
5 revisions
This page shows example usage of gzScript for units and quantities.
length = 25.4:mm:; // 25.4 mm
distance = 1:m:; // 1 metre
// automatic SI conversion. According to the conversion rules the result has the finest grained unit.
sum = length + distance;
assert ( unit(sum) == :mm:;
assert ( sum == 1025.4:mm);
assert ( numeric_value(sum) == 1025.4);
d = 100:m:;
t = 9.58:s:;
v = d / t; // = 10.44:m/s:;
w = 2:m:;
h = 3:m:;
area = w * h; // = 6:m^2:;
h:height: = 1.75:m:;
w:width: = 0.30:m:;
// ok: assign from anonymous length
h = 2:m:;
// error: width cannot be assigned from height
w = h; // compile error
phi = 180:deg:;
theta = 3.14159:rad:;
// explicit conversion deg → rad
phi_r::rad: = phi;
x = sin(theta); // ok: sin takes an angle as argument
y = sin(0.1); // ok sin takes radian as argument , radian is convertible from numeric
z = sin(phi/2); // ok degrees are an angle
a = 2:ft:;
b = 1:m:;
// result is SI
c = a + b; // 1.6096:m:
force = 10:N:; // newton
area = 2:m^2:;
pressure = force / area; // 5:Pa:
This page is a living draft. More examples will be added as gzScript features evolve.