lround, , lroundflroundl, llround, , llroundfllroundl

Rundet einen Gleitkommawert auf die nächste Ganzzahl.

Syntax

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
);
#define lround(X) // Requires C11 or higher

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 none _DOMAIN

Hinweise

Da C++ eine Überladung zulässt, können Sie Überladungen aufrufen lround oder llround überladen, die werte annehmen und long double zurückgebenfloat. In einem C-Programm, es sei denn, Sie verwenden das <Makro tgmath.h> , um diese Funktion aufzurufen, lround und llround nehmen und geben Sie immer ein double.

Wenn Sie das Makro <tgmath.h>lround() verwenden, bestimmt der Typ des Arguments, welche Version der Funktion ausgewählt ist. Ausführliche Informationen finden Sie unter Typgengenerische Mathematik.

Standardmäßig gilt der globale Zustand dieser Funktion für die Anwendung. Wie Sie dieses Verhalten ändern, erfahren Sie unter Globaler Status in der CRT.

Anforderungen

Routine Erforderlicher Header
lround, , lroundflroundl, llround, , llroundfllroundl <math.h>
lround-Makro <tgmath.h>

Weitere Informationen zur Kompatibilität finden Sie unter Kompatibilität.

Beispiel

// crt_lround.c
// Build with: cl /W4 /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.5L;

   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));
}
lround(2.499999) is 2
lround(-2.499999) is -2
lroundf(2.800000) is 3
lroundf(-2.800000) is -3
lroundl(3.500000) is 4
lroundl(-3.500000) is -4

Siehe auch

Mathematische Unterstützung und Gleitkommaunterstützung
ceil, ceilfceill
floor, floorffloorl
fmod, fmodf
lrint, , lrintflrintl, llrint, , llrintfllrintl
round, roundfroundl
nearbyint, nearbyintfnearbyintl
rint, rintfrintl