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

  1. /*------------------------------------------------------------------------
  2.  * filename - tan.cas
  3.  *
  4.  * function(s)
  5.  *        tan - trigonometric tangent 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   NANTRIG [4] = {0,0,0x0420, 0x7FF8};
  26.  
  27. /*--------------------------------------------------------------------------*
  28.  
  29. Name            tan - trigonometric tangent function
  30.  
  31. Usage           double tan(double x);
  32.  
  33. Prototype in    math.h
  34.  
  35. Description     tan  returns the  tangent of  the input  value. Angles  are
  36.                 specified in radians.
  37.  
  38. Return value    tan returns any value for valid angles. For angles close to
  39.                 pi/2 or -pi/2, tan returns 0 and errno is set to
  40.                         ERANGE  Result out of range
  41.                 For very  large arguments (magnitude  2^53 or greater)  all
  42.                 precision is lost. This occurs  "silently" since the ANSI C
  43.                 spec does  not specify an  error return.
  44.  
  45. *---------------------------------------------------------------------------*/
  46. #pragma warn -rvl
  47.  
  48. double _FARFUNC tan( double  x )
  49. {
  50. asm     FLD     DOUBLE (x)
  51.  
  52. asm     mov     ax, 7FF0h
  53. asm     and     ax, W0 (x [6])          /* extract the exponent field */
  54. asm     cmp     ax, (53 * 16) + 3FF0h   /* biased version of exponent 53 */
  55. asm     jae     tan_tooLarge
  56.  
  57. #ifdef _Windows
  58.         _f87_Tangent();
  59. #else
  60.         if (_8087 >= 3)
  61.         {
  62. asm     db      OPCODE_FSINCOS
  63. asm     FDIV
  64.         }
  65.         else
  66.         {
  67. asm     _FAST_  (_FTAN_)
  68.         }
  69. #endif
  70.  
  71. tan_end:
  72.     return;
  73.  
  74.  
  75. tan_tooLarge:                           /* total loss of precision */
  76. asm     FSTP    ST(0)                   /* pop x from stack */
  77.  
  78. #pragma warn -ret
  79.         return  _matherr (TLOSS, "tan", &x, NULL, *((double *) NANTRIG));
  80. #pragma warn .ret
  81. }
  82. #pragma warn .rvl
  83.