Connecting Tech Pros Worldwide Help | Site Map

Question about printing double

  #1  
Old September 26th, 2007, 08:25 AM
Aman JIANG
Guest
 
Posts: 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.

  #2  
Old September 26th, 2007, 08:55 AM
Kai-Uwe Bux
Guest
 
Posts: n/a

re: Question about printing double


Aman JIANG wrote:
Quote:
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? ...

Quote:
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
  #3  
Old September 26th, 2007, 12:35 PM
Aman JIANG
Guest
 
Posts: n/a

re: Question about printing double


On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Quote:
Aman JIANG wrote:
Quote:
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.
Quote:
Quote:
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);
}


  #4  
Old September 26th, 2007, 12:45 PM
John Bode
Guest
 
Posts: n/a

re: Question about printing double


On Sep 26, 6:29 am, Aman JIANG <AmanJI...@gmail.comwrote:
Quote:
On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
>
Quote:
Aman JIANG wrote:
Quote:
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 ?
>
Quote:
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.
>
Quote:
Quote:
2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?
>
Quote:
A bug?
>
Quote:
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.

  #5  
Old September 26th, 2007, 01:45 PM
Aman JIANG
Guest
 
Posts: n/a

re: Question about printing double


On Sep 26, 7:38 pm, John Bode <john_b...@my-deja.comwrote:
Quote:
On Sep 26, 6:29 am, Aman JIANG <AmanJI...@gmail.comwrote:
>
>
>
Quote:
On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
>
Quote:
Quote:
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 ?
>
Quote:
Quote:
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? ...
>
Quote:
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.
>
Quote:
Quote:
2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?
>
Quote:
Quote:
A bug?
>
Quote:
Quote:
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.
>
Quote:
I'll show you a simple one:
>
Quote:
void f() {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
>
Quote:
}
>
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 ... ...

  #6  
Old September 26th, 2007, 01:55 PM
Aman JIANG
Guest
 
Posts: n/a

re: Question about printing double


On Sep 26, 7:38 pm, John Bode <john_b...@my-deja.comwrote:
Quote:
On Sep 26, 6:29 am, Aman JIANG <AmanJI...@gmail.comwrote:
>
>
>
Quote:
On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
>
Quote:
Quote:
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 ?
>
Quote:
Quote:
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? ...
>
Quote:
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.
>
Quote:
Quote:
2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?
>
Quote:
Quote:
A bug?
>
Quote:
Quote:
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.
>
Quote:
I'll show you a simple one:
>
Quote:
void f() {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
>
Quote:
}
>
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 ... ...

  #7  
Old September 26th, 2007, 08:05 PM
Kai-Uwe Bux
Guest
 
Posts: n/a

re: Question about printing double


Aman JIANG wrote:
Quote:
On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Quote:
>Aman JIANG wrote:
Quote:
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.

Quote:
Quote:
Quote:
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
  #8  
Old September 26th, 2007, 08:45 PM
duane hebert
Guest
 
Posts: n/a

re: Question about printing double



"Kai-Uwe Bux" <jkherciueh@gmx.netwrote in message
news:fde9cf$eo8$1@murdoch.acc.Virginia.EDU...
Quote:
Aman JIANG wrote:
>
Quote:
>On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Quote:
>>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.


  #9  
Old September 26th, 2007, 08:45 PM
Victor Bazarov
Guest
 
Posts: n/a

re: Question about printing double


Kai-Uwe Bux wrote:
Quote:
Aman JIANG wrote:
>
Quote:
>On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Quote:
>>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
Quote:
Quote:
Quote:
>>>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


  #10  
Old September 27th, 2007, 06:15 AM
Aman JIANG
Guest
 
Posts: n/a

re: Question about printing double


On Sep 27, 2:45 am, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Quote:
Aman JIANG wrote:
Quote:
On Sep 26, 3:41 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Quote:
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 ?
>
Quote:
Quote:
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? ...
>
Quote:
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.
>
>
>
Quote:
Quote:
2. when a double value is very large, the printed results
were different between iostream(e.g. cout) and printf
in vc08, why ?
>
Quote:
Quote:
A bug?
>
Quote:
Quote:
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.
>
Quote:
I'll show you a simple one:
>
Quote:
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.

  #11  
Old September 27th, 2007, 06:15 AM
Aman JIANG
Guest
 
Posts: n/a

re: Question about printing double


On Sep 27, 3:38 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Quote:
Kai-Uwe Bux wrote:
Quote:
Aman JIANG wrote:
>
Quote:
Quote:
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 ?
>
Quote:
Quote:
>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? ...
>
Quote:
Quote:
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.
>
Quote:
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
>
Quote:
1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000
>
Quote:
from:
>
Quote:
#include <iostream>
#include <cstdio>
>
Quote:
using namespace std;
>
Quote:
int main ( void ) {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
}
>
Quote:
I cannot find a problem.
>
Same code, on VC++ v8 on XP:
>
1234567889999999900000000000000000000000000000.000 000
1234567890000000000000000000000000000000000000.000 000
>
Quote:
Quote:
>>2. when a double value is very large, the printed results
>> were different between iostream(e.g. cout) and printf
>> in vc08, why ?
>
Quote:
Quote:
>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 ?

  #12  
Old September 27th, 2007, 06:55 AM
Kai-Uwe Bux
Guest
 
Posts: n/a

re: Question about printing double


Aman JIANG wrote:
Quote:
On Sep 27, 3:38 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Quote:
>Kai-Uwe Bux wrote:
Quote:
Aman JIANG wrote:
>>
Quote:
>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 ?
>>
Quote:
>>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? ...
>>
Quote:
>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.
>>
Quote:
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
>>
Quote:
1234567889999999964160667452302023944549957632.000 000
1234567889999999964160667452302023944549957632.000 000
>>
Quote:
from:
>>
Quote:
#include <iostream>
#include <cstdio>
>>
Quote:
using namespace std;
>>
Quote:
int main ( void ) {
double value = 1.23456789e45;
cout << fixed << value << endl;
printf ("%f\n", value);
}
>>
Quote:
I cannot find a problem.
>>
>Same code, on VC++ v8 on XP:
>>
>1234567889999999900000000000000000000000000000.00 0000
>1234567890000000000000000000000000000000000000.00 0000
>>
Quote:
>>>2. when a double value is very large, the printed results
>>> were different between iostream(e.g. cout) and printf
>>> in vc08, why ?
>>
Quote:
>>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.


Quote:
int main()
{
f();
}
>
>
My result was:
>
++++++++++++++++++++
>
17976931348623161000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
Quote:
>
17976931348623157000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
Quote:
++++++++++++++++++++
>
17976931348623163000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
Quote:
00000000000000000000000000000.000000
>
17976931348623169000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
Quote:
00000000000000000000000000000.000000
++++++++++++++++++++
>
17976931348623163000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
Quote:
>
17976931348623172000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
Quote:
++++++++++++++++++++
>
17976931348623183000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
Quote:
00000000000000000000000000000.000000
>
17976931348623180000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
Quote:
00000000000000000000000000000.000000
++++++++++++++++++++
>
17976931348623183000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
Quote:
>
17976931348623182000000000000000000000000000000000 000000000000000000000000000000
Quote:
>
00000000000000000000000000000000000000000000000000 0000000000000000000.000000
Quote:
++++++++++++++++++++
>
17976931348623189000000000000000000000000000000000 000000000000000000000000000000
Quote:
00000000000000000000000000000.000000
>
17976931348623190000000000000000000000000000000000 000000000000000000000000000000
Quote:
00000000000000000000000000000.000000
++++++++++++++++++++
>
17976931348623202000000000000000000000000000000000 0000000000000000000.000000
Quote:
>
17976931348623199000000000000000000000000000000000 0000000000000000000.000000
Quote:
>
>
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

  #13  
Old September 27th, 2007, 12:55 PM
Pete Becker
Guest
 
Posts: n/a

re: Question about printing double


On 2007-09-27 01:35:46 -0400, Kai-Uwe Bux <jkherciueh@gmx.netsaid:
Quote:
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)

  #14  
Old September 28th, 2007, 08:25 AM
James Kanze
Guest
 
Posts: n/a

re: Question about printing double


On Sep 27, 1:50 pm, Pete Becker <p...@versatilecoding.comwrote:
Quote:
On 2007-09-27 01:35:46 -0400, Kai-Uwe Bux <jkherci...@gmx.netsaid:
Quote:
Quote:
17976931348623199233534334757853551603231158205077 2848940056867504128.000000
17976931348623199233534334757853551603231158205077 2848940056867504128.000000
Quote:
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:james.kanze@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

  #15  
Old September 28th, 2007, 08:35 AM
James Kanze
Guest
 
Posts: n/a

re: Question about printing double


On Sep 27, 7:06 am, Aman JIANG <AmanJI...@gmail.comwrote:
Quote:
On Sep 27, 2:45 am, Kai-Uwe Bux <jkherci...@gmx.netwrote:
[...]
Quote:
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:james.kanze@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

  #16  
Old September 28th, 2007, 01:45 PM
Pete Becker
Guest
 
Posts: n/a

re: Question about printing double


On 2007-09-28 03:25:01 -0400, James Kanze <james.kanze@gmail.comsaid:
Quote:
On Sep 27, 1:50 pm, Pete Becker <p...@versatilecoding.comwrote:
Quote:
>On 2007-09-27 01:35:46 -0400, Kai-Uwe Bux <jkherci...@gmx.netsaid:
>
Quote:
Quote:
>>179769313486231992335343347578535516032311582050 772848940056867504128.0
00000
Quote:
Quote:
>>179769313486231992335343347578535516032311582050 772848940056867504128.0
00000
>
Quote:
>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)

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
formatted output question with strings Jojo answers 6 July 25th, 2007 09:15 AM
Had a question about the menustrip Kool-Aide answers 2 May 23rd, 2007 06:05 AM
Strange behaviour of tiny double numbers soeren@all-about-shift.com answers 5 June 19th, 2006 09:15 AM
Multiple Double Linked Lists Little answers 3 January 27th, 2006 09:25 AM