Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

round

Name: Anonymous 2007-05-17 11:03 ID:ewt37wAw

Prelude> round 0.5
0
Prelude> round 1.5
2
Prelude> round 2.5
2
Prelude> round 3.5
4


WHAT THE FUCK

Name: Anonymous 2007-05-17 19:01 ID:Vi/TGbmq

>>9
Actually, it should always go up at .5.

According to Hoogle, Haskell's round is defined in terms of properFraction, so I checked it out:

Prelude> map properFraction [0.5..9.5]
[(0,0.5),(1,0.5),(2,0.5),(3,0.5),(4,0.5),(5,0.5),(6,0.5),(7,0.5),(8,0.5),(9,0.5)]


Looks like everything is fine here, so I overloaded round with:

round x = if (snd $ properFraction x) >= 0.5 then ceiling x else floor x

And the results...

Prelude> map round [0.5..9.5]
[1,2,3,4,5,6,7,8,9,10]


...Now this one seems to work just fine.

WHAT THE FUCK

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List