lround, lroundf, lroundl, llround, llroundf, llroundl
Rundet einen Gleitkommawert auf die nächste Ganzzahl.
long lround(
double x
);
long lround(
float x
); // C++ only
long lround(
long double x
); // C++ only
long lroundf(
float x
);
long lroundl(
long double x
);
long long llround(
double x
);
long long llround(
float x
); // C++ only
long long llround(
long double x
); // C++ only
long long llroundf(
float x
);
long long llroundl(
long double x
);
Parameter
- x
Der zu rundende Gleitkommawert.
Rückgabewert
Die Funktionen lround und llround geben die long-Ganzzahl oder die long long-Ganzzahl zurück, die x am nächsten liegt. Halbe Werte werden kaufmännisch gerundet, unabhängig von der Einstellung des Gleitkomma-Rundungsmodus. Es gibt keine Fehlerrückgabe.
Eingabe |
SEH-Ausnahme |
Matherr-Ausnahme |
---|---|---|
± QNAN, IND |
Keine |
_DOMAIN |
Hinweise
Da C++ das Überladen zulässt, können Sie Überladungen von lround oder llround aufrufen, die float- und long double-Werte verwenden und zurückgeben. In einem C-Programm verwenden lround und llround immer double und geben dieses auch zurück.
Anforderungen
Routine |
Erforderlicher Header |
---|---|
lround, lroundf, lroundl, llround, llroundf, llroundl |
<math.h> |
Zusätzliche Informationen zur Kompatibilität finden Sie unter Kompatibilität.
Beispiel
// crt_lround.c
// Build with: cl /W3 /Tc crt_lround.c
// This example displays the rounded results of
// the floating-point values 2.499999, -2.499999,
// 2.8, -2.8, 3.5 and -3.5.
#include <math.h>
#include <stdio.h>
int main( void )
{
double x = 2.499999;
float y = 2.8f;
long double z = 3.5;
printf("lround(%f) is %d\n", x, lround(x));
printf("lround(%f) is %d\n", -x, lround(-x));
printf("lroundf(%f) is %d\n", y, lroundf(y));
printf("lroundf(%f) is %d\n", -y, lroundf(-y));
printf("lroundl(%Lf) is %d\n", z, lroundl(z));
printf("lroundl(%Lf) is %d\n", -z, lroundl(-z));
}