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

  1. /*------------------------------------------------------------------------
  2.  * filename - sqrt.cas
  3.  *
  4.  * function(s)
  5.  *        sqrt - calculates square root
  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   NANSQRT [4] = {0,0,0x0020, 0x7FF8};
  26.  
  27. /*--------------------------------------------------------------------------*
  28.  
  29. Name            sqrt - calculates square root
  30.  
  31. Usage           double  sqrt (double  x);
  32.  
  33. Prototype in    math.h
  34.  
  35. Description     sqrt calculates the square root of input value.
  36.  
  37. Return value    sqrt returns the square root of input value.
  38.                 If the input  value is lees than 0, sqrt  returns 0 and set
  39.                 errno to
  40.                         EDOM    Domain error
  41. *---------------------------------------------------------------------------*/
  42. #pragma warn -rvl
  43. double  _FARFUNC sqrt (double  x)
  44. {
  45. asm     FLD     DOUBLE (x)
  46.  
  47. asm     mov     ax, x [6]
  48. asm     shl     ax, 1
  49. asm     jz      sqrt_zero
  50. asm     jc      sqrt_imaginary
  51.  
  52. asm     FSQRT
  53.  
  54. sqrt_zero:                      /* zero = sqrt (zero) */
  55. sqrt_end:
  56.         return;
  57.  
  58.  
  59. sqrt_imaginary:
  60. asm     FSTP    st (0)                  /* pop x from stack     */
  61. #pragma warn -ret
  62.         return  _matherr (DOMAIN, "sqrt", &x, NULL, *((double *) NANSQRT));
  63. #pragma warn .ret
  64. }
  65. #pragma warn .rvl
  66.