Skip to content

Commit c3db5f0

Browse files
committed
Feature: README - write example with PI calculation
1 parent 1a25d15 commit c3db5f0

3 files changed

Lines changed: 47 additions & 4 deletions

File tree

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,49 @@ For latest stable version:
1313
npm install -g static-script
1414
```
1515

16+
# Let's write simple example
17+
18+
Put it in `calculate-pi.ts`
19+
20+
```ts
21+
{
22+
function calculatePI(cycles: number): number {
23+
let inside = 0;
24+
25+
for (let i = 0; i < cycles; i++) {
26+
let x = Math.random() * 2 - 1;
27+
let y = Math.random() * 2 - 1;
28+
29+
if ((x*x + y*y) < 1) {
30+
inside++
31+
}
32+
}
33+
34+
return 4.0 * inside / cycles;
35+
}
36+
37+
console_log(calculatePI(100000));
38+
}
39+
```
40+
41+
Next compile it:
42+
43+
```sh
44+
$ ./bin/ssc calculate-pi.ts
45+
```
46+
47+
Next run it:
48+
49+
```sh
50+
$ ./output/main
51+
```
52+
53+
This will produce:
54+
55+
```
56+
3.141560
57+
```
58+
1659
### LICENSE
1760

1861
This project is open-sourced software licensed under the MIT License.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"commander": "^2.19.0"
2626
},
2727
"dependencies": {
28-
"@static-script/runtime": "^0.7.0",
28+
"@static-script/runtime": "^0.8.0",
2929
"llvm-node": "github:MichaReiser/llvm-node#master",
3030
"typescript": "^3.1.1"
3131
}

0 commit comments

Comments
 (0)