blob: bb0f9726f4b5c6aaeaaa100b8ea447cf5f0cf73b (
plain)
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
29
30
31
32
33
34
35
|
#include "std/io.toc";
Point ::= struct {
x, y: float;
}
sqrt ::= fn(x: float) a := x/2 {
q ::= x;
y ::= a;
for _ := 0..20 {
a = (x + a * a) / (2 * a);
}
}
normalize ::= fn(p: &Point) {
use p;
sqdist := x * x + y * y;
one_over_dist := 1/sqrt(sqdist);
x *= one_over_dist;
y *= one_over_dist;
}
printf ::= #foreign("printf", "libc.so.6") fn(#C &"const char", #C ..);
main ::= fn() {
p: Point;
use p;
x = 10;
y = 20;
normalize(&p);
fmt := "%f %f\n\0";
printf(&fmt[0], p.x, p.y);
}
|