On this page
floor
Prev: pow | Up: math.h | Next: isnan
Rel: math.h, math, time & assert Guide
Ref: cppreference — floor
Tags: #public #prog #c #stdlib #math #tier/standard
Include
#include <math.h>
Signature & Overview
double floor(double x); /* also ceil, round, trunc */
Rounds x downward toward $-\infty$ (ceil toward $+\infty$, round to nearest).
Notes & Pitfalls
- Rounds toward $-\infty$ and returns
double:floor(-2.1) == -3.0(unlike(int)-2.1 == -2).
Example
#include <assert.h>
#include <math.h>
int main(void) { assert(floor(2.9) == 2.0 && floor(-2.1) == -3.0); }
Linked from
Related notes
- tuts/c/stdlib/math/isnan Linked here; links to this page; shared tags: #c, #math, #prog, #stdlib, #tier
- tuts/c/stdlib/math/pow Linked here; links to this page; shared tags: #c, #math, #prog, #stdlib, #tier
- tuts/c/stdlib/math Linked here; links to this page; shared tags: #c, #math, #prog, #stdlib
- tuts/c/stdlib/math_time_and_assert Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/math/fabs shared tags: #c, #math, #prog, #stdlib, #tier
- tuts/c/stdlib/math/sqrt shared tags: #c, #math, #prog, #stdlib, #tier
- tuts/c/stdlib/assert/assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/assert/static_assert shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isalpha shared tags: #c, #prog, #stdlib, #tier
- tuts/c/stdlib/ctype/isdigit shared tags: #c, #prog, #stdlib, #tier