Difference between revisions of "cpp/numeric/math/acos"
From cppreference.com
Andreas Krug (Talk | contribs) m (,) |
m (fmt) |
||
Line 2: | Line 2: | ||
{{cpp/numeric/math/navbar}} | {{cpp/numeric/math/navbar}} | ||
{{dcl begin}} | {{dcl begin}} | ||
− | {{dcl header | cmath}} | + | {{dcl header|cmath}} |
{{dcl rev multi|num=1 | {{dcl rev multi|num=1 | ||
|until1=|dcl1= | |until1=|dcl1= | ||
Line 9: | Line 9: | ||
float acosf( float arg ); | float acosf( float arg ); | ||
}} | }} | ||
− | {{dcl |num=2| | + | {{dcl|num=2| |
double acos ( double arg ); | double acos ( double arg ); | ||
}} | }} | ||
Line 18: | Line 18: | ||
long double acosl( long double arg ); | long double acosl( long double arg ); | ||
}} | }} | ||
− | {{dcl |num=4|since=c++11 | | + | {{dcl|num=4|since=c++11| |
double acos ( IntegralType arg ); | double acos ( IntegralType arg ); | ||
}} | }} | ||
Line 28: | Line 28: | ||
===Parameters=== | ===Parameters=== | ||
{{par begin}} | {{par begin}} | ||
− | {{par | arg | value of a floating-point or [[cpp/types/is_integral|Integral type]]}} | + | {{par|arg|value of a floating-point or [[cpp/types/is_integral|Integral type]]}} |
{{par end}} | {{par end}} | ||
Line 34: | Line 34: | ||
If no errors occur, the arc cosine of {{tt|arg}} ({{math|arccos(arg)}}) in the range {{math|[0, π]}}, is returned. | If no errors occur, the arc cosine of {{tt|arg}} ({{math|arccos(arg)}}) in the range {{math|[0, π]}}, is returned. | ||
− | If a domain error occurs, an implementation-defined value is returned (NaN where supported) | + | If a domain error occurs, an implementation-defined value is returned (NaN where supported). |
If a range error occurs due to underflow, the correct result (after rounding) is returned. | If a range error occurs due to underflow, the correct result (after rounding) is returned. | ||
Line 46: | Line 46: | ||
* If the argument is {{math|+1}}, the value {{tt|+0}} is returned. | * If the argument is {{math|+1}}, the value {{tt|+0}} is returned. | ||
* If {{math|{{!}}arg{{!}} > 1}}, a domain error occurs and NaN is returned. | * If {{math|{{!}}arg{{!}} > 1}}, a domain error occurs and NaN is returned. | ||
− | * if the argument is NaN, NaN is returned | + | * if the argument is NaN, NaN is returned. |
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | + | |code= | |
#include <cerrno> | #include <cerrno> | ||
#include <cfenv> | #include <cfenv> | ||
Line 57: | Line 57: | ||
#include <iostream> | #include <iostream> | ||
− | #pragma STDC FENV_ACCESS ON | + | // #pragma STDC FENV_ACCESS ON |
+ | |||
int main() | int main() | ||
{ | { | ||
std::cout << "acos(-1) = " << acos(-1) << '\n' | std::cout << "acos(-1) = " << acos(-1) << '\n' | ||
− | << "acos(0.0) = " << acos(0.0) << " 2*acos(0.0) = " << 2*acos(0) << '\n' | + | << "acos(0.0) = " << acos(0.0) << " 2*acos(0.0) = " << 2 * acos(0) << '\n' |
− | << "acos(0.5) = " << acos(0.5) << " 3*acos(0.5) = " << 3*acos(0.5) << '\n' | + | << "acos(0.5) = " << acos(0.5) << " 3*acos(0.5) = " << 3 * acos(0.5) << '\n' |
<< "acos(1) = " << acos(1) << '\n'; | << "acos(1) = " << acos(1) << '\n'; | ||
// error handling | // error handling | ||
Line 73: | Line 74: | ||
std::cout << " FE_INVALID raised" << '\n'; | std::cout << " FE_INVALID raised" << '\n'; | ||
} | } | ||
− | + | |output= | |
acos(-1) = 3.14159 | acos(-1) = 3.14159 | ||
acos(0.0) = 1.5708 2*acos(0.0) = 3.14159 | acos(0.0) = 1.5708 2*acos(0.0) = 3.14159 | ||
Line 85: | Line 86: | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc inc | cpp/numeric/math/dsc asin}} | + | {{dsc inc|cpp/numeric/math/dsc asin}} |
− | {{dsc inc | cpp/numeric/math/dsc atan}} | + | {{dsc inc|cpp/numeric/math/dsc atan}} |
− | {{dsc inc | cpp/numeric/math/dsc atan2}} | + | {{dsc inc|cpp/numeric/math/dsc atan2}} |
− | {{dsc inc | cpp/numeric/math/dsc cos}} | + | {{dsc inc|cpp/numeric/math/dsc cos}} |
− | {{dsc inc | cpp/numeric/complex/dsc acos}} | + | {{dsc inc|cpp/numeric/complex/dsc acos}} |
− | {{dsc inc | cpp/numeric/valarray/dsc acos}} | + | {{dsc inc|cpp/numeric/valarray/dsc acos}} |
− | {{dsc see c | c/numeric/math/acos}} | + | {{dsc see c|c/numeric/math/acos}} |
{{dsc end}} | {{dsc end}} | ||
{{langlinks|de|es|fr|it|ja|pl|pt|ru|zh}} | {{langlinks|de|es|fr|it|ja|pl|pt|ru|zh}} |
Revision as of 15:38, 14 March 2023
Defined in header <cmath>
|
||
(1) | ||
float acos ( float arg ); |
||
float acosf( float arg ); |
(since C++11) | |
double acos ( double arg ); |
(2) | |
(3) | ||
long double acos ( long double arg ); |
||
long double acosl( long double arg ); |
(since C++11) | |
double acos ( IntegralType arg ); |
(4) | (since C++11) |
1-3) Computes the principal value of the arc cosine of
arg
.4) A set of overloads or a function template accepting an argument of any integral type. Equivalent to 2) (the argument is cast to double).
Contents |
Parameters
arg | - | value of a floating-point or Integral type |
Return value
If no errors occur, the arc cosine of arg
(arccos(arg)) in the range [0, π], is returned.
If a domain error occurs, an implementation-defined value is returned (NaN where supported).
If a range error occurs due to underflow, the correct result (after rounding) is returned.
Error handling
Errors are reported as specified in math_errhandling.
Domain error occurs if arg
is outside the range [-1.0, 1.0]
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
- If the argument is +1, the value
+0
is returned. - If |arg| > 1, a domain error occurs and NaN is returned.
- if the argument is NaN, NaN is returned.
Example
Run this code
#include <cerrno> #include <cfenv> #include <cmath> #include <cstring> #include <iostream> // #pragma STDC FENV_ACCESS ON int main() { std::cout << "acos(-1) = " << acos(-1) << '\n' << "acos(0.0) = " << acos(0.0) << " 2*acos(0.0) = " << 2 * acos(0) << '\n' << "acos(0.5) = " << acos(0.5) << " 3*acos(0.5) = " << 3 * acos(0.5) << '\n' << "acos(1) = " << acos(1) << '\n'; // error handling errno = 0; std::feclearexcept(FE_ALL_EXCEPT); std::cout << "acos(1.1) = " << acos(1.1) << '\n'; if (errno == EDOM) std::cout << " errno == EDOM: " << std::strerror(errno) << '\n'; if (std::fetestexcept(FE_INVALID)) std::cout << " FE_INVALID raised" << '\n'; }
Output:
acos(-1) = 3.14159 acos(0.0) = 1.5708 2*acos(0.0) = 3.14159 acos(0.5) = 1.0472 3*acos(0.5) = 3.14159 acos(1) = 0 acos(1.1) = nan errno == EDOM: Numerical argument out of domain FE_INVALID raised
See also
(C++11)(C++11) |
computes arc sine (arcsin(x)) (function) |
(C++11)(C++11) |
computes arc tangent (arctan(x)) (function) |
(C++11)(C++11) |
arc tangent, using signs to determine quadrants (function) |
(C++11)(C++11) |
computes cosine (cos(x)) (function) |
(C++11) |
computes arc cosine of a complex number (arccos(z)) (function template) |
applies the function std::acos to each element of valarray (function template) | |
C documentation for acos
|