"yezi" <> writes:
> I have question with the data type problem. According to the C
> standard. IEEE 754
>
> float 4 3.4x10-38E..3.4x10+38E
> double 8 1.7x10-308E..1.7x10+308E
> long double 12 ???
The C standard allows, but does not require, IEEE 754 floating-point.
> The code function is (0.000200-0.000300)*(0.000200-0.000300)
> suppose the result (difference ) should be the 10 (-
>
> difference I claim is double;
>
> But THe code result is :
> fp1 0.000200
> ------------------------
> fp2 0.000300
> difference is 0.000000
>
> which means the result is zero.
It's difficult to tell what problem you're describing. Try posting
some actual code along with the output it produces, and describe how
it differs from the output you expected.
A couple of thoughts:
Floating-point is inexact. For example, the value 0.1 cannot be
represented exactly in binary floating-point; the closest equivalent
in type double, on one system I've tried, is about
0.10000000000000000555111512312578.
If you're using a "%f" output format, it's not going to show very
small values very well. A printed result of 0.000000 doesn't imply
that the value is actually equal to 0.0, just that it's within a
certain range close to 0.0 (which 1.0e-8 probably is). Try the "%g"
format instead; it switches to scientific notation for very large or
very small values.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.