www.digitalmars.com         C & C++   DMDScript  

D - D floating point

reply John Fletcher <J.P.Fletcher aston.ac.uk> writes:
I am experimenting with this.

I can do

extended x = 1.;
printf("%lf\n",(double)x);

It needs the cast to get the correct answer.

I was trying to do sprintf() to put it into a buffer, but sprintf would
not compile.

John
Jan 25 2002
parent reply Russell Borogove <kaleja estarcion.com> writes:
John Fletcher wrote:

 extended x = 1.;
 printf("%lf\n",(double)x);
 
 It needs the cast to get the correct answer.
My guess is that, since printf is currently coming from a C library, its floating point support is going to match that of the C implementation. A reading of the Digital Mars C library docs suggest you might try a capital L in the format spec: printf( "%Lf\n", x ); ...but that's just a guess on my part. -Russell B
Jan 25 2002
parent reply "Walter" <walter digitalmars.com> writes:
Yes, you need the Lf for "long double", which matches D's
"extended". -Walter

Why doesn't sprintf work for you? I use it!

"Russell Borogove" <kaleja estarcion.com> wrote in message
news:3C51A3B4.5030602 estarcion.com...
 John Fletcher wrote:

 extended x = 1.;
 printf("%lf\n",(double)x);

 It needs the cast to get the correct answer.
My guess is that, since printf is currently coming from a C library, its floating point support is going to match that of the C implementation. A reading of the Digital Mars C library docs suggest you might try a capital L in the format spec: printf( "%Lf\n", x ); ...but that's just a guess on my part. -Russell B
Jan 25 2002
next sibling parent John Fletcher <J.P.Fletcher aston.ac.uk> writes:
Walter wrote:

 Yes, you need the Lf for "long double", which matches D's
 "extended". -Walter
Thank you.
 Why doesn't sprintf work for you? I use it!
I don't know, I couldn't get it to compile, so I dug in the phobos code and saw an example. I'll look again. Thanks for the answer, Walter and Russell. John
Jan 28 2002
prev sibling parent reply John Fletcher <J.P.Fletcher aston.ac.uk> writes:
Walter wrote:

 Yes, you need the Lf for "long double", which matches D's
 "extended". -Walter

 Why doesn't sprintf work for you? I use it!
Walter I can get sprintf to work as long as I don't have printf as well, when I get a conflict of definitions of printf between object.printf and stdio.printf. John
Jan 28 2002
parent "Walter" <walter digitalmars.com> writes:
Just comment out one of them. I'll fix it at my end. -Walter

"John Fletcher" <J.P.Fletcher aston.ac.uk> wrote in message
news:3C55262C.57E5ABB1 aston.ac.uk...
 Walter wrote:

 Yes, you need the Lf for "long double", which matches D's
 "extended". -Walter

 Why doesn't sprintf work for you? I use it!
Walter I can get sprintf to work as long as I don't have printf as well, when I get a conflict of definitions of printf between object.printf and stdio.printf. John
Jan 28 2002