Namespaces
Variants

floor, floorf, floorl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
floor
(C99) (C99) (C99)
(C99)

(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
Definiert im Header <math.h>
float floorf ( float arg ) ;
(1) (seit C99)
double floor ( double arg ) ;
(2)
long double floorl ( long double arg ) ;
(3) (seit C99)
Definiert im Header <tgmath.h>
#define floor( arg )
(4) (seit C99)
1-3) Berechnet den größten ganzzahligen Wert, der nicht größer als arg ist.
4) Typgenerisches Makro: Wenn arg den Typ long double hat, wird floorl aufgerufen. Andernfalls, wenn arg einen Ganzzahltyp oder den Typ double hat, wird floor aufgerufen. Andernfalls wird floorf aufgerufen.

Inhaltsverzeichnis

Parameter

arg - Gleitkommawert

Rückgabewert

Wenn keine Fehler auftreten, wird der größte ganzzahlige Wert zurückgegeben, der nicht größer als arg ist, also ⌊arg⌋ .

Rückgabewert
math-floor.svg
Argument

Fehlerbehandlung

Fehler werden gemeldet, wie in math_errhandling festgelegt.

Wenn die Implementierung IEEE-Gleitkommaarithmetik (IEC 60559) unterstützt:

  • Der aktuelle Rundungsmodus hat keine Auswirkung.
  • Wenn arg ±∞ ist, wird es unverändert zurückgegeben.
  • Wenn arg ±0 ist, wird es unverändert zurückgegeben.
  • Wenn arg NaN ist, wird NaN zurückgegeben.

Hinweise

FE_INEXACT kann (muss aber nicht) ausgelöst werden, wenn ein nicht-ganzzahliger endlicher Wert gerundet wird.

Die größten darstellbaren Gleitkommawerte sind exakte Ganzzahlen in allen standardmäßigen Gleitkommaformaten, daher läuft diese Funktion niemals allein über; jedoch kann das Ergebnis jeden ganzzahligen Typ (einschließlich intmax_t ) überlaufen, wenn es in einer ganzzahligen Variable gespeichert wird.

Beispiel

#include <math.h>
#include <stdio.h>
int main(void)
{
    printf("floor(+2.7) = %+.1f\n", floor(2.7));
    printf("floor(-2.7) = %+.1f\n", floor(-2.7));
    printf("floor(-0.0) = %+.1f\n", floor(-0.0));
    printf("floor(-Inf) = %+f\n",   floor(-INFINITY));
}

Mögliche Ausgabe:

floor(+2.7) = +2.0
floor(-2.7) = -3.0
floor(-0.0) = -0.0
floor(-Inf) = -inf

Referenzen

  • C23-Standard (ISO/IEC 9899:2024):
  • 7.12.9.2 Die floor-Funktionen (S.: TBD)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S.: TBD)
  • F.10.6.2 Die floor-Funktionen (S.: TBD)
  • C17-Standard (ISO/IEC 9899:2018):
  • 7.12.9.2 Die floor-Funktionen (S.: TBD)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S.: TBD)
  • F.10.6.2 Die floor-Funktionen (S.: TBD)
  • C11-Standard (ISO/IEC 9899:2011):
  • 7.12.9.2 Die floor-Funktionen (S. 251)
  • 7.25 Typgenerische Mathematik <tgmath.h> (S. 373-375)
  • F.10.6.2 Die floor-Funktionen (S. 526)
  • C99-Standard (ISO/IEC 9899:1999):
  • 7.12.9.2 Die floor-Funktionen (S. 232)
  • 7.22 Typgenerische Mathematik <tgmath.h> (S. 335-337)
  • F.9.6.2 Die floor-Funktionen (S. 463)
  • C89/C90 Standard (ISO/IEC 9899:1990):
  • 4.5.6.3 Die floor-Funktion

Siehe auch

(C99) (C99)
berechnet die kleinste Ganzzahl, die nicht kleiner als der gegebene Wert ist
(Funktion)
(C99) (C99) (C99)
rundet auf die nächstgelegene Ganzzahl, die nicht größer im Betrag als der gegebene Wert ist
(Funktion)
(C99) (C99) (C99) (C99) (C99) (C99) (C99) (C99) (C99)
rundet auf die nächstgelegene Ganzzahl, bei Mittelwerten von Null weg
(Funktion)