math.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include "hoc.h"
  12. double errcheck(double, char*);
  13. double
  14. Log(double x)
  15. {
  16. return errcheck(log(x), "log");
  17. }
  18. double
  19. Log10(double x)
  20. {
  21. return errcheck(log10(x), "log10");
  22. }
  23. double
  24. Sqrt(double x)
  25. {
  26. return errcheck(sqrt(x), "sqrt");
  27. }
  28. double
  29. Exp(double x)
  30. {
  31. return errcheck(exp(x), "exp");
  32. }
  33. double
  34. Asin(double x)
  35. {
  36. return errcheck(asin(x), "asin");
  37. }
  38. double
  39. Acos(double x)
  40. {
  41. return errcheck(acos(x), "acos");
  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. double
  59. integer(double x)
  60. {
  61. if(x<-2147483648.0 || x>2147483647.0)
  62. execerror("argument out of domain", 0);
  63. return (double)(int32_t)x;
  64. }
  65. double
  66. errcheck(double d, char* s) /* check result of library call */
  67. {
  68. if(isNaN(d))
  69. execerror(s, "argument out of domain");
  70. if(isInf(d, 0))
  71. execerror(s, "result out of range");
  72. return d;
  73. }