Die Funktion fmax () in C ++ verwendet zwei Argumente und gibt das größte unter ihnen zurück. Wenn eines der Argumente NaN ist, wird das andere Argument zurückgegeben.
Die Funktion ist in der Header-Datei definiert.
Prototyp fmax () (Stand C ++ 11 Standard)
doppeltes fmax (doppeltes x, doppeltes y); float fmax (float x, float y); langes doppeltes fmax (langes doppeltes x, langes doppeltes y); Geförderte fmax (Typ1 x, Typ2 y); // Zusätzliche Überladungen für arithmetische Typen
Seit C ++ 11 lautet long double
der Rückgabetyp , wenn ein an fmax () übergebenes Argument Promoted
lautet long double
. Wenn nicht, Promoted
lautet der Rückgabetyp double
.
fmax () Parameter
- x : Das erste Argument von fmax ().
- y : Das zweite Argument von fmax ().
fmax () Rückgabewert
Die Funktion fmax () gibt den Maximalwert zwischen x und y zurück.
Beispiel 1: Funktion fmax () für Argumente des gleichen Typs
#include #include using namespace std; int main() ( double x = -2.05, y = NAN, result; result = fmax(x, y); cout << "fmax(x, y) = " << result << endl; return 0; )
Wenn Sie das Programm ausführen, lautet die Ausgabe wie folgt:
fmax (x, y) = -2,05
Beispiel 2: Funktion fmax () für Argumente unterschiedlichen Typs
#include #include using namespace std; int main() ( double x = 56.13, result; int y = 89; result = fmax(x, y); cout << "fmax(x, y) = " << result << endl; return 0; )
Wenn Sie das Programm ausführen, lautet die Ausgabe wie folgt:
fmax (x, y) = 89