[LC++]float, double, or long double?

David Spencer David.W.Spencer at oracle.com
Mon Jan 6 23:03:01 UTC 2003


Ray hong wrote:

>  Dear Sir or Madam,
>
>  
>
> How are you doing?
>
>  
>
I was ok until that greeting - what am I, your bank manager? :-)

> As far as I know, there are the: real (single precision), double 
> (precision), and the complex (precision)
>
> in the Fortran. While in the C or C++, there are also the float 
> (single precision) and the double (precision).
>
> Could you tell me whether there is the better (more accurate) one, 
> something like the "long double"?
>
The most accurate are the integral forms - int, long, long long etc. 
 All floating point representations are approximate.  double stores more 
digits than float, and I think there's a long double as well, but there 
is no complex type in C (but you can use two doubles.)

>  
>
> Currently, I encountered difficulties in the numerical computation. 
> The best way to overcome it is to use
>
> the more accurate data structure. If not possible, I maybe have to the 
> Fortran.
>
What difficulties precisely?  Stuff like 1.9 being represented as 
1.8999999999999947451253 for example?
Fortran won't fix this kind of problem though (unless its maths 
libraries function significantly differently from C's)

Dave.





More information about the tuxCPProgramming mailing list