math.h
来自「DVB软件,基于CT216软件的开发源程序.」· C头文件 代码 · 共 645 行 · 第 1/2 页
H
645 行
#ifndef CYGONCE_LIBM_MATH_H
#define CYGONCE_LIBM_MATH_H
//===========================================================================
//
// math.h
//
// Standard mathematical functions conforming to ANSI and other standards
//
//===========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
// Copyright (C) 2004, 2005 eCosCentric Limited
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//===========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): jlarmour
// Contributors: jlarmour
// Date: 1998-02-13
// Purpose:
// Description: Standard mathematical functions. These can be
// configured to conform to ANSI section 7.5. There are also
// a number of extensions conforming to IEEE-754 and behaviours
// compatible with other standards
// Usage: #include <math.h>
//
//####DESCRIPTIONEND####
//
//===========================================================================
// CONFIGURATION
#include <pkgconf/libm.h> // Configuration header
// INCLUDES
#include <cyg/infra/cyg_type.h> // Common type definitions and support
#include <float.h> // Properties of FP representation on this
// platform
#include <sys/ieeefp.h> // Cyg_libm_ieee_double_shape_type
// CONSTANT DEFINITIONS
// HUGE_VAL is a positive double (not necessarily representable as a float)
// representing infinity as specified in ANSI 7.5. __infinity is
// defined further down.
// Don't remove the line break. It's there to avoid an unnecessary "fixincludes"
// with GCC 3.3.
#ifndef HUGE_VAL
#define \
HUGE_VAL (__infinity[0].value)
#endif
/* HUGE_VALF is the equivalent of HUGE_VAL, but for floats */
#ifndef HUGE_VALF
# define HUGE_VALF (__infinityf[0].value)
#endif
#ifndef CYGSYM_LIBM_NO_XOPEN_SVID_NAMESPACE_POLLUTION
// HUGE is defined in System V Interface Definition 3 (SVID3) as the largest
// finite single precision number
#define HUGE FLT_MAX // from float.h
// Values used in the type field of struct exception below
#define DOMAIN 1
#define SING 2
#define OVERFLOW 3
#define UNDERFLOW 4
#define TLOSS 5
#define PLOSS 6
// TYPE DEFINITIONS
// Things required to support matherr() ( see comments in <pkgconf/libm.h>)
// The following sentence is required to prevent the compiler "fixincluding"
// this header: "We have a problem when using C++". The sentence is clearly
// rubbish as we are safe with C++!
#ifdef __cplusplus
struct __math_exception {
#else
struct exception {
#endif
int type; // One of DOMAIN, SING, OVERFLOW, UNDERFLOW, TLOSS, PLOSS
char *name; // Name of the function generating the exception
double arg1; // First argument to the function
double arg2; // Second argument to the function
double retval; // Value to be returned - can be altered by matherr()
int err;
};
#endif // ifndef CYGSYM_LIBM_NO_XOPEN_SVID_NAMESPACE_POLLUTION
// GLOBALS
/* Declare this as an array without bounds so that no matter what small data
support a port and/or library has, this reference will be via the general
method for accessing globals. */
__externC const Cyg_libm_ieee_double_shape_type __infinity[];
__externC const Cyg_libm_ieee_float_shape_type __infinityf[];
//===========================================================================
// FUNCTION PROTOTYPES
// Functions not part of a standard
// This retrieves a pointer to the current compatibility mode of the Math
// library. See <pkgconf/libm.h> for the definition of Cyg_libm_compat_t
#ifdef CYGSEM_LIBM_THREAD_SAFE_COMPAT_MODE
__externC Cyg_libm_compat_t
cyg_libm_get_compat_mode( void );
__externC Cyg_libm_compat_t
cyg_libm_set_compat_mode( Cyg_libm_compat_t );
#else
__externC Cyg_libm_compat_t cygvar_libm_compat_mode;
// Defined as static inline as it is unlikely that anyone wants to take the
// address of these functions.
//
// This returns the current compatibility mode
static __inline__ Cyg_libm_compat_t
cyg_libm_get_compat_mode( void )
{
return cygvar_libm_compat_mode;
}
// This sets the compatibility mode, and returns the previous mode
static __inline__ Cyg_libm_compat_t
cyg_libm_set_compat_mode( Cyg_libm_compat_t math_compat_mode)
{
Cyg_libm_compat_t oldmode;
oldmode = cygvar_libm_compat_mode;
cygvar_libm_compat_mode = math_compat_mode;
return oldmode;
}
#endif // ifdef CYGSEM_LIBM_THREAD_SAFE_COMPAT_MODE
#ifdef CYGSEM_LIBM_THREAD_SAFE_GAMMA_FUNCTIONS
// FIXME: these need to be documented and signgam mentioned as non-ISO
// This returns the address of the signgam variable used by the gamma*() and
// lgamma*() functions
__externC int *
cyg_libm_get_signgam_p( void );
#define signgam (*cyg_libm_get_signgam_p())
#else
__externC int signgam;
#endif // ifdef CYGSEM_LIBM_THREAD_SAFE_GAMMA_FUNCTIONS
//===========================================================================
// Standard ANSI functions. Angles are always in radians
// Trigonometric functions - ANSI 7.5.2
__externC double
acos( double ); // arc cosine i.e. inverse cos
__externC double
asin( double ); // arc sine i.e. inverse sin
__externC double
atan( double ); // arc tan i.e. inverse tan
__externC double
atan2( double, double ); // arc tan of (first arg/second arg) using signs
// of args to determine quadrant
__externC double
cos( double ); // cosine
__externC double
sin( double ); // sine
__externC double
tan( double ); // tangent
// Hyperbolic functions - ANSI 7.5.3
__externC double
cosh( double ); // hyperbolic cosine
__externC double
sinh( double ); // hyperbolic sine
__externC double
tanh( double ); // hyperbolic tangent
// Exponential and Logarithmic Functions - ANSI 7.5.4
__externC double
exp( double ); // exponent
__externC double
frexp( double, int * ); // break number into normalized fraction (returned)
// and integral power of 2 (second arg)
__externC double
ldexp( double, int ); // multiples number by integral power of 2
/* Need to undefine "log" as some other headers (yes you, FreeBSD networking) define it
* for completely different purposes. This way as long as no-one actually tries to _use_
* it for BSD logging, the correct thing will happen, otherwise it's an error. */
#undef log
__externC double
log( double ); // natural logarithm
__externC double
log10( double ); // base ten logarithm
__externC double
modf( double, double * ); // break number into integral and fractional
// parts, each of which has same sign as arg.
// It returns signed fractional part, and
// puts integral part in second arg
// Power Functions - ANSI 7.5.5
__externC double
pow( double, double ); // (1st arg) to the power of (2nd arg)
__externC double
sqrt( double ); // square root
// Nearest integer, absolute value and remainder functions - ANSI 7.5.6
__externC double
ceil( double ); // smallest integer >= arg
__externC double
fabs( double ); // absolute value
__externC double
floor( double ); // largest integer <= arg
__externC double
fmod( double, double ); // remainder of (1st arg)/(2nd arg)
/*=========================================================================*/
#ifndef __STRICT_ANSI__
/* ISO C99 types and macros. */
#ifndef FLT_EVAL_METHOD
#define FLT_EVAL_METHOD 0
typedef float float_t;
typedef double double_t;
#endif /* FLT_EVAL_METHOD */
#define FP_NAN 0
#define FP_INFINITE 1
#define FP_ZERO 2
#define FP_SUBNORMAL 3
#define FP_NORMAL 4
extern int __fpclassifyf (float x);
extern int __fpclassifyd (double x);
extern int __signbitf (float x);
extern int __signbitd (double x);
#define fpclassify(x) \
(__extension__ ({__typeof__(x) __x = (x); \
(sizeof (__x) == sizeof (float)) ? __fpclassifyf(__x) : __fpclassifyd(__x);}))
#define isfinite(x) \
(__extension__ ({__typeof__(x) __x = (x); \
fpclassify(__x) != FP_INFINITE && fpclassify(__x) != FP_NAN;}))
#define isnormal(x) \
(__extension__ ({__typeof__(x) __x = (x); \
fpclassify(__x) == FP_NORMAL;}))
#define signbit(x) \
(__extension__ ({__typeof__(x) __x = (x); \
(sizeof(__x) == sizeof(float)) ? __signbitf(__x) : __signbitd(__x);}))
#define isgreater(x,y) \
(__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
!isunordered(__x,__y) && (__x > __y);}))
#define isgreaterequal(x,y) \
(__extension__ ({__typeof__(x) __x = (x); __typeof__(y) __y = (y); \
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?