Re: converting float to double
On 21 Dec 2006 21:08:59 -0800, in comp.lang.c , "William Hughes"
<wpihughes@hotm ail.comwrote:
This doesn't follow, unless the currency rounding rule is to select
the closest precise answer, and in that case its tautological.
Several markets and currencies do not follow this rule - eg they
always round down, or always discard pennies, or round up if the
integer part is even, and down if its odd. Or whatever.
If you want "correct" values, you need to implement special handling
routines for rounding.
--
Mark McIntyre
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
On 21 Dec 2006 21:08:59 -0800, in comp.lang.c , "William Hughes"
<wpihughes@hotm ail.comwrote:
>
>Assume possible precise answers are spaced at intervals of the smallest
>currency unit.
>
>We convert the floating point value to a precise answer by
>finding the closest precise answer.
>
>We now see that as long as the error is less that 1/2 of the smallest
>currency spacing, the closest precise answer will also be the
>correct answer.
>Assume possible precise answers are spaced at intervals of the smallest
>currency unit.
>
>We convert the floating point value to a precise answer by
>finding the closest precise answer.
>
>We now see that as long as the error is less that 1/2 of the smallest
>currency spacing, the closest precise answer will also be the
>correct answer.
the closest precise answer, and in that case its tautological.
Several markets and currencies do not follow this rule - eg they
always round down, or always discard pennies, or round up if the
integer part is even, and down if its odd. Or whatever.
If you want "correct" values, you need to implement special handling
routines for rounding.
--
Mark McIntyre
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Comment