OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libm/] [math/] [w_hypot.c] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
 
 
/* @(#)w_hypot.c 5.1 93/09/24 */
/* @(#)w_hypot.c 5.1 93/09/24 */
/*
/*
 * ====================================================
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * software is freely granted, provided that this notice
 * is preserved.
 * is preserved.
 * ====================================================
 * ====================================================
 */
 */
 
 
/*
/*
FUNCTION
FUNCTION
        <<hypot>>, <<hypotf>>---distance from origin
        <<hypot>>, <<hypotf>>---distance from origin
INDEX
INDEX
        hypot
        hypot
INDEX
INDEX
        hypotf
        hypotf
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double hypot(double <[x]>, double <[y]>);
        double hypot(double <[x]>, double <[y]>);
        float hypotf(float <[x]>, float <[y]>);
        float hypotf(float <[x]>, float <[y]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        double hypot(<[x]>, <[y]>)
        double hypot(<[x]>, <[y]>)
        double <[x]>, <[y]>;
        double <[x]>, <[y]>;
 
 
        float hypotf(<[x]>, <[y]>)
        float hypotf(<[x]>, <[y]>)
        float <[x]>, <[y]>;
        float <[x]>, <[y]>;
 
 
DESCRIPTION
DESCRIPTION
        <<hypot>> calculates the Euclidean distance
        <<hypot>> calculates the Euclidean distance
        @tex
        @tex
        $\sqrt{x^2+y^2}$
        $\sqrt{x^2+y^2}$
        @end tex
        @end tex
        @ifnottex
        @ifnottex
        <<sqrt(<[x]>*<[x]> + <[y]>*<[y]>)>>
        <<sqrt(<[x]>*<[x]> + <[y]>*<[y]>)>>
        @end ifnottex
        @end ifnottex
        between the origin (0,0) and a point represented by the
        between the origin (0,0) and a point represented by the
        Cartesian coordinates (<[x]>,<[y]>).  <<hypotf>> differs only
        Cartesian coordinates (<[x]>,<[y]>).  <<hypotf>> differs only
        in the type of its arguments and result.
        in the type of its arguments and result.
 
 
RETURNS
RETURNS
        Normally, the distance value is returned.  On overflow,
        Normally, the distance value is returned.  On overflow,
        <<hypot>> returns <<HUGE_VAL>> and sets <<errno>> to
        <<hypot>> returns <<HUGE_VAL>> and sets <<errno>> to
        <<ERANGE>>.
        <<ERANGE>>.
 
 
        You can change the error treatment with <<matherr>>.
        You can change the error treatment with <<matherr>>.
 
 
PORTABILITY
PORTABILITY
        <<hypot>> and <<hypotf>> are not ANSI C.  */
        <<hypot>> and <<hypotf>> are not ANSI C.  */
 
 
/*
/*
 * wrapper hypot(x,y)
 * wrapper hypot(x,y)
 */
 */
 
 
#include "fdlibm.h"
#include "fdlibm.h"
#include <errno.h>
#include <errno.h>
 
 
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
 
 
#ifdef __STDC__
#ifdef __STDC__
        double hypot(double x, double y)/* wrapper hypot */
        double hypot(double x, double y)/* wrapper hypot */
#else
#else
        double hypot(x,y)               /* wrapper hypot */
        double hypot(x,y)               /* wrapper hypot */
        double x,y;
        double x,y;
#endif
#endif
{
{
#ifdef _IEEE_LIBM
#ifdef _IEEE_LIBM
        return __ieee754_hypot(x,y);
        return __ieee754_hypot(x,y);
#else
#else
        double z;
        double z;
        struct exception exc;
        struct exception exc;
        z = __ieee754_hypot(x,y);
        z = __ieee754_hypot(x,y);
        if(_LIB_VERSION == _IEEE_) return z;
        if(_LIB_VERSION == _IEEE_) return z;
        if((!finite(z))&&finite(x)&&finite(y)) {
        if((!finite(z))&&finite(x)&&finite(y)) {
            /* hypot(finite,finite) overflow */
            /* hypot(finite,finite) overflow */
#ifndef HUGE_VAL 
#ifndef HUGE_VAL 
#define HUGE_VAL inf
#define HUGE_VAL inf
            double inf = 0.0;
            double inf = 0.0;
 
 
            SET_HIGH_WORD(inf,0x7ff00000);      /* set inf to infinite */
            SET_HIGH_WORD(inf,0x7ff00000);      /* set inf to infinite */
#endif
#endif
            exc.type = OVERFLOW;
            exc.type = OVERFLOW;
            exc.name = "hypot";
            exc.name = "hypot";
            exc.err = 0;
            exc.err = 0;
            exc.arg1 = x;
            exc.arg1 = x;
            exc.arg2 = y;
            exc.arg2 = y;
            if (_LIB_VERSION == _SVID_)
            if (_LIB_VERSION == _SVID_)
               exc.retval = HUGE;
               exc.retval = HUGE;
            else
            else
               exc.retval = HUGE_VAL;
               exc.retval = HUGE_VAL;
            if (_LIB_VERSION == _POSIX_)
            if (_LIB_VERSION == _POSIX_)
               errno = ERANGE;
               errno = ERANGE;
            else if (!matherr(&exc)) {
            else if (!matherr(&exc)) {
                errno = ERANGE;
                errno = ERANGE;
            }
            }
            if (exc.err != 0)
            if (exc.err != 0)
               errno = exc.err;
               errno = exc.err;
            return exc.retval;
            return exc.retval;
        } else
        } else
            return z;
            return z;
#endif
#endif
}
}
 
 
#endif /* defined(_DOUBLE_IS_32BITS) */
#endif /* defined(_DOUBLE_IS_32BITS) */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.