C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- 容å¨åº
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- æ°å¼åº
- å¸¸ç¨æ°å¦å½æ°
- std::abs(int), std::labs, std::llabs, std::imaxabs
- std::div, std::ldiv, std::lldiv
- std::fmod, std::fmodf, std::fmodl
- std::remainder, std::remainderf, std::remainderl
- std::remquo, std::remquof, std::remquol
- std::hypot, std::hypotf, std::hypotl
- std::abs(float), std::fabs, std::fabsf, std::fabsl
- std::sqrt, std::sqrtf, std::sqrtl
- std::sin, std::sinf, std::sinl
- std::fma, std::fmaf, std::fmal
- std::fmax, std::fmaxf, std::fmaxl
- std::fmin, std::fminf, std::fminl
- std::fdim, std::fdimf, std::fdiml
- NAN
- std::exp, std::expf, std::expl
- std::exp2, std::exp2f, std::exp2l
- std::expm1, std::expm1f, std::expm1l
- std::log, std::logf, std::logl
- std::log10, std::log10f, std::log10l
- std::log1p, std::log1pf, std::log1pl
- std::log2, std::log2f, std::log2l
- std::cbrt, std::cbrtf, std::cbrtl
- std::pow, std::powf, std::powl
- std::cos, std::cosf, std::cosl
- std::tan, std::tanf, std::tanl
- std::asin, std::asinf, std::asinl
- std::acos, std::acosf, std::acosl
- std::atan, std::atanf, std::atanl
- std::atan2, std::atan2f, std::atan2l
- std::sinh, std::sinhf, std::sinhl
- std::cosh, std::coshf, std::coshl
- std::tanh, std::tanhf, std::tanhl
- std::asinh, std::asinhf, std::asinhl
- std::acosh, std::acoshf, std::acoshl
- std::atanh, std::atanh, std::atanhl
- std::erf, std::erff, std::erfl
- std::erfc, std::erfcf, std::erfcl
- std::lgamma, std::lgammaf, std::lgammal
- std::tgamma, std::tgammaf, std::tgammal
- std::ceil, std::ceilf, std::ceill
- std::floor, std::floorf, std::floorl
- std::round, std::roundf, std::roundl, std::lround, std::lroundf, std::lroundl, std::llround, std::llroundf
- std::trunc, std::truncf, std::truncl
- std::nearbyint, std::nearbyintf, std::nearbyintl
- std::rint, std::rintf, std::rintl, std::lrint, std::lrintf, std::lrintl, std::llrint, std::llrintf
- std::ldexp, std::ldexpf, std::ldexpl
- std::scalbn, std::scalbnf, std::scalbnl, std::scalbln, std::scalblnf, std::scalblnl
- std::ilogb, std::ilogbf, std::ilogbl
- std::logb, std::logbf, std::logbl
- std::frexp, std::frexpf, std::frexpl
- std::modf, std::modff, std::modfl
- std::nextafter, std::nextafterf, std::nextafterl, std::nexttoward, std::nexttowardf, std::nexttowardl
- std::copysign, std::copysignf, std::copysignl
- std::fpclassify
- std::isfinite
- std::isinf
- std::isnan
- std::isnormal
- std::signbit
- std::isgreater
- std::isgreaterequal
- std::isless
- std::islessequal
- std::islessgreater
- std::isunordered
- HUGE_VALF, HUGE_VAL, HUGE_VALL
- INFINITY
- MATH_ERRNO, MATH_ERREXCEPT, math_errhandling
- FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN
- std::midpoint
- std::lerp
- std::has_single_bit
- std::bit_ceil
- std::bit_floor
- std::bit_width
- std::rotl
- æ°å¦ç¹æ®å½æ°
- ä¼ªéæºæ°çæ
- æµ®ç¹ç¯å¢
- std::complex
- std::valarray
- ç¼è¯æ¶æçæ°ç®æ¯
- std::gcd
- std::lcm
- æ°å¦å¸¸æ°
- std::bit_cast
- std::rotr
- std::countl_zero
- std::countl_one
- std::countr_zero
- std::countr_one
- std::popcount
- 注é
- è¾å ¥/è¾åºåº
- æä»¶ç³»ç»åº
- æ¬å°ååº
- æ£å表达å¼åº
- ååæä½åº
- çº¿ç¨æ¯æåº
- å®éªæ§ C++ ç¹æ§
- æç¨çèµæº
- ç´¢å¼
- std 符å·ç´¢å¼
- åç¨æ¯æ (C++20)
- C++ å ³é®è¯
ä½ç½®ï¼é¦é¡µ > C++ åèæå >æ°å¼åº >å¸¸ç¨æ°å¦å½æ° > std::atan2, std::atan2f, std::atan2l
std::atan2, std::atan2f, std::atan2l
| å®ä¹äºå¤´æä»¶ <cmath>
|
||
| (1) | ||
| float    atan2 ( float y, float x ); |
||
| float    atan2f( float y, float x ); |
(C++11 èµ·) | |
| double    atan2 ( double y, double x ); |
(2) | |
| (3) | ||
| long double atan2 ( long double y, long double x ); |
||
| long double atan2l( long double y, long double x ); |
(C++11 èµ·) | |
| Promoted   atan2 ( Arithmetic1 y, Arithmetic2 x ); |
(4) | (C++11 èµ·) |
1-3) 计ç®
y/x çå¼§ï¼åï¼æ£åï¼ä»¥åæ°ç¬¦å·ç¡®å®æ£ç¡®ç象éã4) ææ 1-3) æä¸è¦ççç®æ¯ç±»åçéè½½éæå½æ°æ¨¡æ¿ãè¥ä»»ä½åæ°æ¥ææ´æ°ç±»åï¼åå°å®è½¬å为 double ãè¥ä»»ä½åæ°ä¸º long double ï¼åè¿åç±»å
Promoted 亦为 long double ï¼å¦åè¿åç±»åå§ç»ä¸º double ãåæ°
| x, y | - | æµ®ç¹ææ´æ°ç±»åå¼ |
è¿åå¼
è¥ä¸åºç°é误ï¼åè¿åy/x å¨ [-Ï ; +Ï] 弧度èå´ä¸çå¼§ï¼åï¼æ£åï¼ arctan(| y |
| x |
Y åæ°
è¿åå¼
X åæ°
è¥åºç°å®ä¹åé误ï¼åè¿åå®ç°å®ä¹å¼ã
è¥åºç°ä¸æº¢æè´çå¼åé误ï¼åè¿åï¼èå ¥åçï¼æ£ç¡®ç»æã
é误å¤ç
æ¥å math_errhandling 䏿å®çé误ã
è¥ x ä¸ y å为é¶åå¯è½åºç°å®ä¹åé误ã
è¥å®ç°æ¯æ IEEE æµ®ç¹ç®æ¯ï¼ IEC 60559 ï¼ï¼å
- è¥
xä¸yå为é¶ï¼åå®ä¹åé误ä¸åºç° - è¥
xä¸yå为é¶ï¼åä¹ä¸åºç°å¼åé误 - è¥
y为é¶ï¼åä¸åºç°æç¹é误 - è¥
y为±0ä¸xä¸ºè´æ-0ï¼åè¿åÂ±Ï - è¥
y为±0ä¸xä¸ºæ£æ+0ï¼åè¿å±0 - è¥
y为±âä¸xæéï¼åè¿å±Ï/2 - è¥
y为±âä¸x为-âï¼åè¿å±3Ï/4 - è¥
y为±âä¸x为+âï¼åè¿å±Ï/4 - è¥
x为±0ä¸y为è´ï¼åè¿å-Ï/2 - è¥
x为±0ä¸y为æ£ï¼åè¿å+Ï/2 - è¥
x为-âä¸yä¸ºæ£æéï¼åè¿å+Ï - è¥
x为-âä¸yä¸ºè´æéï¼åè¿å-Ï - è¥
x为+âä¸yä¸ºæ£æéï¼åè¿å+0 - è¥
x为+âä¸yä¸ºè´æéï¼åè¿å-0 - è¥
x为 NaN æy为 NaN ï¼åè¿å NaN
注æ
std::atan2(y, x) çä»·äº std::arg(std::complex<double>(x,y)) ã
POSIX æå®å¨ä¸æº¢æ
åµä¸ï¼è¿åä¸ä¿®æ¹ç arg ï¼èè¥ä¸æ¯æå¦æ¤ï¼åè¿åä¸å¤§äº DBL_MIN ã FLT_MIN å LDBL_MIN çå®ç°å®ä¹å¼ã
示ä¾
è¿è¡æ¤ä»£ç
#include <iostream> #include <cmath>  int main() { // æ£å¸¸ç¨æ³ï¼äºä¸ªåæ°ç符å·ç¡®å®è±¡é std::cout << "(+1,+1) cartesian is (" << hypot(1,1) << ',' << atan2(1,1) << ") polar\n" // atan2(1,1) = +pi/4 ï¼ç¬¬ I 象é << "(+1,-1) cartesian is (" << hypot(1,-1) << ',' << atan2(1,-1) << ") polar\n" // atan2(1, -1) = +3pi/4 ï¼ç¬¬ II 象é << "(-1,-1) cartesian is (" << hypot(-1,-1) << ',' << atan2(-1,-1) << ") polar\n" // atan2(-1,-1) = -3pi/4 ï¼ç¬¬ III 象é << "(-1,+1) cartesian is (" << hypot(-1,1) << ',' << atan2(-1,1) << ") polar\n"; // atan2(-1,-1) = -pi/4 ï¼ç¬¬ IV 象é // ç¹æ®å¼ std::cout << "atan2(0, 0) = " << atan2(0,0) << " atan2(0,-0) = " << atan2(0,-0.0) << '\n' << "atan2(7, 0) = " << atan2(7,0) << " atan2(7,-0) = " << atan2(7,-0.0) << '\n'; }
è¾åºï¼
(+1,+1) cartesian is (1.41421,0.785398) polar (+1,-1) cartesian is (1.41421,2.35619) polar (-1,-1) cartesian is (1.41421,-2.35619) polar (-1,+1) cartesian is (1.41421,-0.785398) polar atan2(0, 0) = 0 atan2(0,-0) = 3.14159 atan2(7, 0) = 1.5708 atan2(7,-0) = 1.5708
åé
| (C++11)(C++11) |
计ç®åæ£å¼¦ï¼ arcsin(x) ï¼ (彿°) |
| (C++11)(C++11) |
计ç®åä½å¼¦ï¼ arccos(x) ï¼ (彿°) |
| (C++11)(C++11) |
计ç®åæ£åï¼ arctan(x) ï¼ (彿°) |
| è¿åè¾è§ (彿°æ¨¡æ¿) | |
| åºç¨å½æ° std::atan2 å°ä¸ä¸ª valarray åä¸ä¸ªå¼ (彿°æ¨¡æ¿) |