Re: Problem in Float Arithmetic



On Sat, 05 Jul 2008 14:34:30 -0400, Joseph M. Newcomer
<newcomer@xxxxxxxxxxxx> wrote:

When integers and integers only are represented as doubles, and the operations are limited
to add, subtract, and multiply, then the precision of a double is the same as the
precision of an integer of the same number of bits of significance as the mantissa of the
floating point number. The problem, for example, is that 'float' has fewer bits than
'int', so it only becomes interesting when you start using 'double'.

Right, I couldn't imagine using anything but double for this. However, if
int was 16 bits, the usual 32 bit float could work (23 bit mantissa), but
it would almost certainly be better to use long, which has at least 32
bits. The only exception I can think of is some weird hardware that has a
fast FPU but a really lousy ALU that can't do 32 bit integers.

Once "divide" comes into play, life gets very dicey even if the only values are initially
integral.
joe

What I said to David was:

<q>
Floating point arithmetic on integer values that produces integer values is
exact over a wide range, something like +/- 2^53 for double.
</q>

I did not mean anything but exactly what I wrote. Are you saying it's not
true for division? (If not, too bad for languages like Perl, I guess.)

--
Doug Harrison
Visual C++ MVP
.



Relevant Pages

  • Re: float vs. double?
    ... There have been repeated myths that float is faster than double. ... In antique machines, the ... Note that the floating-point ALU of Intel chips supports an 80-bit floating point number, ... is different precision being stored? ...
    (microsoft.public.vc.mfc)
  • Re: Floating Point Precision
    ... > I have a question about floating point precision in C. ... The relative error (loosely speaking, the precision) ... It is the difference between 1.0f and the "next" float value, ... a field known as "Numerical Analysis." ...
    (comp.lang.c)
  • Re: Good C Question | pointer problem
    ... int main{ ... This allocates an array of 100 chars and putting the result in ptr. ... This will give you 100/sizeof (float) entries. ... You did not store any floating point values at fpor fp ...
    (comp.programming)
  • Re: static_cast<unsigned int> question...
    ... > unsigned int test2; ... This is caused by the way the float type store number internally. ... floating point value to: ... This is also the reason why comparing two floating point values with the ...
    (comp.lang.cpp)
  • Re: Interesting math
    ... Floating point number represents a real number with 6 digits precision. ... Floating point numbers are denoted by the keyword float. ...
    (alt.usage.english)