home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / MATH.ZIP / LOG.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.2 KB  |  86 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - log.cas
  3.  *
  4.  * function(s)
  5.  *        log - natural logarithm function
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987, 1990 by Borland International        |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18.  
  19. #pragma inline
  20. #include <asmrules.h>
  21.  
  22. #include <_math.h>
  23. #include <math.h>
  24. #include <errno.h>
  25. #include <stddef.h>
  26.  
  27. static  unsigned short   NANLOG [4] = {0,0,0x0480, 0xFFF0};
  28.  
  29. /*--------------------------------------------------------------------------*
  30.  
  31. Name        log - natural logarithm function
  32.  
  33. Usage        double log(double x);
  34.  
  35. Prototype in    math.h
  36.  
  37. Description    log calculates    the natural logarithm  of x, which  must be
  38.         greater than zero.
  39.  
  40. Return value    log  returns the  natural logarithm   of x,  which must  be
  41.         greater than zero.
  42.  
  43. *---------------------------------------------------------------------------*/
  44. #pragma warn -rvl
  45. #pragma warn -use
  46. double    log (double  x)
  47. {
  48. double    temp;
  49.  
  50. asm    FLD    DOUBLE (x)
  51.  
  52. asm    mov    ax, W0 (x [6])        /* get the exponent field */
  53. asm    shl    ax, 1
  54. asm    jz    log_zero
  55. asm    jc    log_imaginary
  56. asm    cmp    ax, 0FFE0h
  57. asm    je    log_infinite
  58.  
  59. asm    _FAST_    (_FLOG_)
  60.  
  61. log_end:
  62.     return;
  63.  
  64. log_zero:
  65. asm    mov    si, SING
  66.     temp = -HUGE_VAL;
  67. asm    jmp    short    log_complain
  68.  
  69. log_infinite:
  70. asm    mov    si, OVERFLOW
  71.     temp = HUGE_VAL;
  72. asm    jmp    short    log_complain
  73.  
  74. log_imaginary:
  75. asm    mov    si, DOMAIN
  76.     temp = *((double *) NANLOG);
  77.  
  78. log_complain:
  79. asm    FSTP    ST(0)            /* pop x from stack */
  80. #pragma    warn -ret
  81.     return    _matherr (_SI, "log", &x, NULL, temp);
  82. #pragma    warn .ret
  83. }
  84. #pragma warn .rvl
  85. #pragma warn .use
  86.