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::nextafter, std::nextafterf, std::nextafterl, std::nexttoward, std::nexttowardf, std::nexttowardl
std::nextafter, std::nextafterf, std::nextafterl, std::nexttoward, std::nexttowardf, std::nexttowardl
| å®ä¹äºå¤´æä»¶ <cmath>
|
||
| float    nextafter ( float from, float to ); float    nextafterf( float from, float to ); |
(1) | (C++11 èµ·) |
| double    nextafter ( double from, double to ); |
(2) | (C++11 èµ·) |
| long double nextafter ( long double from, long double to ); long double nextafterl( long double from, long double to ); |
(3) | (C++11 èµ·) |
| Promoted   nextafter ( Arithmetic1 from, Arithmetic2 to ); |
(4) | (C++11 èµ·) |
| float    nexttoward ( float from, long double to ); float    nexttowardf( float from, long double to ); |
(5) | (C++11 èµ·) |
| double    nexttoward ( double from, long double to ); |
(6) | (C++11 èµ·) |
| long double nexttoward ( long double from, long double to ); long double nexttowardl( long double from, long double to ); |
(7) | (C++11 èµ·) |
| double    nexttoward ( IntegralType from, long double to ); |
(8) | (C++11 èµ·) |
è¿å from äº to æ¹åçä¸ä¸ªå¯è¡¨ç¤ºå¼ã
from çäº to ï¼åè¿å to ãfrom çäº to ï¼åè¿åä» long double 转æ¢å°å½æ°è¿åç±»åç to ï¼èä¸å¸¦èå´æç²¾åº¦çæå¤±ãPromoted 亦为 long double ï¼å¦åè¿åç±»åå§ç»ä¸º double ãfrom åæ°çéè½½éæå½æ°æ¨¡æ¿ãçä»·äº (6) ï¼å°åæ°è½¬å为 double ï¼ãåæ°
| from, to | - | æµ®ç¹å¼ |
è¿åå¼
è¥ä¸åºç°é误ï¼åè¿å from äº to çæ¹åçä¸ä¸ªå¯è¡¨ç¤ºå¼ãè¥ from çäº to ï¼åè¿å to ï¼è½¬æ¢å°å½æ°çç±»åã
è¥åºç°ä¸æº¢æè´çå¼åé误ï¼åè¿å ±HUGE_VAL ã ±HUGE_VALF æ ±HUGE_VALL ï¼æå¸¦ç¬¦å·å from ï¼ã
è¥åºç°ä¸æº¢æè´çå¼åé误ï¼åè¿åæ£ç¡®ç»æã
é误å¤ç
æ¥å math_errhandling 䏿å®çé误ã
è¥å®ç°æ¯æ IEEE æµ®ç¹ç®æ¯ï¼ IEC 60559 ï¼ï¼å
- è¥
fromæéï¼ä½æå¾ çç»ææ éï¼åå¼å FE_INEXACT å FE_OVERFLOW ã - è¥
fromä¸çäºtoä¸ç»æä¸ºéæ£è§æé¶ï¼åå¼å FE_INEXACT å FE_UNDERFLOW ã - 任使 åµä¸ï¼è¿åå¼ç¬ç«äºå½åèå ¥æ¨¡å¼ã
- è¥
fromæto为 NaN ï¼åè¿å NaN
注æ
POSIX æå®ä¸æº¢å䏿º¢æ¡ä»¶æ¯å¼åé误ï¼å¯ä»¥è®¾ç½® errno ï¼ã
IEC 60559 æ¨èå¡å¨ from==to æ¶è¿å from ãè¿äºå½æ°æ¿èè¿å to ï¼è¿ä½¿å¾å´ç»é¶çè¡ä¸ºä¸è´ï¼ std::nextafter(-0.0, +0.0) è¿å +0.0 è std::nextafter(+0.0, -0.0) è¿å â0.0 ã
示ä¾
#include <cmath> #include <iomanip> #include <iostream> #include <cfloat> #include <cfenv>  int main() { float from1 = 0, to1 = std::nextafter(from1, 1.f); std::cout << "The next representable float after " << std::setprecision(20) << from1 << " is " << to1 << std::hexfloat << " (" << to1 << ")\n" << std::defaultfloat;  float from2 = 1, to2 = std::nextafter(from2, 2.f); std::cout << "The next representable float after " << from2 << " is " << to2 << std::hexfloat << " (" << to2 << ")\n" << std::defaultfloat;  double from3 = std::nextafter(0.1, 0), to3 = 0.1; std::cout << "The number 0.1 lies between two valid doubles:\n" << std::setprecision(56) << " " << from3 << std::hexfloat << " (" << from3 << ')' << std::defaultfloat << "\nand " << to3 << std::hexfloat << " (" << to3 << ")\n" << std::defaultfloat << std::setprecision(20);  // nextafter å nexttoward é´çå·®å¼ï¼ long double dir = std::nextafter(from1, 1.0L); // é¦ä¸ªéæ£è§ long double float x = nextafter(from1, dir); // é¦å è½¬æ¢ dir 为 float ï¼ç»åº 0 std::cout << "With nextafter, next float after " << from1 << " is " << x << '\n'; x = std::nexttoward(from1, dir); std::cout << "With nexttoward, next float after " << from1 << " is " << x << '\n';  // ç¹æ®å¼ { #pragma STDC FENV_ACCESS ON std::feclearexcept(FE_ALL_EXCEPT); double from4 = DBL_MAX, to4 = std::nextafter(from4, INFINITY); std::cout << "The next representable double after " << std::setprecision(6) << from4 << std::hexfloat << " (" << from4 << ')' << std::defaultfloat << " is " << to4 << std::hexfloat << " (" << to4 << ")\n" << std::defaultfloat; if(std::fetestexcept(FE_OVERFLOW)) std::cout << " raised FE_OVERFLOW\n"; if(std::fetestexcept(FE_INEXACT)) std::cout << " raised FE_INEXACT\n"; } // ç»æ FENV_ACCESS å  float from5 = 0.0, to5 = std::nextafter(from5, -0.0); std::cout << "std::nextafter(+0.0, -0.0) gives " << std::fixed << to5 << '\n'; }
è¾åºï¼
The next representable float after 0 is 1.4012984643248170709e-45 (0x1p-149)
The next representable float after 1 is 1.0000001192092895508 (0x1.000002p+0)
The number 0.1 lies between two valid doubles:
0.09999999999999999167332731531132594682276248931884765625 (0x1.9999999999999p-4)
and 0.1000000000000000055511151231257827021181583404541015625 (0x1.999999999999ap-4)
With nextafter, next float after 0 is 0
With nexttoward, next float after 0 is 1.4012984643248170709e-45
The next representable double after 1.79769e+308 (0x1.fffffffffffffp+1023) is inf (inf)
raised FE_OVERFLOW
raised FE_INEXACT
std::nextafter(+0.0, -0.0) gives -0.000000