Small fixes as always, + add pi program
This commit is contained in:
@@ -73,7 +73,7 @@ void program_uptime()
|
||||
|
||||
void program_help()
|
||||
{
|
||||
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\n");
|
||||
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\npi\n");
|
||||
}
|
||||
|
||||
// Panic
|
||||
|
||||
34
src/programs/pi.c
Normal file
34
src/programs/pi.c
Normal file
@@ -0,0 +1,34 @@
|
||||
// Program for Pi computation using Leibniz series
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https://github.com/xamidev/blankos
|
||||
|
||||
#include "../libc/stdio.h"
|
||||
#include "../libc/string.h"
|
||||
|
||||
void program_pi(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("Usage: %s <terms>\n", argv[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
double pi = 0.0;
|
||||
int terms = atoi(argv[1]);
|
||||
|
||||
for (int i=0; i<terms; i++)
|
||||
{
|
||||
double term = 1.0/(2*i+1);
|
||||
if (i%2 == 0)
|
||||
{
|
||||
pi += term;
|
||||
} else {
|
||||
pi -= term;
|
||||
}
|
||||
}
|
||||
|
||||
pi *= 4;
|
||||
|
||||
printf("%f\n", pi);
|
||||
}
|
||||
@@ -31,9 +31,12 @@ void program_primes(int argc, char* argv[])
|
||||
|
||||
for (long long x=0; x<primes_max; x++)
|
||||
{
|
||||
if (isPrime(x))
|
||||
if (isPrime(x) && x != 3301)
|
||||
{
|
||||
printf("%d ", x);
|
||||
} else if(x == 3301)
|
||||
{
|
||||
colorputs("3301 ", red, black);
|
||||
}
|
||||
delay(1);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ void get_meminfo(unsigned int multiboot_info_address);
|
||||
void program_conway();
|
||||
void program_cowsay();
|
||||
void cowsay(); // Splash screen
|
||||
void program_pi();
|
||||
|
||||
// Ciphers
|
||||
void program_rot13();
|
||||
|
||||
Reference in New Issue
Block a user