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

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