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

std::numeric_limits::max()

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
* 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.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.