C ++ nexttoward () - C ++ Standardbibliotek

Nexttoward () -funktionen i C ++ tar två argument och returnerar nästa representerbara värde efter x i riktning mot y.

Funktionen definieras i rubrikfilen.

Det är identiskt med nextafter () förutom att det andra argumentet för nexttoward () alltid är av typ long double.

nexttoward () prototyp (Från och med C ++ 11 standard)

dubbel efterföljande (dubbel x, lång dubbel y); float nexttoward (float x, long float y); lång dubbel efterföljande (lång dubbel x, lång dubbel y); dubbel efterföljande (T x, lång dubbel y); // För integrerad typ

Den nexttoward () funktionen tar två argument och returnerar ett värde av typen double, floateller long doubletyp.

nexttoward () Parametrar

  • x : Basvärdet.
  • y : Det värde mot vilket returvärdet approximeras.

nexttoward () Returvärde

Funktionen nexttoward () returnerar nästa representerbara värde efter x i riktning mot y.

Exempel 1: Hur fungerar nexttoward () i C ++?

 #include #include using namespace std; int main() ( long double y = -1.0; double x = 0.0; double result = nexttoward(x, y); cout << "nexttoward(x, y) = " << result << endl; return 0; ) 

När du kör programmet blir resultatet:

 nexttoward (x, y) = -4.94066e-324 

Exempel 2: nexttoward () -funktion för integrerade typer

 #include #include #include using namespace std; int main() ( long double y = INFINITY; int x = INT_MAX; double result = nexttoward(x,y); cout << "nexttoward(x, y) = " << result << endl; return 0; ) 

När du kör programmet blir resultatet:

 nexttoward (x, y) = 2.14748e + 09 

Intressanta artiklar...