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

  1. /*------------------------------------------------------------------------
  2.  * filename - cos.cas
  3.  *
  4.  * function(s)
  5.  *        cos - trigonometric 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        cos - trigonometric function
  32.  
  33. Usage        double cos(double x);
  34.  
  35. Prototype in    math.h
  36.  
  37. Description    cos  returns the  cosine of   the input  value. Angles    are
  38.         specified in radians.
  39.  
  40. Return value    cos returns a value in the range -1 to 1.
  41.         For very  large arguments (magnitude 2^53  radians or more)
  42.         there  is no  precision. This  is "silent",  since the ANSI
  43.         spec allows no error return for this function.
  44.  
  45. *---------------------------------------------------------------------------*/
  46. #pragma warn -rvl
  47. double    cos (double  x)
  48. {
  49. asm    FLD    DOUBLE (x)
  50.  
  51. asm    mov    ax, 7FF0h
  52. asm    and    ax, W0 (x [6])        /* extract the exponent field */
  53. asm    cmp    ax, (53 * 16) + 3FF0h    /* biased version of exponent 53 */
  54. asm    jae    cos_tooLarge
  55.  
  56.     if (_8087 >= 3)
  57.     {
  58. asm    db    OPCODE_FCOS
  59.     }
  60.     else
  61.     {
  62. asm    _FAST_    (_FCOS_)
  63.     }
  64. cos_end:
  65.     return;
  66.  
  67. cos_tooLarge:
  68. asm    FSTP    ST(0)            /* pop x from stack */
  69.  
  70. #pragma    warn -ret
  71.     return    _matherr (TLOSS, "cos", &x, NULL, *(double *) NANTRIG);
  72. #pragma    warn .ret
  73. }
  74. #pragma warn .rvl
  75.