Logo

Programming-Idioms

History of Idiom 81 > diff from v45 to v46

Edit summary for version 46 by hrschueler:
[Haskell] It says "round up on 5"

Version 45

2018-04-08, 06:49:45

Version 46

2018-04-17, 17:13:22

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
y = floor (x + 1/2)
Code
y = round (x + 1/2)
Comments bubble
Haskell would round half-ties towards nearest ∈ℤ2 rather than towards +∞
Comments bubble
Haskell would round half-ties towards nearest ∈ℤ2 rather than towards +∞
Doc URL
http://hackage.haskell.org/package/base/docs/Prelude.html#v:floor
Doc URL
http://hackage.haskell.org/package/base/docs/Prelude.html#v:floor