floor, floorf, floorl

Berechnet die nächstliegende nicht kleinere ganze Zahl eines Werts.

Syntax

double floor(
   double x
);
float floor(
   float x
); // C++ only
long double floor(
   long double x
); // C++ only
float floorf(
   float x
);
long double floorl(
   long double x
);
#define floor(X) // Requires C11 or higher

Parameter

x
Gleitkommawert.

Rückgabewert

Die floor-Funktionen geben einen Gleitkommawert zurück, der die größte ganze Zahl darstellt, die kleiner oder gleich x ist. Es wird kein Fehler zurückgegeben.

Eingabe SEH-Ausnahme _matherr-Ausnahme
± QNaN, IND Keine _DOMAIN

floor ist eine Implementierung, die SIMD-Streamingerweiterungen 2 (SSE2) verwendet. Informationen und Einschränkungen zur Verwendung der SSE2-Implementierung finden Sie unter _set_SSE2_enable.

Hinweise

Da C++ das Überladen zulässt, können Sie Überladungen von floor aufrufen, die float- und long double-Werte verwenden und zurückgeben. In einem C-Programm, es sei denn, Sie verwenden das <Makro tgmath.h> , um diese Funktion aufzurufen, floor übernimmt und gibt immer ein double.

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

Standardmäßig gilt der globale Zustand dieser Funktion für die Anwendung. Informationen zum Ändern dieses Verhaltens finden Sie im Global state in the CRT.

Anforderungen

Funktion Erforderlicher Header
floor, floorf, floorl <math.h>
floor-Makro <tgmath.h>

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

Beispiel

// crt_floor.c
// This example displays the largest integers
// less than or equal to the floating-point values 2.8
// and -2.8. It then shows the smallest integers greater
// than or equal to 2.8 and -2.8.

#include <math.h>
#include <stdio.h>

int main( void )
{
   double y;

   y = floor( 2.8 );
   printf( "The floor of 2.8 is %f\n", y );
   y = floor( -2.8 );
   printf( "The floor of -2.8 is %f\n", y );

   y = ceil( 2.8 );
   printf( "The ceil of 2.8 is %f\n", y );
   y = ceil( -2.8 );
   printf( "The ceil of -2.8 is %f\n", y );
}
The floor of 2.8 is 2.000000
The floor of -2.8 is -3.000000
The ceil of 2.8 is 3.000000
The ceil of -2.8 is -2.000000

Siehe auch

Mathematische und Gleitkommaunterstützung
ceil, ceilf, ceill
round, roundf, roundl
fmod, fmodf