Dealing with the bits of a floating point number directly is a bit odd, and it makes it hard to review the code. Is there a reason you don't want to use things like modf, floor, and ceil?
Hi. Vincent.
The hard part of Banker's Rounding function is to determine if the fractional part is *exactly* 0.5. Thus, to use ceil and floor , one way (for the positive case) is adding 0.5 to a double value, then judge whether the floor of result number equals to the ceil of result number. And equaty comparison could not avoid incurring inaccuracy, which is not what I want .Dealing with the bit pattern may looks odd, but it is correct. --
Regards, Zhan Jianyu
Sent from cell phone. 在 2013-4-21 上午1:30,"Vincent Povirk" madewokherd@gmail.com写道:
Dealing with the bits of a floating point number directly is a bit odd, and it makes it hard to review the code. Is there a reason you don't want to use things like modf, floor, and ceil?
The man page for modf claims it produces an exact fractional part: http://manpages.ubuntu.com/manpages/quantal/en/man3/modf.3.html
It's possible for modf to do this because the fractional part of a floating point number cannot require more precision than the original value.
So I think you've essentially just rewritten modf. My understanding is that floating point equality comparisons are exact, except in weird cases like NaN.
On Sun, Apr 21, 2013 at 11:05 PM, Vincent Povirk madewokherd@gmail.com wrote:
The man page for modf claims it produces an exact fractional part: http://manpages.ubuntu.com/manpages/quantal/en/man3/modf.3.html
It's possible for modf to do this because the fractional part of a floating point number cannot require more precision than the original value.
So I think you've essentially just rewritten modf. My understanding is that floating point equality comparisons are exact, except in weird cases like NaN.
Oh, thanks for your tips, I will look at it.
--
Regards, Zhan Jianyu