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::div, std::ldiv, std::lldiv
std::div, std::ldiv, std::lldiv
| å®ä¹äºå¤´æä»¶ <cstdlib>
|
||
| std::div_t   div( int x, int y ); |
(1) | |
| std::ldiv_t   div( long x, long y ); |
(2) | |
| std::lldiv_t  div( long long x, long long y ); |
(3) | (C++11 èµ·) |
| std::ldiv_t  ldiv( long x, long y ); |
(4) | |
| std::lldiv_t lldiv( long long x, long long y ); |
(5) | (C++11 èµ·) |
| å®ä¹äºå¤´æä»¶ <cinttypes>
|
||
| std::imaxdiv_t div( std::intmax_t x, std::intmax_t y ); |
(6) | (C++11 èµ·) |
| std::imaxdiv_t imaxdiv( std::intmax_t x, std::intmax_t y ); |
(7) | (C++11 èµ·) |
计ç®åå x é¤ä»¥åæ¯ y çåå使°
|
忝èå¼ä»»ä½å°æ°é¨åï¼åé¶æªæï¼ç代æ°åã使°æ»¡è¶³ quot * y + rem == x ã |
(C++11 å) |
|
åæ¯è¡¨è¾¾å¼ x/y çç»æã使°æ¯è¡¨è¾¾å¼ x%y çç»æã |
(C++11 èµ·) |
åæ°
| x, y | - | æ´æ°å¼ |
è¿åå¼
è¥ä½æ°ä¸ä¸çè½è¡¨ç¤ºæå¯¹åºç±»åï¼åå«ä¸º int ã long ã long long ã std::imaxdiv_t ï¼ç对象ï¼åè¿åä½ä¸ºå®ä¹äºä¸ç std::div_t ã std::ldiv_t ã std::lldiv_t ã std::imaxdiv_t ç±»å对象çäºè
ï¼
std::div_t
struct div_t { int quot; int rem; };
æ
struct div_t { int rem; int quot; };
std::ldiv_t
struct ldiv_t { long quot; long rem; };
æ
struct ldiv_t { long rem; long quot; };
std::lldiv_t
struct lldiv_t { long long quot; long long rem; };
æ
struct lldiv_t { long long rem; long long quot; };
std::imaxdiv_t
struct imaxdiv_t { std::intmax_t quot; std::intmax_t rem; };
æ
struct imaxdiv_t { std::intmax_t rem; std::intmax_t quot; };
è¥ä½æ°æåä¹ä¸æ æ³è¡¨ç¤ºï¼åè¡ä¸ºæªå®ä¹ã
注æ
C++11 åï¼è¥è¿ç®æ°ä¹ä¸ä¸ºè´ï¼åå å»ºé¤æ³ä¸åä½è¿ç®ç¬¦ä¸åçèå ¥æ¹åå使°çç¬¦å·æ¯å®ç°å®ä¹çï¼ä½å¨ std::div ä¸å·²æ¯è¯å¥½å®ä¹ã
夿°å¹³å°ä¸ï¼åæ¡ CPU æä»¤ä¸åè·å¾åä¸ä½æ°ï¼èæ¤å½æ°å¯ä»¥æ´»ç¨è¿ç¹ï¼å°½ç®¡ç¼è¯å¨é常è½å¤å¨éåå¤åå¹¶é»è¿ç / ä¸Â % ã
示ä¾
#include <string> #include <cmath> #include <cstdlib> #include <iostream>  std::string itoa(int n, int base) { std::string buf; std::div_t dv{}; dv.quot = n; do { dv = std::div(dv.quot, base); buf += "0123456789abcdef"[std::abs(dv.rem)]; // å符串åé¢éæ¯æ°ç» } while(dv.quot); if(n<0) buf += '-'; return {buf.rbegin(), buf.rend()}; }  int main() { std::cout << itoa(12345, 10) << '\n' << itoa(-12345, 10) << '\n' << itoa(65535, 16) << '\n'; }
è¾åºï¼
12345 -12345 ffff
åé
| (C++11)(C++11) |
æµ®ç¹é¤æ³è¿ç®ç使° (彿°) |
| (C++11)(C++11)(C++11) |
餿³è¿ç®çæç¬¦å·ä½æ° (彿°) |
| (C++11)(C++11)(C++11) |
餿³è¿ç®çæç¬¦å·ä½æ°åæåä¸ä¸ªäºè¿å¶ä½ (彿°) |