Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. /* @(#)w_hypot.c 5.1 93/09/24 */
  3. /*
  4.  * ====================================================
  5.  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  6.  *
  7.  * Developed at SunPro, a Sun Microsystems, Inc. business.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software is freely granted, provided that this notice
  10.  * is preserved.
  11.  * ====================================================
  12.  */
  13.  
  14. /*
  15. FUNCTION
  16.         <<hypot>>, <<hypotf>>---distance from origin
  17. INDEX
  18.         hypot
  19. INDEX
  20.         hypotf
  21.  
  22. ANSI_SYNOPSIS
  23.         #include <math.h>
  24.         double hypot(double <[x]>, double <[y]>);
  25.         float hypotf(float <[x]>, float <[y]>);
  26.  
  27. TRAD_SYNOPSIS
  28.         double hypot(<[x]>, <[y]>)
  29.         double <[x]>, <[y]>;
  30.  
  31.         float hypotf(<[x]>, <[y]>)
  32.         float <[x]>, <[y]>;
  33.  
  34. DESCRIPTION
  35.         <<hypot>> calculates the Euclidean distance
  36.         @tex
  37.         $\sqrt{x^2+y^2}$
  38.         @end tex
  39.         @ifnottex
  40.         <<sqrt(<[x]>*<[x]> + <[y]>*<[y]>)>>
  41.         @end ifnottex
  42.         between the origin (0,0) and a point represented by the
  43.         Cartesian coordinates (<[x]>,<[y]>).  <<hypotf>> differs only
  44.         in the type of its arguments and result.
  45.  
  46. RETURNS
  47.         Normally, the distance value is returned.  On overflow,
  48.         <<hypot>> returns <<HUGE_VAL>> and sets <<errno>> to
  49.         <<ERANGE>>.
  50.  
  51.         You can change the error treatment with <<matherr>>.
  52.  
  53. PORTABILITY
  54.         <<hypot>> and <<hypotf>> are not ANSI C.  */
  55.  
  56. /*
  57.  * wrapper hypot(x,y)
  58.  */
  59.  
  60. #define _IEEE_LIBM
  61.  
  62. #include "fdlibm.h"
  63. #include <errno.h>
  64.  
  65. #ifndef _DOUBLE_IS_32BITS
  66.  
  67. #ifdef __STDC__
  68.         double hypot(double x, double y)/* wrapper hypot */
  69. #else
  70.         double hypot(x,y)               /* wrapper hypot */
  71.         double x,y;
  72. #endif
  73. {
  74. #ifdef _IEEE_LIBM
  75.         return __ieee754_hypot(x,y);
  76. #else
  77.         double z;
  78.         struct exception exc;
  79.         z = __ieee754_hypot(x,y);
  80.         if(_LIB_VERSION == _IEEE_) return z;
  81.         if((!finite(z))&&finite(x)&&finite(y)) {
  82.             /* hypot(finite,finite) overflow */
  83. #ifndef HUGE_VAL
  84. #define HUGE_VAL inf
  85.             double inf = 0.0;
  86.  
  87.             SET_HIGH_WORD(inf,0x7ff00000);      /* set inf to infinite */
  88. #endif
  89.             exc.type = OVERFLOW;
  90.             exc.name = "hypot";
  91.             exc.err = 0;
  92.             exc.arg1 = x;
  93.             exc.arg2 = y;
  94.             if (_LIB_VERSION == _SVID_)
  95.                exc.retval = HUGE;
  96.             else
  97.                exc.retval = HUGE_VAL;
  98.             if (_LIB_VERSION == _POSIX_)
  99.                errno = ERANGE;
  100.             else if (!matherr(&exc)) {
  101.                 errno = ERANGE;
  102.             }
  103.             if (exc.err != 0)
  104.                errno = exc.err;
  105.             return exc.retval;
  106.         } else
  107.             return z;
  108. #endif
  109. }
  110.  
  111. #endif /* defined(_DOUBLE_IS_32BITS) */
  112.