home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / MATHSRC.ZIP / HYPOTL.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  2.3 KB  |  78 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - hypotl.cas
  3.  *
  4.  * function(s)
  5.  *        hypotl - calculates hypotlenuse of right angle (long double)
  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.  
  24. /*--------------------------------------------------------------------------*
  25.  
  26. Name            hypotl - calculates hypotlenuse of right angle
  27.  
  28. Usage           long double hypotl(long double x, long double y);
  29.  
  30. Prototype in    math.h
  31.  
  32. Description     hypotl calculates the value z where
  33.                         z^2 = x^2 + y^2
  34.  
  35.                 This is  equivalent to the length of the hypotenuse of a
  36.                 right triangle, if  the lengths of the two sides are x and
  37.                 y.
  38.  
  39. Return value    hypotl returns sqrt (x^2 + y^2). On error (such as an
  40.                 overflow), hypotl  returns the value _LHUGE_VAL, and
  41.                 sets errno to:
  42.                         ERANGE  Value out of range
  43.  
  44. *---------------------------------------------------------------------------*/
  45. #pragma warn -rvl
  46. #pragma warn -ret
  47. long double  hypotl (long double x, long double y)
  48. {
  49. asm     FLD     LONGDOUBLE (x)
  50. asm     mov     ax, x [8]               /* fetch exponent               */
  51. asm     and     ax, 07fffh
  52. asm     cmp     ax,1fffh+3fffh          /* exponent >= 1fffH (biased)?  */
  53. asm     jae     hyp_infiniteX
  54. asm     FMUL    st, st
  55.  
  56. asm     FLD     LONGDOUBLE (y)
  57. asm     mov     ax, y [8]               /* fetch exponent               */
  58. asm     and     ax, 07fffh
  59. asm     cmp     ax,1fffh+3fffh          /* exponent >= 1fffH (biased)?  */
  60. asm     jae     hyp_infiniteY
  61. asm     FMUL    st, st
  62.  
  63. asm     FADD
  64. asm     FSQRT
  65.  
  66.         return;
  67.  
  68. hyp_infiniteY:
  69. asm     FSTP    st(0)                   /* pop y off stack      */
  70. hyp_infiniteX:
  71. asm     FSTP    st(0)                   /* pop x off stack      */
  72.  
  73.          return  __matherrl (OVERFLOW, "hypotl", &x, &y, _LHUGE_VAL);
  74. }
  75. #pragma warn .ret
  76. #pragma warn .rvl
  77.  
  78.