By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,851 Members | 1,664 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,851 IT Pros & Developers. It's quick & easy.

Question about printing double

P: n/a
1. when a double value is very large, I can not use
iostream(e.g. cout) to print it (but printf works well)
in g++, why ?

2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?

thanks.

Sep 26 '07 #1
Share this Question
Share on Google+
15 Replies


P: n/a
Aman JIANG wrote:
1. when a double value is very large, I can not use
iostream(e.g. cout) to print it (but printf works well)
in g++, why ?
What does it mean "you cannot use std::cout"? did the compiler detect that
the numbers were too large and issue an error message? did the program
crash? was the output not what you expected? ...

2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?
A bug?

Anyway, post some code that exhibits the problem. Maybe your test code has
undefined behavior. If not, your should contact the vendors of your
libraries.
Best

Kai-Uwe Bux
Sep 26 '07 #2

P: n/a
On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Aman JIANG wrote:
1. when a double value is very large, I can not use
iostream(e.g. cout) to print it (but printf works well)
in g++, why ?

What does it mean "you cannot use std::cout"? did the compiler detect that
the numbers were too large and issue an error message? did the program
crash? was the output not what you expected? ...
The program has been built, 0 error(s) and 0 warning(s), it runs, but
no
any message or value has been printed. My OS is XP, you can test.
2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?

A bug?

Anyway, post some code that exhibits the problem. Maybe your test code has
undefined behavior. If not, your should contact the vendors of your
libraries.
I'll show you a simple one:

void f() {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
}
Sep 26 '07 #3

P: n/a
On Sep 26, 6:29 am, Aman JIANG <AmanJI...@gmail.comwrote:
On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Aman JIANG wrote:
1. when a double value is very large, I can not use
iostream(e.g. cout) to print it (but printf works well)
in g++, why ?
What does it mean "you cannot use std::cout"? did the compiler detect that
the numbers were too large and issue an error message? did the program
crash? was the output not what you expected? ...

The program has been built, 0 error(s) and 0 warning(s), it runs, but
no
any message or value has been printed. My OS is XP, you can test.
2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?
A bug?
Anyway, post some code that exhibits the problem. Maybe your test code has
undefined behavior. If not, your should contact the vendors of your
libraries.

I'll show you a simple one:

void f() {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);

}
FWIW, I had no problems. Here's my code:

#include <iostream>
#include <iomanip>
#include <cstdio>

int main(void)
{
double value = 1.23456789e45;
std::cout << std::fixed << value << std::endl;
std::cout << value << std::endl;
printf("%f\n", value);
return 0;
}
And here's the output:

1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000

This was built using g++ on Mac OS X.

There must be something else going on in your code.

Sep 26 '07 #4

P: n/a
On Sep 26, 7:38 pm, John Bode <john_b...@my-deja.comwrote:
On Sep 26, 6:29 am, Aman JIANG <AmanJI...@gmail.comwrote:
On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Aman JIANG wrote:
1. when a double value is very large, I can not use
iostream(e.g. cout) to print it (but printf works well)
in g++, why ?
What does it mean "you cannot use std::cout"? did the compiler detect that
the numbers were too large and issue an error message? did the program
crash? was the output not what you expected? ...
The program has been built, 0 error(s) and 0 warning(s), it runs, but
no
any message or value has been printed. My OS is XP, you can test.
2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?
A bug?
Anyway, post some code that exhibits the problem. Maybe your test code has
undefined behavior. If not, your should contact the vendors of your
libraries.
I'll show you a simple one:
void f() {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
}

FWIW, I had no problems. Here's my code:

#include <iostream>
#include <iomanip>
#include <cstdio>

int main(void)
{
double value = 1.23456789e45;
std::cout << std::fixed << value << std::endl;
std::cout << value << std::endl;
printf("%f\n", value);
return 0;

}

And here's the output:

1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000

This was built using g++ on Mac OS X.

There must be something else going on in your code.
a) My example codes before was just for vc08, not g++.

b) And that my first question which about g++ was just for
XP system, not Mac OS X ... ...

Sep 26 '07 #5

P: n/a
On Sep 26, 7:38 pm, John Bode <john_b...@my-deja.comwrote:
On Sep 26, 6:29 am, Aman JIANG <AmanJI...@gmail.comwrote:
On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Aman JIANG wrote:
1. when a double value is very large, I can not use
iostream(e.g. cout) to print it (but printf works well)
in g++, why ?
What does it mean "you cannot use std::cout"? did the compiler detect that
the numbers were too large and issue an error message? did the program
crash? was the output not what you expected? ...
The program has been built, 0 error(s) and 0 warning(s), it runs, but
no
any message or value has been printed. My OS is XP, you can test.
2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?
A bug?
Anyway, post some code that exhibits the problem. Maybe your test code has
undefined behavior. If not, your should contact the vendors of your
libraries.
I'll show you a simple one:
void f() {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
}

FWIW, I had no problems. Here's my code:

#include <iostream>
#include <iomanip>
#include <cstdio>

int main(void)
{
double value = 1.23456789e45;
std::cout << std::fixed << value << std::endl;
std::cout << value << std::endl;
printf("%f\n", value);
return 0;

}

And here's the output:

1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000

This was built using g++ on Mac OS X.

There must be something else going on in your code.
a) My example codes before was just for vc08, not g++.

b) And that my first question which about g++ was just for
XP system, not Mac OS X ... ...

Sep 26 '07 #6

P: n/a
Aman JIANG wrote:
On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
>Aman JIANG wrote:
1. when a double value is very large, I can not use
iostream(e.g. cout) to print it (but printf works well)
in g++, why ?

What does it mean "you cannot use std::cout"? did the compiler detect
that the numbers were too large and issue an error message? did the
program crash? was the output not what you expected? ...

The program has been built, 0 error(s) and 0 warning(s), it runs, but
no
any message or value has been printed. My OS is XP, you can test.
No, I can't. I don't have XP. But I have g++ on Linux. With the code you
provided and g++ version 4.1.1,I get

1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000

from:

#include <iostream>
#include <cstdio>

using namespace std;

int main ( void ) {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
}
I cannot find a problem.

2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?

A bug?

Anyway, post some code that exhibits the problem. Maybe your test code
has undefined behavior. If not, your should contact the vendors of your
libraries.

I'll show you a simple one:

void f() {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
}
Maybe, there is a bug elsewhere in your code. Instead of giving us a
function, you should follow the FAQ on how-to-post and provide a _complete_
compilable example (e.g., there should be a main function somewhere in your
code).

Best

Kai-Uwe Bux
Sep 26 '07 #7

P: n/a

"Kai-Uwe Bux" <jk********@gmx.netwrote in message
news:fd**********@murdoch.acc.Virginia.EDU...
Aman JIANG wrote:
>On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
>>Aman JIANG wrote:
1. when a double value is very large, I can not use
iostream(e.g. cout) to print it (but printf works well)
in g++, why ?

What does it mean "you cannot use std::cout"? did the compiler detect
that the numbers were too large and issue an error message? did the
program crash? was the output not what you expected? ...

The program has been built, 0 error(s) and 0 warning(s), it runs, but
no
any message or value has been printed. My OS is XP, you can test.

No, I can't. I don't have XP. But I have g++ on Linux. With the code you
provided and g++ version 4.1.1,I get

1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000

from:

#include <iostream>
#include <cstdio>

using namespace std;

int main ( void ) {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
}
I cannot find a problem.
If the OP is trying to run his code directly from Xp he
needs to open a command prompt and run it from
there. If he runs it from the gui, it's going to close the
temp command prompt before he can see the cout.
Or after the cout/printf add:
std::system("pause");

Perhaps that's the problem.
Sep 26 '07 #8

P: n/a
Kai-Uwe Bux wrote:
Aman JIANG wrote:
>On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
>>Aman JIANG wrote:
1. when a double value is very large, I can not use
iostream(e.g. cout) to print it (but printf works well)
in g++, why ?

What does it mean "you cannot use std::cout"? did the compiler
detect that the numbers were too large and issue an error message?
did the program crash? was the output not what you expected? ...

The program has been built, 0 error(s) and 0 warning(s), it runs, but
no
any message or value has been printed. My OS is XP, you can test.

No, I can't. I don't have XP. But I have g++ on Linux. With the code
you provided and g++ version 4.1.1,I get

1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000

from:

#include <iostream>
#include <cstdio>

using namespace std;

int main ( void ) {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
}
I cannot find a problem.
Same code, on VC++ v8 on XP:

1234567889999999900000000000000000000000000000.000 000
1234567890000000000000000000000000000000000000.000 000
>>>2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?

A bug?
Probably.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 26 '07 #9

P: n/a
On Sep 27, 2:45 am, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Aman JIANG wrote:
On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Aman JIANG wrote:
1. when a double value is very large, I can not use
iostream(e.g. cout) to print it (but printf works well)
in g++, why ?
What does it mean "you cannot use std::cout"? did the compiler detect
that the numbers were too large and issue an error message? did the
program crash? was the output not what you expected? ...
The program has been built, 0 error(s) and 0 warning(s), it runs, but
no
any message or value has been printed. My OS is XP, you can test.

No, I can't. I don't have XP. But I have g++ on Linux. With the code you
provided and g++ version 4.1.1,I get

1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000

from:

#include <iostream>
#include <cstdio>

using namespace std;

int main ( void ) {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);

}

I cannot find a problem.
2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?
A bug?
Anyway, post some code that exhibits the problem. Maybe your test code
has undefined behavior. If not, your should contact the vendors of your
libraries.
I'll show you a simple one:
void f() {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
}

Maybe, there is a bug elsewhere in your code. Instead of giving us a
function, you should follow the FAQ on how-to-post and provide a _complete_
compilable example (e.g., there should be a main function somewhere in your
code).

Best

Kai-Uwe Bux
I have no idea ... that you said you donnot have a XP system,
but this problem is just depend on OS and compiler.

Sep 27 '07 #10

P: n/a
On Sep 27, 3:38 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Kai-Uwe Bux wrote:
Aman JIANG wrote:
On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Aman JIANG wrote:
1. when a double value is very large, I can not use
iostream(e.g. cout) to print it (but printf works well)
in g++, why ?
>What does it mean "you cannot use std::cout"? did the compiler
detect that the numbers were too large and issue an error message?
did the program crash? was the output not what you expected? ...
The program has been built, 0 error(s) and 0 warning(s), it runs, but
no
any message or value has been printed. My OS is XP, you can test.
No, I can't. I don't have XP. But I have g++ on Linux. With the code
you provided and g++ version 4.1.1,I get
1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000
from:
#include <iostream>
#include <cstdio>
using namespace std;
int main ( void ) {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
}
I cannot find a problem.

Same code, on VC++ v8 on XP:

1234567889999999900000000000000000000000000000.000 000
1234567890000000000000000000000000000000000000.000 000
>>2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?
>A bug?

Probably.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Okay... what about this one, the whole program:

#include <iostream>
#include <limits>
#include <cstdio>
using namespace std;

void f() {
double value = numeric_limits<double>::max();
for (int i = 0; i < 7; ++i) {
cout << "++++++++++++++++++++" << endl;
cout << fixed << value << endl;
printf("%f\n", value);
for (int i = 0; i < 20; ++i)
value *= 0.01;
}
}

int main()
{
f();
}
My result was:

++++++++++++++++++++
17976931348623161000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
17976931348623157000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
++++++++++++++++++++
17976931348623163000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.000000
17976931348623169000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.000000
++++++++++++++++++++
17976931348623163000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
17976931348623172000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
++++++++++++++++++++
17976931348623183000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.000000
17976931348623180000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.000000
++++++++++++++++++++
17976931348623183000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
17976931348623182000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
++++++++++++++++++++
17976931348623189000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.000000
17976931348623190000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.000000
++++++++++++++++++++
17976931348623202000000000000000000000000000000000 0000000000000000000.000000
17976931348623199000000000000000000000000000000000 0000000000000000000.000000
And what's yours, please ?

Sep 27 '07 #11

P: n/a
Aman JIANG wrote:
On Sep 27, 3:38 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>Kai-Uwe Bux wrote:
Aman JIANG wrote:
>On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Aman JIANG wrote:
1. when a double value is very large, I can not use
iostream(e.g. cout) to print it (but printf works well)
in g++, why ?
>>What does it mean "you cannot use std::cout"? did the compiler
detect that the numbers were too large and issue an error message?
did the program crash? was the output not what you expected? ...
>The program has been built, 0 error(s) and 0 warning(s), it runs, but
no
any message or value has been printed. My OS is XP, you can test.
No, I can't. I don't have XP. But I have g++ on Linux. With the code
you provided and g++ version 4.1.1,I get
1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000
from:
#include <iostream>
#include <cstdio>
using namespace std;
int main ( void ) {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
}
I cannot find a problem.

Same code, on VC++ v8 on XP:

1234567889999999900000000000000000000000000000.00 0000
1234567890000000000000000000000000000000000000.00 0000
>>>2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?
>>A bug?

Probably.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Okay... what about this one, the whole program:

#include <iostream>
#include <limits>
#include <cstdio>
using namespace std;

void f() {
double value = numeric_limits<double>::max();
for (int i = 0; i < 7; ++i) {
cout << "++++++++++++++++++++" << endl;
cout << fixed << value << endl;
printf("%f\n", value);
for (int i = 0; i < 20; ++i)
value *= 0.01;
}
}
Ok. One possibility is that you are seeing artifacts from compiler
optimization. The C++ standard permits floats to be represented with higher
precision in CPU registers. Only when written to memory are those excess
digits lost. If the compiler optimizes away some writes to memory, it might
appear that the value of the variable changes magically between two points
of access.

Try declaring

double volatile value

(I don't know if that helps, but I think it might).

Also, your compiler probably has some switches that controll optimization f
floating point arithmetic.
int main()
{
f();
}
My result was:

++++++++++++++++++++
17976931348623161000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
>
17976931348623157000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
++++++++++++++++++++
17976931348623163000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.000000
17976931348623169000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.000000
++++++++++++++++++++
17976931348623163000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
>
17976931348623172000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
++++++++++++++++++++
17976931348623183000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.000000
17976931348623180000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.000000
++++++++++++++++++++
17976931348623183000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
>
17976931348623182000000000000000000000000000000000 000000000000000000000000000000
>
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
++++++++++++++++++++
17976931348623189000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.000000
17976931348623190000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.000000
++++++++++++++++++++
17976931348623202000000000000000000000000000000000 0000000000000000000.000000
>
17976931348623199000000000000000000000000000000000 0000000000000000000.000000
>

And what's yours, please ?

++++++++++++++++++++
17976931348623157081452742373170435679807056752584 49965989174768031572607800285387605895586327668781 71540458953514382464234321326889464182768467546703 53751698604991057655128207624549009038932894407586 85084551339423045832369032229481658085593321233482 74797826204144723168738177180919299881250404026184 124858368.000000
17976931348623157081452742373170435679807056752584 49965989174768031572607800285387605895586327668781 71540458953514382464234321326889464182768467546703 53751698604991057655128207624549009038932894407586 85084551339423045832369032229481658085593321233482 74797826204144723168738177180919299881250404026184 124858368.000000
++++++++++++++++++++
17976931348623168803535103715102371936956876099477 02702141689666572909556250171678295311235774929133 77429477075922398159003872026533981994017157930965 40036137152752946476437620203845856055675848407785 66865660436247586535451385853201414325080542802044 2630978199812571136.000000
17976931348623168803535103715102371936956876099477 02702141689666572909556250171678295311235774929133 77429477075922398159003872026533981994017157930965 40036137152752946476437620203845856055675848407785 66865660436247586535451385853201414325080542802044 2630978199812571136.000000
++++++++++++++++++++
17976931348623171849786541014958455787798926170036 13451168130107163462505465704834010736734883887699 94822679814457092827304161765579176761651716704122 77012638102071565755338305263916723763735250852347 53899083930760905818275577856.000000
17976931348623171849786541014958455787798926170036 13451168130107163462505465704834010736734883887699 94822679814457092827304161765579176761651716704122 77012638102071565755338305263916723763735250852347 53899083930760905818275577856.000000
++++++++++++++++++++
17976931348623180334121130800512705664326599659323 09596391036156164582179293175260943956591811422387 79925433505180572176304271562985878751258358863773 650012083645864786519533819782081019904.000000
17976931348623180334121130800512705664326599659323 09596391036156164582179293175260943956591811422387 79925433505180572176304271562985878751258358863773 650012083645864786519533819782081019904.000000
++++++++++++++++++++
17976931348623181586724979444854831637051379627365 10146554741473569448882659539702768344431724585762 1991662199371641181642702350033510153168128835584. 000000
17976931348623181586724979444854831637051379627365 10146554741473569448882659539702768344431724585762 1991662199371641181642702350033510153168128835584. 000000
++++++++++++++++++++
17976931348623190044383294395538695880988582027861 80889326404644101794303230278148231539669010545381 356863488.000000
17976931348623190044383294395538695880988582027861 80889326404644101794303230278148231539669010545381 356863488.000000
++++++++++++++++++++
17976931348623199233534334757853551603231158205077 2848940056867504128.000000
17976931348623199233534334757853551603231158205077 2848940056867504128.000000

Best

Kai-Uwe Bux

Sep 27 '07 #12

P: n/a
On 2007-09-27 01:35:46 -0400, Kai-Uwe Bux <jk********@gmx.netsaid:
17976931348623199233534334757853551603231158205077 2848940056867504128.000000
17976931348623199233534334757853551603231158205077 2848940056867504128.000000
Also known as "false precision".

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Sep 27 '07 #13

P: n/a
On Sep 27, 1:50 pm, Pete Becker <p...@versatilecoding.comwrote:
On 2007-09-27 01:35:46 -0400, Kai-Uwe Bux <jkherci...@gmx.netsaid:
17976931348623199233534334757853551603231158205077 2848940056867504128.000000
17976931348623199233534334757853551603231158205077 2848940056867504128.000000
Also known as "false precision".
Or garbage. The real problem, IMHO, is in the orginal request.
Asking for more than 300 digits of a floating point number, when
(on most machines), it only has 17 digits precision. In a very
real sense, anything beyond the first 17 digits is garbage, and
anything the compiler outputs is "correct". (Practically
speaking, of course, outputting 0's is the best solution,
because it does look like the rounding it is. But I have my
doubts about a program which requests such a thing to begin
with.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Sep 28 '07 #14

P: n/a
On Sep 27, 7:06 am, Aman JIANG <AmanJI...@gmail.comwrote:
On Sep 27, 2:45 am, Kai-Uwe Bux <jkherci...@gmx.netwrote:
[...]
I have no idea ... that you said you donnot have a XP system,
but this problem is just depend on OS and compiler.
The problem depends on the implementation of the library, and
perhaps on the compiler (or the compiler flags) with which it
was compiled.

In many cases, different parts of the library have difference
sources. On most Unix systems, for example, g++ will use
libstdc++ (it's own implementation) for the iostream's, but will
use the implementation in libc (bundled with the system) for the
printf family---given the irrelevance of the digits you're
asking for, and the anomalies which may be associated with
floating point rounding, it's not too surprising that the
results aren't exactly the same. Rounded to 17 significant
digits, they should be the same, but beyond that, it's really
just noise. (I'm not sure what the situation is with VC++. I
know that Dinkumware provides the C++ library, but I wouldn't be
surprised if the printf stuff were some legacy Microsoft code.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Sep 28 '07 #15

P: n/a
On 2007-09-28 03:25:01 -0400, James Kanze <ja*********@gmail.comsaid:
On Sep 27, 1:50 pm, Pete Becker <p...@versatilecoding.comwrote:
>On 2007-09-27 01:35:46 -0400, Kai-Uwe Bux <jkherci...@gmx.netsaid:
>>179769313486231992335343347578535516032311582050 772848940056867504128.0
00000
>>179769313486231992335343347578535516032311582050 772848940056867504128.0
00000
>Also known as "false precision".

Or garbage.
"False precision" is the polite term. <gLike when someone converts
"about an inch" to "about 2.54 centimeters", making the value look much
more precise than it actually is.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Sep 28 '07 #16

This discussion thread is closed

Replies have been disabled for this discussion.