资料一:
math.h头定义了各种数学函数和一个宏。这个库中所有可用的函数取double参数并返回double的结果。
库宏
只有一个在这个库中定义的宏:
| S.N. | 宏及说明 |
|---|---|
| 1 | HUGE_VAL 当函数结果可能不是一个浮点数表示。正确的结果如果幅度太大,无法表示的功能设置errno为ERANGE表示一个范围错误,并且返回一个特定的值非常大宏HUGE_VAL或其否定( - HUGE_VAL)命名。 如果结果的幅度太小,而不是一个零值,则返回。在这种情况下,将errno可能会或可能不会被设置为ERANGE。 |
库函数
以下是math.h的标头中定义的函数:
| S.N. | 函数及说明 |
|---|---|
| 1 | double acos(double x) 返回x的反余弦弧度。 |
| 2 | double asin(double x) 返回x的正弦弧线弧度。 |
| 3 | double atan(double x) 返回x的反正切值,以弧度为单位。 |
| 4 | double atan2(doubly y, double x) 返回y / x的以弧度为单位的反正切值,根据这两个值,以确定正确的象限上的标志。 |
| 5 | double cos(double x) 返回的弧度角x的余弦值。 |
| 6 | double cosh(double x) 返回x的双曲余弦。 |
| 7 | double sin(double x) 返回一个弧度角x的正弦。 |
| 8 | double sinh(double x) 返回x的双曲正弦。 |
| 9 | double tanh(double x) 返回x的双曲正切。 |
| 10 | double exp(double x) 返回e值的第x次幂。 |
| 11 | double frexp(double x, int *exponent) The returned value is the mantissa and the integer yiibaied to by exponent is the exponent. The resultant value is x = mantissa * 2 ^ exponent. |
| 12 | double ldexp(double x, int exponent) Returns x multiplied by 2 raised to the power of exponent. |
| 13 | double log(double x) 返回自然对数的x(基准-E对数)。 |
| 14 | double log10(double x) 返回x的常用对数(以10为底)。 |
| 15 | double modf(double x, double *integer) 返回的值是小数成分(小数点后的部分),并设置整数的整数部分。 |
| 16 | double pow(double x, double y) 返回x的y次方。 |
| 17 | double sqrt(double x) 返回x的平方根。 |
| 18 | double ceil(double x) 返回大于或等于x的最小整数值。 |
| 19 | double fabs(double x) 返回x的绝对值 |
| 20 | double floor(double x) 返回的最大整数值小于或等于x。 |
| 21 | double fmod(double x, double y) 返回的x除以y的余数。 |
资料二:
<cmath> (math.h)
C numerics library
Header
<cmath> declares a set of functions to compute common mathematical operations and transformations:
Functions
Trigonometric functions
-
cos
- Compute cosine (function )
-
sin
- Compute sine (function )
-
tan
- Compute tangent (function )
-
acos
- Compute arc cosine (function )
-
asin
- Compute arc sine (function )
-
atan
- Compute arc tangent (function )
-
atan2
- Compute arc tangent with two parameters (function )
Hyperbolic functions
-
cosh
- Compute hyperbolic cosine (function )
-
sinh
- Compute hyperbolic sine (function )
-
tanh
- Compute hyperbolic tangent (function )
-
acosh
- Compute area hyperbolic cosine (function )
-
asinh
- Compute area hyperbolic sine (function )
-
atanh
- Compute area hyperbolic tangent (function )
Exponential and logarithmic functions
-
exp
- Compute exponential function (function )
-
frexp
- Get significand and exponent (function )
-
ldexp
- Generate value from significand and exponent (function )
-
log
- Compute natural logarithm (function )
-
log10
- Compute common logarithm (function )
-
modf
- Break into fractional and integral parts (function )
-
exp2
- Compute binary exponential function (function )
-
expm1
- Compute exponential minus one (function )
-
ilogb
- Integer binary logarithm (function )
-
log1p
- Compute logarithm plus one (function )
-
log2
- Compute binary logarithm (function )
-
logb
- Compute floating-point base logarithm (function )
-
scalbn
- Scale significand using floating-point base exponent (function )
-
scalbln
- Scale significand using floating-point base exponent (long) (function )
Power functions
-
pow
- Raise to power (function )
-
sqrt
- Compute square root (function )
-
cbrt
- Compute cubic root (function )
-
hypot
- Compute hypotenuse (function )
Error and gamma functions
-
erf
- Compute error function (function )
-
erfc
- Compute complementary error function (function )
-
tgamma
- Compute gamma function (function )
-
lgamma
- Compute log-gamma function (function )
Rounding and remainder functions
-
ceil
- Round up value (function )
-
floor
- Round down value (function )
-
fmod
- Compute remainder of division (function )
-
trunc
- Truncate value (function )
-
round
- Round to nearest (function )
-
lround
- Round to nearest and cast to long integer (function )
-
llround
- Round to nearest and cast to long long integer (function )
-
rint
- Round to integral value (function )
-
lrint
- Round and cast to long integer (function )
-
llrint
- Round and cast to long long integer (function )
-
nearbyint
- Round to nearby integral value (function )
-
remainder
- Compute remainder (IEC 60559) (function )
-
remquo
- Compute remainder and quotient (function )
Floating-point manipulation functions
-
copysign
- Copy sign (function )
-
nan
- Generate quiet NaN (function )
-
nextafter
- Next representable value (function )
-
nexttoward
- Next representable value toward precise value (function )
Minimum, maximum, difference functions
-
fdim
- Positive difference (function )
-
fmax
- Maximum value (function )
-
fmin
- Minimum value (function )
Other functions
-
fabs
- Compute absolute value (function )
-
abs
- Compute absolute value (function )
-
fma
- Multiply-add (function )
Macros / Functions
These are implemented as macros in C and as functions in C++:Classification macro / functions
-
fpclassify
- Classify floating-point value (macro/function )
-
isfinite
- Is finite value (macro )
-
isinf
- Is infinity (macro/function )
-
isnan
- Is Not-A-Number (macro/function )
-
isnormal
- Is normal (macro/function )
-
signbit
- Sign bit (macro/function )
Comparison macro / functions
-
isgreater
- Is greater (macro )
-
isgreaterequal
- Is greater or equal (macro )
-
isless
- Is less (macro )
-
islessequal
- Is less or equal (macro )
-
islessgreater
- Is less or greater (macro )
-
isunordered
- Is unordered (macro )
Macro constants
-
math_errhandling
- Error handling (macro )
-
INFINITY
- Infinity (constant )
-
NAN
- Not-A-Number (constant )
-
HUGE_VAL
- Huge value (constant )
-
HUGE_VALF
- Huge float value
-
HUGE_VALL
- Huge long double value (constant )
This header also defines the following macro constants (since C99/C++11):
| macro | type | description |
|---|---|---|
| MATH_ERRNO MATH_ERREXCEPT | int | Bitmask value with the possible values math_errhandling can take. |
| FP_FAST_FMA FP_FAST_FMAF FP_FAST_FMAL | int | Each, if defined, identifies for which type fma is at least as efficient as x*y+z. |
| FP_INFINITE FP_NAN FP_NORMAL FP_SUBNORMAL FP_ZERO | int | The possible values returned by fpclassify. |
| FP_ILOGB0 FP_ILOGBNAN | int | Special values the ilogb function may return. |
Types
-
double_t
- Floating-point type (type )
-
float_t
- Floating-point type (type )
资料三:
Standard library header <cmath>
This header was originally in the C standard library as <math.h>.
This header is part of the numeric library.
Macro constants
|
(C++11)(C++11)
| indicates the overflow value for float, double and long double respectively (macro constant) |
|
(C++11)
| evaluates to positive infinity or the value guaranteed to overflow a float (macro constant) |
|
(C++11)
| evaluates to a quiet NaN of type float (macro constant) |
|
(C++11)(C++11)(C++11)
| defines the error handling mechanism used by the common mathematical functions (macro constant) |
Classification | |
|
(C++11)(C++11)(C++11)(C++11)(C++11)
| indicates a floating-point category (macro constant) |
Types
|
float_t
(C++11)
| most efficient floating-point type at least as wide as float (typedef) |
|
double_t
(C++11)
| most efficient floating-point type at least as wide as double (typedef) |
Functions
Basic operations | |
| absolute value of a floating point value (|x|) (function) | |
| remainder of the floating point division operation (function) | |
|
(C++11)
| signed remainder of the division operation (function) |
|
(C++11)
| signed remainder as well as the three last bits of the division operation (function) |
|
(C++11)
| fused multiply-add operation (function) |
|
(C++11)
| larger of two floating point values (function) |
|
(C++11)
| smaller of two floating point values (function) |
|
(C++11)
| positive difference of two floating point values (max(0, x-y)) (function) |
|
(C++11)(C++11)(C++11)
| not-a-number (NaN) (function) |
Exponential functions | |
| returns e raised to the given power (ex) (function) | |
|
(C++11)
| returns 2 raised to the given power (2x) (function) |
|
(C++11)
| returns e raised to the given power, minus one (ex-1) (function) |
| computes natural (base e) logarithm (to base e) (ln(x)) (function) | |
| computes common (base 10) logarithm (log10(x)) (function) | |
|
(C++11)
| base 2 logarithm of the given number (log2(x)) (function) |
|
(C++11)
| natural logarithm (to base e) of 1 plus the given number (ln(1+x)) (function) |
Power functions | |
| raises a number to the given power (xy) (function) | |
| computes square root (√x) (function) | |
|
(C++11)
| computes cubic root (3√x) (function) |
|
(C++11)
| computes square root of the sum of the squares of two given numbers (√x2 +y2 ) (function) |
Trigonometric functions | |
| computes sine (sin(x)) (function) | |
| computes cosine (cos(x)) (function) | |
| computes tangent (tan(x)) (function) | |
| computes arc sine (arcsin(x)) (function) | |
| computes arc cosine (arccos(x)) (function) | |
| computes arc tangent (arctan(x)) (function) | |
| arc tangent, using signs to determine quadrants (function) | |
Hyperbolic functions | |
| computes hyperbolic sine (sh(x)) (function) | |
| computes hyperbolic cosine (ch(x)) (function) | |
| hyperbolic tangent (function) | |
|
(C++11)
| computes the inverse hyperbolic sine (arsinh(x)) (function) |
|
(C++11)
| computes the inverse hyperbolic cosine (arcosh(x)) (function) |
|
(C++11)
| computes the inverse hyperbolic tangent (artanh(x)) (function) |
Error and gamma functions | |
|
(C++11)
| error function (function) |
|
(C++11)
| complementary error function (function) |
|
(C++11)
| gamma function (function) |
|
(C++11)
| natural logarithm of the gamma function (function) |
Nearest integer floating point operations | |
| nearest integer not less than the given value (function) | |
| nearest integer not greater than the given value (function) | |
|
(C++11)
| nearest integer not greater in magnitude than the given value (function) |
|
(C++11)(C++11)(C++11)
| nearest integer, rounding away from zero in halfway cases (function) |
|
(C++11)
| nearest integer using current rounding mode (function) |
|
(C++11)(C++11)(C++11)
| nearest integer using current rounding mode with exception if the result differs (function) |
Floating point manipulation functions | |
| decomposes a number into significand and a power of 2 (function) | |
| multiplies a number by 2 raised to a power (function) | |
| decomposes a number into integer and fractional parts (function) | |
|
(C++11)(C++11)
| multiplies a number by FLT_RADIX raised to a power (function) |
|
(C++11)
| extracts exponent of the number (function) |
|
(C++11)
| extracts exponent of the number (function) |
|
(C++11)(C++11)
| next representable floating point value towards the given value (function) |
|
(C++11)
| copies the sign of a floating point value (function) |
Classification and comparison | |
|
(C++11)
| categorizes the given floating point value (function) |
|
(C++11)
| checks if the given number has finite value (function) |
|
(C++11)
| checks if the given number is infinite (function) |
|
(C++11)
| checks if the given number is NaN (function) |
|
(C++11)
| checks if the given number is normal (function) |
|
(C++11)
| checks if the given number is negative (function) |
|
(C++11)
| checks if the first floating-point argument is greater than the second (function) |
|
(C++11)
| checks if the first floating-point argument is greater or equal than the second (function) |
|
(C++11)
| checks if the first floating-point argument is less than the second (function) |
|
(C++11)
| checks if the first floating-point argument is less or equal than the second (function) |
|
(C++11)
| checks if the first floating-point argument is less or greater than the second (function) |
|
(C++11)
| checks if two floating-point values are unordered (function) |
本文详细介绍了math.h头文件中的宏定义、三角函数、指数与对数函数等数学运算功能,以及C++标准库<cmath>提供的高级数学函数。
1万+

被折叠的 条评论
为什么被折叠?



