Created
April 27, 2017 17:47
-
-
Save andreafioraldi/a5fc7b86201babf7f904764e84397e2d to your computer and use it in GitHub Desktop.
Calculate PI using my own programming language: Stout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Calculate PI using my own programming language: Stout | |
author = Andrea Fioraldi | |
copyright = Copyright 2017, Andrea Fioraldi | |
license = MIT | |
mail = [email protected] | |
*/ | |
use IO; | |
use Math; | |
if(args.Length() < 3) { | |
IO.PrintErr("Usage: ./calculate_pi.dubbel <precision:int> <output_file:string>\n"); | |
return 1; | |
} | |
try precision <- args[1].ToInt(); | |
catch { | |
IO.PrintErr("The precision argument must be an integer\n"); | |
return 1; | |
} | |
output <- args[2]; | |
pi <- Math.GetPI(precision); | |
try file <- new IO.File(output, "w"); | |
catch { | |
IO.PrintErr("Invalid file ", output, "\n"); | |
return 1; | |
} | |
file.Write(pi); | |
file.Close(); | |
IO.Printl("Done."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment