How to display a floating point number by invoking crt_printf?

Started by vraifreud, September 23, 2007, 09:13:20 AM

Previous topic - Next topic

MichaelW

FWIW, this is what the Turbo C++ 3.0 printf does with pi:

            1 2345678901234567890
            3.1415926535897932384626...
float       3.14159274101257324000
            3.1415926535897932384626...
double      3.14159265358979312000
            3.1415926535897932384626...
long double 3.14159265358979324000


This is what VC++ 2003 does:

            1 2345678901234567890
            3.1415926535897932384626...
float       3.14159274101257320000
            3.1415926535897932384626...
double      3.14159265358979310000
            3.1415926535897932384626...
long double 3.14159265358979310000


And this is what FpuFLtoA does:

1 2345678901234567890
3.1415926535897932384626...
3.141592653589793


I think the decision to eliminate long double, despite the existence of well-tested, reliable code to support it, probably indicates that the compiler people did not value those last few digits too highly.
eschew obfuscation

raymond

QuoteI'll probably try to write algo myself 

That would be an excellent learning experience. Go for it. You could always study the source code in the fpulib wich is only one way to arrive at the result. You may then want to use some other approach but you will at least see which precautions must be taken.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com