YouTip LogoYouTip

Cpp Libs Cmath

The C++ standard library provides a rich set of features, and `` is a header file containing mathematical functions that provides many basic mathematical operations and constants. `` is a header file in the C++ standard library that defines a set of mathematical functions that can perform basic mathematical operations such as power operations, trigonometric functions, logarithms, absolute values, etc. To use the functions in ``, you need to include this header file in your C++ program: #include ## Common Functions `` provides many mathematical functions, and here are some commonly used functions. ### 1. Basic Mathematical Functions | Function | Description | Example | | --- | --- | --- | | `abs(x)` | Calculate the absolute value of integer `x` | `abs(-5) // 5` | | `fabs(x)` | Calculate the absolute value of floating-point `x` | `fabs(-5.5) // 5.5` | | `fmod(x, y)` | Calculate the remainder of `x` divided by `y` | `fmod(5.3, 2) // 1.3` | | `remainder(x, y)` | Calculate the remainder of `x` divided by `y` | `remainder(5.5, 2) // 1.5` | | `fmax(x, y)` | Return the larger value between `x` and `y` | `fmax(3.5, 4.2) // 4.2` | | `fmin(x, y)` | Return the smaller value between `x` and `y` | `fmin(3.5, 4.2) // 3.5` | | `hypot(x, y)` | Calculate `sqrt(x*x + y*y)` | `hypot(3, 4) // 5` | ### 2. Exponential and Logarithmic Functions | Function | Description | Example | | --- | --- | --- | | `exp(x)` | Calculate `e^x`, where `e` is the base of natural logarithm | `exp(1) // 2.71828...` | | `log(x)` | Calculate the natural logarithm of `x` | `log(2.71828) // 1` | | `log10(x)` | Calculate the base-10 logarithm of `x` | `log10(100) // 2` | | `pow(x, y)` | Calculate `x` raised to the power of `y` | `pow(2, 3) // 8` | | `sqrt(x)` | Calculate the square root of `x` | `sqrt(16) // 4` | | `cbrt(x)` | Calculate the cube root of `x` | `cbrt(27) // 3` | | `expm1(x)` | Calculate `e^x - 1` | `expm1(1) // 1.71828...` | | `log1p(x)` | Calculate `log(1 + x)`, suitable for x close to 0 | `log1p(0.00001) // 0.00001` | ### 3. Trigonometric Functions | Function | Description | Example | | --- | --- | --- | | `sin(x)` | Calculate the sine of `x`, where `x` is in radians | `sin(3.14159 / 2) // 1` | | `cos(x)` | Calculate the cosine of `x`, where `x` is in radians | `cos(3.14159) // -1` | | `tan(x)` | Calculate the tangent of `x`, where `x` is in radians | `tan(0) // 0` | | `asin(x)` | Calculate the arcsine of `x`, returns radians | `asin(1) // 3.14159/2` | | `acos(x)` | Calculate the arccosine of `x`, returns radians | `acos(-1) // 3.14159` | | `atan(x)` | Calculate the arctangent of `x`, returns radians | `atan(1) // 3.14159/4` | | `atan2(y, x)` | Calculate the arctangent of `y/x`, returns radians | `atan2(1, 1) // 3.14159/4` | ### 4. Hyperbolic Functions | Function | Description | Example | | --- | --- | --- | | `sinh(x)` | Calculate the hyperbolic sine of `x` | `sinh(0) // 0` | | `cosh(x)` | Calculate the hyperbolic cosine of `x` | `cosh(0) // 1` | | `tanh(x)` | Calculate the hyperbolic tangent of `x` | `tanh(1) // 0.7616` | | `asinh(x)` | Calculate the inverse hyperbolic sine of `x` | `asinh(1) // 0.8814` | | `acosh(x)` | Calculate the inverse hyperbolic cosine of `x`, `x` β‰₯ 1 | `acosh(1) // 0` | | `atanh(x)` | Calculate the inverse hyperbolic tangent of `x`, `x` in (-1, 1) | `atanh(0.5) // 0.5493` | ### 5. Rounding and Floating-Point Operations | Function | Description | Example | | --- | --- | --- | | `ceil(x)` | Return the smallest integer not less than `x` | `ceil(2.3) // 3`
← Cpp Libs RegexCpp Libs Complex β†’