-
Notifications
You must be signed in to change notification settings - Fork 0
/
testcode.ansll
29 lines (21 loc) · 892 Bytes
/
testcode.ansll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module sample::mathstuff;
import std::units;
import std::trig;
# A standalone unit (e.g. seconds, meters, etc.)
unitdef Chairs;
# A unit that is defined by another (e.g. kilometers, inches, watts, etc.)
unitdef SqChairs Chairs ^^ 2;
# Variables are implicitly 64-bit "doubles" signed floating-point numbers
# But they can be explicitly stated written as if they were a unit
fn calculate($freq Hz) Hz ft
{
# Order of operations, 12 squared then multiply by freq then add 3
$somethin := 3 Hz ft + $freq * 12 ft ^^ 2;
# This would give an error because units don't match
# you can also state a unit for the local variable explicitly (optional)
# > Error cannot add values of unit 'V' and 'V A'
# $wattage W := -2.7 V + 12 V * 15 A;
# If a unit has a direct conversion it can be converted like this:
$meters m := <m>(27 ft);
return $somethin;
}