473,396 Members | 2,023 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,396 software developers and data experts.

std::numeric_limits::max()

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

Similar topics

5
by: Gianni Mariani | last post by:
The spirit of this arguably pointless exercise, is that the numeric_limits<T> class could be replaced with a totally generic template of compile-time, template computed constants. The problem is...
5
by: PengYu.UT | last post by:
Hi, Would you please let me know where max and min int are defined in C++? Best wishes, Peng
1
by: Vijai Kalyan | last post by:
Oops, maybe that is the standard. I don't have a copy unfortunately, but here goes. I was experimenting and wrote the following code: #include <limits.h> #include <stdexcept> #include <sstream>...
3
by: puzzlecracker | last post by:
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); I have seen it in faq - what does it do, exactly?
35
by: Frederick Gotham | last post by:
I'm writing a template, and I need to know the maximum value of a given integer type at compile time. something like: template<class NumType> class Arb { public: static NumType const max =...
1
by: liam_herron | last post by:
Does anyone know why this is? Is there a compile flag to have this return 'inf' as opposed to zero? Any help would be much appreciated. I have included a sample program with sample output: ...
41
by: Gary Wessle | last post by:
Hi often I need to read numbers and only keep the highest or lowest. so I do something like int uLimit = 0; int lLimit = 999999999999; //hoping the compiler will not complain uLimit =...
5
by: aaragon | last post by:
Hi everyone, I wrote a very simple function to try to understand the casting of variables in C++. The function is function foo() { std::vector<inttest(100); randomize(test); unsigned long...
4
by: john | last post by:
The code: #include <iostream> #include <limits> int main() { using namespace std;
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.