From 413f1f19184acd9024b9a97156c467b88ff72484 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 17 Aug 2018 03:57:35 +0200 Subject: math, time, seed and randomness - simple test --- userspace/Makefile | 8 ++++---- userspace/add.c | 41 ----------------------------------------- userspace/crt0.S | 3 --- userspace/task1.c | 1 - userspace/test-math.c | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 36 insertions(+), 49 deletions(-) delete mode 100644 userspace/add.c create mode 100644 userspace/test-math.c (limited to 'userspace') diff --git a/userspace/Makefile b/userspace/Makefile index 62bc857..2812edd 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -1,4 +1,3 @@ - CC=i686-foolos-gcc CC=i686-elf-gcc @@ -12,9 +11,10 @@ CFLAGS+=-g #CFLAGS+=-fstack-protector-all #LDFLAGS=-nostdlib -LDFLAGS=-L/home/miguel/foolos/usr/i686-foolos/lib/ -lc -lm -lg -lnosys +LDFLAGS=-L/home/miguel/foolos/usr/i686-foolos/lib/ +LDLIBS=-lc -lm -lg -lnosys -PROGS=foolshell ls simple brainfuck add checker clear task1 task2 init cat snake +PROGS=foolshell ls simple brainfuck test-math checker clear task1 task2 init cat snake include ../Makefile.common @@ -50,7 +50,7 @@ brainfuck: brainfuck.o snake: snake.o foolshell: foolshell.o simple: simple.o -add: add.o +test-math: test-math.o checker: checker.o task1: task1.o task2: task2.o diff --git a/userspace/add.c b/userspace/add.c deleted file mode 100644 index 94bb244..0000000 --- a/userspace/add.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include -#include "../fs/fs.h" - -int main(int argc, char **argv) -{ - - float sum=0; - float i=0; - - char *buf=malloc(256); - puts("\n*** fools calculator ***"); - - while(1) - { - printf("enter numer (or 'exit' to finish) %i: ",i+1); - fgets(buf,255,stdin); - - if(buf[1]=='x')break; - - i++; - sum+=atoi(buf); - } - - if(i!=0) - { - puts("--------"); - printf("sum = %f \n",sum); - printf("avg = %f \n",sum/i); -// printf("sin(avg) = %f \n\n",sin(sum/i)); - } - - return 0; -} - - - - - diff --git a/userspace/crt0.S b/userspace/crt0.S index 4c08f89..23efec5 100644 --- a/userspace/crt0.S +++ b/userspace/crt0.S @@ -24,6 +24,3 @@ call _exit2 .wait: hlt jmp .wait - -.hellostr: -.ascii "Hello Ass" diff --git a/userspace/task1.c b/userspace/task1.c index d9875f4..793b7f8 100644 --- a/userspace/task1.c +++ b/userspace/task1.c @@ -27,7 +27,6 @@ ULL fib(ULL i) } - int main(unsigned int argc, char **argv) { ULL i=0; diff --git a/userspace/test-math.c b/userspace/test-math.c new file mode 100644 index 0000000..acaecad --- /dev/null +++ b/userspace/test-math.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + time_t ltime; + time(<ime); + printf("the time is %s", ctime(<ime)); + + unsigned int seed=time(NULL); + printf("seed = %u\n",seed); + + srand(seed); + + for(int i=0;i<10;i++) + { + int r=rand()%100; + printf("sin(%i) = %f \n",r,sin(r)); + } + + + return 0; +} + + + + + -- cgit v1.2.3