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

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