home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / MATHSRC.ZIP / LOG.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  2.0 KB  |  89 lines

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