OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libm/] [math/] [w_atan2.c] - Diff between revs 56 and 57

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 56 Rev 57
 
 
/* @(#)w_atan2.c 5.1 93/09/24 */
/* @(#)w_atan2.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
        <<atan2>>, <<atan2f>>---arc tangent of y/x
        <<atan2>>, <<atan2f>>---arc tangent of y/x
 
 
INDEX
INDEX
   atan2
   atan2
INDEX
INDEX
   atan2f
   atan2f
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double atan2(double <[y]>,double <[x]>);
        double atan2(double <[y]>,double <[x]>);
        float atan2f(float <[y]>,float <[x]>);
        float atan2f(float <[y]>,float <[x]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double atan2(<[y]>,<[x]>);
        double atan2(<[y]>,<[x]>);
        double <[y]>;
        double <[y]>;
        double <[x]>;
        double <[x]>;
 
 
        float atan2f(<[y]>,<[x]>);
        float atan2f(<[y]>,<[x]>);
        float <[y]>;
        float <[y]>;
        float <[x]>;
        float <[x]>;
 
 
DESCRIPTION
DESCRIPTION
 
 
<<atan2>> computes the inverse tangent (arc tangent) of <[y]>/<[x]>.
<<atan2>> computes the inverse tangent (arc tangent) of <[y]>/<[x]>.
<<atan2>> produces the correct result even for angles near
<<atan2>> produces the correct result even for angles near
@ifinfo
@ifinfo
pi/2 or -pi/2
pi/2 or -pi/2
@end ifinfo
@end ifinfo
@tex
@tex
$\pi/2$ or $-\pi/2$
$\pi/2$ or $-\pi/2$
@end tex
@end tex
(that is, when <[x]> is near 0).
(that is, when <[x]> is near 0).
 
 
<<atan2f>> is identical to <<atan2>>, save that it takes and returns
<<atan2f>> is identical to <<atan2>>, save that it takes and returns
<<float>>.
<<float>>.
 
 
RETURNS
RETURNS
<<atan2>> and <<atan2f>> return a value in radians, in the range of
<<atan2>> and <<atan2f>> return a value in radians, in the range of
@ifinfo
@ifinfo
-pi to pi.
-pi to pi.
@end ifinfo
@end ifinfo
@tex
@tex
$-\pi$ to $\pi$.
$-\pi$ to $\pi$.
@end tex
@end tex
 
 
If both <[x]> and <[y]> are 0.0, <<atan2>> causes a <<DOMAIN>> error.
If both <[x]> and <[y]> are 0.0, <<atan2>> causes a <<DOMAIN>> error.
 
 
You can modify error handling for these functions using <<matherr>>.
You can modify error handling for these functions using <<matherr>>.
 
 
PORTABILITY
PORTABILITY
<<atan2>> is ANSI C.  <<atan2f>> is an extension.
<<atan2>> is ANSI C.  <<atan2f>> is an extension.
 
 
 
 
*/
*/
 
 
/*
/*
 * wrapper atan2(y,x)
 * wrapper atan2(y,x)
 */
 */
 
 
#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 atan2(double y, double x)        /* wrapper atan2 */
        double atan2(double y, double x)        /* wrapper atan2 */
#else
#else
        double atan2(y,x)                       /* wrapper atan2 */
        double atan2(y,x)                       /* wrapper atan2 */
        double y,x;
        double y,x;
#endif
#endif
{
{
#ifdef _IEEE_LIBM
#ifdef _IEEE_LIBM
        return __ieee754_atan2(y,x);
        return __ieee754_atan2(y,x);
#else
#else
        double z;
        double z;
        struct exception exc;
        struct exception exc;
        z = __ieee754_atan2(y,x);
        z = __ieee754_atan2(y,x);
        if(_LIB_VERSION == _IEEE_||isnan(x)||isnan(y)) return z;
        if(_LIB_VERSION == _IEEE_||isnan(x)||isnan(y)) return z;
        if(x==0.0&&y==0.0) {
        if(x==0.0&&y==0.0) {
            /* atan2(+-0,+-0) */
            /* atan2(+-0,+-0) */
            exc.arg1 = y;
            exc.arg1 = y;
            exc.arg2 = x;
            exc.arg2 = x;
            exc.type = DOMAIN;
            exc.type = DOMAIN;
            exc.name = "atan2";
            exc.name = "atan2";
            exc.err = 0;
            exc.err = 0;
            exc.retval = 0.0;
            exc.retval = 0.0;
            if(_LIB_VERSION == _POSIX_)
            if(_LIB_VERSION == _POSIX_)
               errno = EDOM;
               errno = EDOM;
            else if (!matherr(&exc)) {
            else if (!matherr(&exc)) {
               errno = EDOM;
               errno = EDOM;
            }
            }
            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.