Re: converting float to ascii w/o printf




"Thad Smith" <ThadSmith@xxxxxxx> wrote in message
news:4609b2ec$0$47168$892e0abb@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Wilco Dijkstra wrote:
"Ron Blancarte" <ron@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:c0ui03dctcb8t4s04fmrs65v837jimars1@xxxxxxxxxx

Clearly, the entered value is being stored correctly and the displayed
value, while close, is just slightly off. So is there a way to do
this without this error induced by my multiplications by 10 (and still
not using sprintf()?

The correct way of doing this is to only do one normalizing multiply
or divide by a power of 10, so you only get one roundoff error. Powers
of 10 are exact in floats up to 10^10, for a wider dynamic range you
get multiple roundoff errors unless you use more precision. After
normalization you use integer arithmetic to extract the digits.

Agreed.

My advice would be to use integer-only arithmetic for normalization,
this way you get less roundoff error over much larger ranges.

Hmmm, I don't understand the recommendation here. I would say multiply or divide by the
proper (exact) power of 10 to get a number in the range -9999999..9999999, add a
rounding factor (-0.5 or +0.5), convert to a 32-bit integer, convert that to a 7-digit
character string, then format.

What I mean is that if you do the normalization multiply/divide using
integer arithmetic, you get more precision, eg. 32 bits rathern than 24
when using float. This gives you larger powers of 10 that can be
represented exactly and a more accurate result after normalization
(and more control over rounding). Integer arithmetic makes even more
sense if you use emulated floating point.

Wilco



.



Relevant Pages

  • Re: converting float to ascii w/o printf
    ... this without this error induced by my multiplications by 10 (and still ... or divide by a power of 10, so you only get one roundoff error. ... get multiple roundoff errors unless you use more precision. ... What I mean is that if you do the normalization multiply/divide using ...
    (comp.arch.embedded)
  • shifting bits
    ... result I chose to shift the variables' bits using multiplications and ... divisions by powers of two. ...
    (comp.lang.ada)
  • Re: converting float to ascii w/o printf
    ... this without this error induced by my multiplications by 10 (and still ... or divide by a power of 10, so you only get one roundoff error. ... of 10 are exact in floats up to 10^10, for a wider dynamic range you ... My advice would be to use integer-only arithmetic for normalization, ...
    (comp.arch.embedded)
  • Re: converting float to ascii w/o printf
    ... this without this error induced by my multiplications by 10 (and still ... or divide by a power of 10, so you only get one roundoff error. ... I would say multiply or divide by the proper (exact) power of 10 to get a number in the range -9999999..9999999, add a rounding factor, convert to a 32-bit integer, convert that to a 7-digit character string, then format. ...
    (comp.arch.embedded)
  • Re: How to solve (2x + 3y)^3?
    ... involved in computing the binomial coefficients ... to compute,(quite a few multiplications and divisions ... You're probably right about the powers of 2 and 3, but I guess anyone reasonably well-versed in arithmetic knows the first few by heart. ... practise with it, ...
    (sci.math)