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

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