parent
bf83ceee87
commit
ec25a3cbf0
6 changed files with 87 additions and 8 deletions
@ -0,0 +1,21 @@ |
||||
<?php |
||||
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php'; |
||||
|
||||
use PhpAot\Php\Translator; |
||||
|
||||
if (empty($argv[1])) { |
||||
die("php compiler.php [file]\n"); |
||||
} |
||||
|
||||
try { |
||||
$file = $argv[1]; |
||||
$translator = new Translator(); |
||||
$info = pathinfo($file); |
||||
$objectFile = './tmp/' . $info['filename'] . '.cc.o'; |
||||
$translator->compileBinary($info['filename'], $objectFile); |
||||
} catch (Error $error) { |
||||
echo "Parse error: {$error->getMessage()}\n"; |
||||
return; |
||||
} |
||||
@ -0,0 +1,16 @@ |
||||
"use strict"; |
||||
|
||||
let fs = require("fs"); |
||||
let rounds = parseInt(fs.readFileSync("./rounds.txt", "utf8")); |
||||
|
||||
let x = 1.0; |
||||
let pi = 1.0; |
||||
|
||||
for (let i = 2; i < rounds + 2; i++) { |
||||
x *= -1; |
||||
pi += x / (2 * i - 1); |
||||
} |
||||
|
||||
pi *= 4; |
||||
|
||||
console.log(pi); |
||||
@ -0,0 +1,25 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"os" |
||||
"strconv" |
||||
"strings" |
||||
) |
||||
|
||||
func main() { |
||||
file, _ := os.ReadFile("rounds.txt") |
||||
rounds, _ := strconv.Atoi(strings.TrimSpace(string(file))) |
||||
|
||||
x := 1.0 |
||||
pi := 1.0 |
||||
stop := float64(rounds + 2) |
||||
|
||||
for i := 2.0; i <= stop; i++ { |
||||
x = -x |
||||
pi += x / (2.0*i - 1.0) |
||||
} |
||||
|
||||
pi *= 4.0 |
||||
fmt.Println(pi) |
||||
} |
||||
Loading…
Reference in new issue