log.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. *
  5. * Author: Ceriel J.H. Jacobs
  6. */
  7. /* $Id$ */
  8. #define __NO_DEFS
  9. #include <math.h>
  10. double
  11. _log(x)
  12. double x;
  13. {
  14. /* Algorithm and coefficients from:
  15. "Software manual for the elementary functions"
  16. by W.J. Cody and W. Waite, Prentice-Hall, 1980
  17. */
  18. static double a[] = {
  19. -0.64124943423745581147e2,
  20. 0.16383943563021534222e2,
  21. -0.78956112887491257267e0
  22. };
  23. static double b[] = {
  24. -0.76949932108494879777e3,
  25. 0.31203222091924532844e3,
  26. -0.35667977739034646171e2,
  27. 1.0
  28. };
  29. extern double _fef();
  30. double znum, zden, z, w;
  31. int exponent;
  32. if (x <= 0) {
  33. error(3);
  34. return -HUGE;
  35. }
  36. x = _fef(x, &exponent);
  37. if (x > M_1_SQRT2) {
  38. znum = (x - 0.5) - 0.5;
  39. zden = x * 0.5 + 0.5;
  40. }
  41. else {
  42. znum = x - 0.5;
  43. zden = znum * 0.5 + 0.5;
  44. exponent--;
  45. }
  46. z = znum/zden; w = z * z;
  47. x = z + z * w * (POLYNOM2(w,a)/POLYNOM3(w,b));
  48. z = exponent;
  49. x += z * (-2.121944400546905827679e-4);
  50. return x + z * 0.693359375;
  51. }