From 07e77936d535e58b0aeb4f2a11400c1050556739 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sun, 5 Dec 2021 16:16:21 -0800 Subject: Feat: added math library Used Plan9's libc as starting point. This cleans up dangling references due to loss of libc. --- include/base/math.h | 39 +++++++++++++++++++++++++++++++++++++++ include/base/string.h | 8 +++++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 include/base/math.h (limited to 'include/base') diff --git a/include/base/math.h b/include/base/math.h new file mode 100644 index 0000000..69d344e --- /dev/null +++ b/include/base/math.h @@ -0,0 +1,39 @@ +#pragma once + +double math·NaN(void); +double math·Inf(int); +int math·isNaN(double); +int math·isInf(double, int); +ulong math·umuldiv(ulong, ulong, ulong); +long math·muldiv(long, long, long); + +double math·pow(double, double); +double math·atan2(double, double); +double math·fabs(double); +double math·atan(double); +int math·abs(int); +long math·labs(long); +double math·ldexp(double, int); +double math·log(double); +double math·log10(double); +double math·exp(double); +double math·floor(double); +double math·ceil(double); +double math·sin(double); +double math·cos(double); +double math·tan(double); +double math·asin(double); +double math·acos(double); +double math·sinh(double); +double math·cosh(double); +double math·tanh(double); +double math·sqrt(double); +double math·fmod(double, double); +double math·modf(double, double*); +double math·frexp(double, int*); + +double math·copysign(double, double); + +#define math·HUGE 3.4028234e38 +#define math·PIO2 1.570796326794896619231e0 +#define math·PI (math·PIO2+math·PIO2) diff --git a/include/base/string.h b/include/base/string.h index 238ebf9..a59c553 100644 --- a/include/base/string.h +++ b/include/base/string.h @@ -29,9 +29,15 @@ int str·compare(char *, char *); int str·ncompare(char *, intptr len, char *); int str·ecompare(char *, char *end, char *); -int str·atoi(char *s); +/* old school interfaces (no error checking) */ +long str·atoi(char *s); +double str·atof(char *s); char *str·itoa(char *s, int x); +/* nicer */ +vlong str·asint(char *s, char **end); +double str·asfloat(char *s, char **end); + /* augmented string functions */ string string·makecap(char *s, vlong len, vlong cap); string string·makelen(char *s, vlong len); -- cgit v1.2.1