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

  1. /*------------------------------------------------------------------------
  2.  * filename - hypot.cas
  3.  *
  4.  * function(s)
  5.  *        hypot - calculates hypotenuse of right angle
  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.  
  27. Name            hypot - calculates hypotenuse of right angle
  28.  
  29. Usage           double hypot(double x, double y);
  30.  
  31. Prototype in    math.h
  32.  
  33. Description     hypot calculates the value z where
  34.                         z^2 = x^2 + y^2
  35.  
  36.                 This is  equivalent to the   length of the  hypotenuse of a
  37.                 right triangle, if  the lengths of the two sides  are x and
  38.                 y.
  39.  
  40. Return value    hypot returns sqrt (x^2 + y^2);
  41.                 On  error (such  as an  overflow), hypot  returns the value
  42.                 HUGE_VAL, and sets errno to
  43.                         ERANGE  Value out of range
  44.  
  45. *---------------------------------------------------------------------------*/
  46. #pragma warn -rvl
  47.  
  48. double _FARFUNC hypot( double x, double y )
  49. {
  50.         unsigned temp;
  51.  
  52. asm     FLD     DOUBLE (x)
  53. asm     mov     ax, x [6]
  54. asm     FMUL    st, st                  /*      (z.x)^2 */
  55. asm     shl     ax, 1
  56. asm     cmp     ax, 0FFE0h
  57. asm     jnb     hyp_infiniteX
  58.  
  59. asm     FLD     DOUBLE (y)
  60. asm     mov     ax, y [6]
  61. asm     FMUL    st, st                  /*               (z.y)^2        */
  62. asm     shl     ax, 1
  63. asm     cmp     ax, 0FFE0h
  64. asm     jnb     hyp_infiniteY
  65.  
  66. asm     FADD                            /*       --"--  +  --"--        */
  67. asm     FSQRT                           /* sqrt (               )       */
  68. #ifdef __HUGE__
  69. asm     mov     ax, seg HUGE_VAL
  70. asm     mov     es,ax
  71. asm     FCOM    es: DOUBLE (HUGE_VAL)
  72. #else
  73. asm     FCOM    DOUBLE (HUGE_VAL)
  74. #endif
  75. asm     FSTSW   temp
  76. asm     test    temp, 04500H
  77. asm     jz      hyp_infiniteX           /* Result too large for double  */
  78. hyp_end:
  79.         return;
  80.  
  81.  
  82. hyp_infiniteY:
  83. asm     FSTP    st(0)                   /* pop y off stack      */
  84. hyp_infiniteX:
  85. asm     FSTP    st(0)                   /* pop x off stack      */
  86.  
  87. #pragma warn -ret
  88.         return  _matherr (OVERFLOW, "hypot", &x, &y, HUGE_VAL);
  89. #pragma warn .ret
  90. }
  91. #pragma warn .rvl
  92.