std::numeric_limits::max()

C

Christopher

I am trying to calculate a number of sums a double can hold with a max
addend of x. I performed the following computation:

cout<<std::numeric_limits<double>::max()<<endl;
cout<<std::numeric_limits<double>::max() / x<<endl;

when x = 10 I got the following output:
4294967295
1.79769e+307

is the computation to find the number of computations itself overflowing?

How can I accomplish my goal?

I am trying to do this to effectivley write a test program to average the
results of a function and need to figure how many iterations to do before
division.

Thank you,
Christopher
 
A

Alf P. Steinbach

* Christopher:
I am trying to calculate a number of sums a double can hold with a max
addend of x. I performed the following computation:

cout<<std::numeric_limits<double>::max()<<endl;
cout<<std::numeric_limits<double>::max() / x<<endl;

when x = 10 I got the following output:
4294967295
1.79769e+307

is the computation to find the number of computations itself overflowing?

The first result is incorrect for any implementation.

But I think it's more likely that it isn't actually the result
from the first statement shown; instead it's probably -1 assigned
to an unsigned int -- i.e. you have _not_ shown the actual code.

The second result is what you'd expect for IEEE 64-bit double.


How can I accomplish my goal?

I am trying to do this to effectivley write a test program to average the
results of a function and need to figure how many iterations to do before
division.

That makes no sense to me.

Here's one way: scale the function result down by 10^12.

Then you can do at least 10^12 additions before overflow.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top