Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Scheme

Idiom #81 Round floating point number to integer

Declare the integer y and initialize it with the rounded value of the floating point number x .
Ties (when the fractional part of x is exactly .5) must be rounded up (to positive infinity).

(define y (round x))

Similar functions:
- round: compat with IEEE floating point rounding rules; rounds to even when halfway b/w two integers
- floor: largest int not larger than x
- ceiling: smallest int not smaller than x
- truncate: integer closest to x whose absolute value is not larger than the absolute value of x
Y : constant Integer := Integer (Float'Rounding (X));

New implementation...