9base

revived minimalist port of Plan 9 userland to Unix
git clone git://git.suckless.org/9base
Log | Files | Refs | README | LICENSE

math.c (990B)


      1 #include <u.h>
      2 #include <libc.h>
      3 
      4 #include "hoc.h"
      5 
      6 double	errcheck(double, char*);
      7 
      8 double
      9 Log(double x)
     10 {
     11 	return errcheck(log(x), "log");
     12 }
     13 double
     14 Log10(double x)
     15 {
     16 	return errcheck(log10(x), "log10");
     17 }
     18 
     19 double
     20 Sqrt(double x)
     21 {
     22 	return errcheck(sqrt(x), "sqrt");
     23 }
     24 
     25 double
     26 Exp(double x)
     27 {
     28 	return errcheck(exp(x), "exp");
     29 }
     30 
     31 double
     32 Asin(double x)
     33 {
     34 	return errcheck(asin(x), "asin");
     35 }
     36 
     37 double
     38 Acos(double x)
     39 {
     40 	return errcheck(acos(x), "acos");
     41 }
     42 
     43 double
     44 Sinh(double x)
     45 {
     46 	return errcheck(sinh(x), "sinh");
     47 }
     48 double
     49 Cosh(double x)
     50 {
     51 	return errcheck(cosh(x), "cosh");
     52 }
     53 double
     54 Pow(double x, double y)
     55 {
     56 	return errcheck(pow(x,y), "exponentiation");
     57 }
     58 
     59 double
     60 integer(double x)
     61 {
     62 	if(x<-2147483648.0 || x>2147483647.0)
     63 		execerror("argument out of domain", 0);
     64 	return (double)(long)x;
     65 }
     66 
     67 double
     68 errcheck(double d, char* s)	/* check result of library call */
     69 {
     70 	if(isNaN(d))
     71 		execerror(s, "argument out of domain");
     72 	if(isInf(d, 0))
     73 		execerror(s, "result out of range");
     74 	return d;
     75 }