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/] [common/] [s_log2.c] - Diff between revs 207 and 345

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

Rev 207 Rev 345
/* @(#)s_log2.c 5.1 93/09/24 */
/* @(#)s_log2.c 5.1 93/09/24 */
/* Modification from s_exp10.c Yaakov Selkowitz 2009.  */
/* Modification from s_exp10.c Yaakov Selkowitz 2009.  */
 
 
/*
/*
 * ====================================================
 * ====================================================
 * 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
        <<log2>>, <<log2f>>--base 2 logarithm
        <<log2>>, <<log2f>>--base 2 logarithm
INDEX
INDEX
        log2
        log2
INDEX
INDEX
        log2f
        log2f
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <math.h>
        #include <math.h>
        double log2(double <[x]>);
        double log2(double <[x]>);
        float log2f(float <[x]>);
        float log2f(float <[x]>);
 
 
DESCRIPTION
DESCRIPTION
The <<log2>> functions compute the base-2 logarithm of <[x]>.  A domain error
The <<log2>> functions compute the base-2 logarithm of <[x]>.  A domain error
occurs if the argument is less than zero.  A range error occurs if the
occurs if the argument is less than zero.  A range error occurs if the
argument is zero.
argument is zero.
 
 
The Newlib implementations are not full, intrinisic calculations, but
The Newlib implementations are not full, intrinisic calculations, but
rather are derivatives based on <<log>>.  (Accuracy might be slightly off from
rather are derivatives based on <<log>>.  (Accuracy might be slightly off from
a direct calculation.)  In addition to functions, they are also implemented as
a direct calculation.)  In addition to functions, they are also implemented as
macros defined in math.h:
macros defined in math.h:
. #define log2(x) (log (x) / _M_LOG2_E)
. #define log2(x) (log (x) / _M_LOG2_E)
. #define log2f(x) (logf (x) / (float) _M_LOG2_E)
. #define log2f(x) (logf (x) / (float) _M_LOG2_E)
To use the functions instead, just undefine the macros first.
To use the functions instead, just undefine the macros first.
 
 
You can use the (non-ANSI) function <<matherr>> to specify error
You can use the (non-ANSI) function <<matherr>> to specify error
handling for these functions, indirectly through the respective <<log>>
handling for these functions, indirectly through the respective <<log>>
function.
function.
 
 
RETURNS
RETURNS
The <<log2>> functions return
The <<log2>> functions return
@ifnottex
@ifnottex
<<log base-2(<[x]>)>>
<<log base-2(<[x]>)>>
@end ifnottex
@end ifnottex
@tex
@tex
$log_2(x)$
$log_2(x)$
@end tex
@end tex
on success.
on success.
When <[x]> is zero, the
When <[x]> is zero, the
returned value is <<-HUGE_VAL>> and <<errno>> is set to <<ERANGE>>.
returned value is <<-HUGE_VAL>> and <<errno>> is set to <<ERANGE>>.
When <[x]> is negative, the returned value is NaN (not a number) and
When <[x]> is negative, the returned value is NaN (not a number) and
<<errno>> is set to <<EDOM>>.  You can control the error behavior via
<<errno>> is set to <<EDOM>>.  You can control the error behavior via
<<matherr>>.
<<matherr>>.
 
 
PORTABILITY
PORTABILITY
C99, POSIX, System V Interface Definition (Issue 6).
C99, POSIX, System V Interface Definition (Issue 6).
*/
*/
 
 
/*
/*
 * wrapper log2(x)
 * wrapper log2(x)
 */
 */
 
 
#include "fdlibm.h"
#include "fdlibm.h"
#include <errno.h>
#include <errno.h>
#include <math.h>
#include <math.h>
#undef log2
#undef log2
 
 
#ifndef _DOUBLE_IS_32BITS
#ifndef _DOUBLE_IS_32BITS
 
 
#ifdef __STDC__
#ifdef __STDC__
        double log2(double x)           /* wrapper log2 */
        double log2(double x)           /* wrapper log2 */
#else
#else
        double log2(x)                  /* wrapper log2 */
        double log2(x)                  /* wrapper log2 */
        double x;
        double x;
#endif
#endif
{
{
  return (log(x) / M_LOG2_E);
  return (log(x) / M_LOG2_E);
}
}
 
 
#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.