floor, floorf, floorl

Calcola la parte intera di un valore.

Sintassi

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

Parametri

x
Valore a virgola mobile.

Valore restituito

Le funzioni floor restituiscono un valore a virgola mobile che rappresenta l'intero più vicino minore o uguale a x. Non viene restituito alcun errore.

Input Eccezione SEH Eccezione _matherr
± QNaN, IND Nessuno _DOMAIN

floor ha un'implementazione che usa SSE2 (Streaming SIMD Extensions 2). Per informazioni e restrizioni sull'uso dell'implementazione di S edizione Standard 2, vedere _set_SSE2_enable.

Osservazioni:

C++ consente l'overload, quindi è possibile chiamare overload di floor che accettino e restituiscano i valori float e long double. In un programma C, a meno che non si usi la <macro tgmath.h> per chiamare questa funzione, floor accetta sempre e restituisce un oggetto double.

Se si utilizza la <macro tgmath.h>floor() , il tipo dell'argomento determina quale versione della funzione è selezionata. Per informazioni dettagliate, vedere La matematica generica dei tipi.

Per impostazione predefinita, lo stato globale di questa funzione è limitato all'applicazione. Per modificare questo comportamento, vedere Stato globale in CRT.

Requisiti

Funzione Intestazione obbligatoria
floor, floorf, floorl <math.h>
floor Macro <tgmath.h>

Per altre informazioni sulla compatibilità, vedere Compatibility (Compatibilità).

Esempio

// 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

Vedi anche

Supporto matematico e a virgola mobile
ceil, ceilf, ceill
round, roundf, roundl
fmod, fmodf