473,394 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Question about printing double

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
15 1761
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
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
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
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
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
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

"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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Master of C++ | last post by:
Hello Folks, I have a programming dilemma with templates and "genericity". I can think of a few solutions, but I am not sure which one is the best in terms of genetic C++ style. Any suggestions...
11
by: theshowmecanuck | last post by:
As a matter of academic interest only, is there a way to programmatically list the 'c' data types? I am not looking for detail, just if it is possible, and what function could be used to...
14
by: philbo30 | last post by:
Silly question, I know, but I have a code snippet that looks like this: printf("blah blah"); printf("more blah"); x = a + b - c; printf($%3.2f\n", x); y = d + e; printf($%3.2f\n, y);
1
by: ghostdog | last post by:
I've got problem with printing out double type. int xx=1, yy=1, zz=0, i=46; float xxx=1, yyy=1, zzz=0; long double x=1, y=1, z=0; for(int i = 0;i<r;i++) { zz=xx; zzz=xxx;...
9
by: junky_fellow | last post by:
Hi, To print the pointer using printf(), we convert it to (void *) . printf("%p",(void *)ptr); My question is how printf() determine which type of pointer is passed to it and prints its value...
2
by: Kool-Aide | last post by:
Alright, here goes...When I put a menu strip on the windows form I can double click the exit button to go to the source page and it takes me to the on click exit blah blah blah and you would put...
6
by: Jojo | last post by:
Hi all, I was wondering how I can perform formatted output with C++ strings. For example, suppose I have in plain C: sprintf(C_string, "%5.2f %6d"); How can I do such a thing with C++...
2
by: rlntemp-gng | last post by:
Re: Access 2003 My client has a printer that can print single-sided or double-sided. The default settings for this printer in Windows is double-sided printing for the bulk of their work. ...
7
by: Ouroborus777 | last post by:
I've been messing around with printing floats. It seems that printf() is only capable of printing the fractional portion at a fixed length. Is there some way to print floats such that the full...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.