diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-03-13 20:59:41 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-03-13 20:59:41 -0400 |
commit | 8ab5902d2cb66809d478ef795a878a413dea41cc (patch) | |
tree | a2d4f9cba84dbb481d4c988537f608c8e788f710 /num.c |
migrate to gitlab
Diffstat (limited to 'num.c')
-rw-r--r-- | num.c | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -0,0 +1,50 @@ +#include "bc.h" +#include <math.h> +#include <stdlib.h> +#include <stdio.h> + +bc_num zero; + +bc_num *bc_new(const char *str) +{ + if (str == NULL) { + return &zero; + } + + bc_num *num = calloc(1, sizeof(*num)); + num->n = atoi(str); + return num; +} + +int bc_toint(bc_num *num) +{ + return num->n; +} + +bc_num *bc_print(bc_num *num) +{ + printf("%"PRIdMAX"\n", num->n); + return num; +} + +bc_num *bc_length(bc_num *a) +{ + return a; +} + +bc_num *bc_sqrt(bc_num *a) +{ + bc_num *root = calloc(1, sizeof(*root)); + root->n = sqrt(a->n); + return root; +} + +bc_num *bc_scale(bc_num *a) +{ + return a; +} + +void bc_free(bc_num *n) +{ + free(n); +} |