diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/cmd/hoc/math.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/cmd/hoc/math.c')
-rwxr-xr-x | sys/src/cmd/hoc/math.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/sys/src/cmd/hoc/math.c b/sys/src/cmd/hoc/math.c new file mode 100755 index 000000000..a45458380 --- /dev/null +++ b/sys/src/cmd/hoc/math.c @@ -0,0 +1,75 @@ +#include <u.h> +#include <libc.h> + +#include "hoc.h" + +double errcheck(double, char*); + +double +Log(double x) +{ + return errcheck(log(x), "log"); +} +double +Log10(double x) +{ + return errcheck(log10(x), "log10"); +} + +double +Sqrt(double x) +{ + return errcheck(sqrt(x), "sqrt"); +} + +double +Exp(double x) +{ + return errcheck(exp(x), "exp"); +} + +double +Asin(double x) +{ + return errcheck(asin(x), "asin"); +} + +double +Acos(double x) +{ + return errcheck(acos(x), "acos"); +} + +double +Sinh(double x) +{ + return errcheck(sinh(x), "sinh"); +} +double +Cosh(double x) +{ + return errcheck(cosh(x), "cosh"); +} +double +Pow(double x, double y) +{ + return errcheck(pow(x,y), "exponentiation"); +} + +double +integer(double x) +{ + if(x<-2147483648.0 || x>2147483647.0) + execerror("argument out of domain", 0); + return (double)(long)x; +} + +double +errcheck(double d, char* s) /* check result of library call */ +{ + if(isNaN(d)) + execerror(s, "argument out of domain"); + if(isInf(d, 0)) + execerror(s, "result out of range"); + return d; +} |