ceilf - Linux


Overview

ceilf rounds its input to the nearest integer greater than or equal to the input value. It is commonly used to perform ceiling operations on floating-point values and for integer rounding.

Syntax

ceilf (-inf|-infinity) => infinity
ceilf(inf|infinity) => infinity
ceilf(nan) => nan
ceilf(x) => smallest integer y such that y ≥ x

Options/Flags

ceilf does not take any options or flags.

Examples

Basic Usage:

ceilf(2.3)  # Output: 3
ceilf(-1.6) # Output: -1

Rounding:

ceilf(12.456, -1) # Round to the nearest ten: 13
ceilf(49.9999, 0)   # Round to the nearest integer: 50

Common Issues

  • Input Range: ceilf operates on floating-point values. Attempting to round values outside the supported range may lead to unexpected behavior or errors.
  • Negative Rounding: Rounding negative values with positive decimals can result in unexpected values. For example, ceilf(-1.5, 1) returns -2 instead of -1.

Integration

ceilf can be combined with other commands for complex operations, such as:

printf "%.0f\n" $(ceilf 2.3)  # Round to the nearest integer and print as a whole number
ceilf "$(bc -l <<< "scale=2; 1.234 + 0.345")"` # Round the sum of two decimal values

Related Commands

  • floorf: Rounds its input to the nearest integer less than or equal to the input value
  • roundf: Rounds its input to the nearest integer, rounding up for values greater than or equal to 0.5, and down otherwise
  • lroundf: Rounds its input to the nearest integer of type long long