<div dir="ltr"><div><div>That's an overly specific solution. I believe the more general rounding function taught in grade-school math would be:<br><br></div>(define (my-round n)<br></div> (floor (+ n 1/2)))<br><br>This is also untested. And it might need tweaking for negative numbers if they are supposed to round away from zero, I forget how that works.<br>
</div><div class="gmail_extra"><br clear="all"><div>Carl Eastlund</div>
<br><br><div class="gmail_quote">On Sat, Mar 16, 2013 at 8:32 PM, Eric Dobson <span dir="ltr"><<a href="mailto:eric.n.dobson@gmail.com" target="_blank">eric.n.dobson@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The docs say that it is round to even, which is the standard for<br>
floating point numbers [1]. You can write your own rounding operator<br>
that rounds .5 up if need be.<br>
<br>
;; Untested<br>
(define (my-round n)<br>
(let ((r (round n))) (if (= .5 (- n r)) (add1 r) r)))<br>
<br>
[1] <a href="http://en.wikipedia.org/wiki/Rounding#Round_half_to_even" target="_blank">http://en.wikipedia.org/wiki/Rounding#Round_half_to_even</a><br>
<div class="HOEnZb"><div class="h5"><br>
On Sat, Mar 16, 2013 at 7:21 AM, Eric Nadeau <<a href="mailto:nado18@gmail.com">nado18@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> I was having problems with a mathematical application I'm writing and narrowed it down to:<br>
><br>
> (round 0.5)<br>
> (round (/ 1 2))<br>
> (round 1.5)<br>
> (round (/ 3 2))<br>
><br>
> giving me<br>
><br>
> 0.0<br>
> 0<br>
> 2.0<br>
> 2<br>
><br>
> Since when is round 0.5 not giving 1?!<br>
><br>
> Cheers,<br>
> Eric<br>
> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
</div></div></blockquote></div><br></div>