home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / MATHSRC.ZIP / COS.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  1.9 KB  |  79 lines

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