Logo

Programming-Idioms

History of Idiom 81 > diff from v51 to v52

Edit summary for version 52 by Gene_Parmesan:
New Scheme implementation by user [Gene_Parmesan]

Version 51

2019-10-14, 12:27:32

Version 52

2019-12-24, 03:29:35

Idiom #81 Round floating point number to integer

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

Idiom #81 Round floating point number to integer

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

Code
(define y (round x))
Comments bubble
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
Doc URL
https://groups.csail.mit.edu/mac/ftpdir/scheme-7.4/doc-html/scheme_5.html