 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
John Ratliff Guest
|
Posted: Wed Sep 28, 2005 11:29 pm Post subject: primitive range |
|
|
Is there a guaranteed minimum size for the primitive double?
I need to know if I can store 5.12 * 2^32 - 1 in a double.
http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5
Only talks about minimum sizes for integer values. It doesn't say
anything about float or double.
Thanks,
--John Ratliff
|
|
| Back to top |
|
 |
Mark P Guest
|
Posted: Thu Sep 29, 2005 12:01 am Post subject: Re: primitive range |
|
|
John Ratliff wrote:
| Quote: | Is there a guaranteed minimum size for the primitive double?
I need to know if I can store 5.12 * 2^32 - 1 in a double.
http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5
Only talks about minimum sizes for integer values. It doesn't say
anything about float or double.
Thanks,
--John Ratliff
|
Not sure if this fits the bill, but you may want to check
numeric_limits<double>::epsilon defined in <limits>
|
|
| Back to top |
|
 |
red floyd Guest
|
Posted: Thu Sep 29, 2005 12:57 am Post subject: Re: primitive range |
|
|
John Ratliff wrote:
| Quote: | Is there a guaranteed minimum size for the primitive double?
I need to know if I can store 5.12 * 2^32 - 1 in a double.
http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5
Only talks about minimum sizes for integer values. It doesn't say
anything about float or double.
Thanks,
--John Ratliff
|
The standard says that the rep for a floating point value is
implementation defined (3.9.1/ . It also says to use
std::numeric_limits<> (18.2) for any given type.
However most implementations of double that I've seen use IEEE 64 bit
rep (1 sign, 10 bit exponent, 53 bit normalized mantissa). The real so
a double probably could. The other issue is that I'm not sure that 5.12
is exactly representable as a double (It may be an infinitely recurring
binary fraction).
|
|
| Back to top |
|
 |
John Ratliff Guest
|
Posted: Thu Sep 29, 2005 3:55 am Post subject: Re: primitive range |
|
|
red floyd wrote:
| Quote: | John Ratliff wrote:
Is there a guaranteed minimum size for the primitive double?
I need to know if I can store 5.12 * 2^32 - 1 in a double.
http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5
Only talks about minimum sizes for integer values. It doesn't say
anything about float or double.
Thanks,
--John Ratliff
The standard says that the rep for a floating point value is
implementation defined (3.9.1/ . It also says to use
std::numeric_limits<> (18.2) for any given type.
However most implementations of double that I've seen use IEEE 64 bit
rep (1 sign, 10 bit exponent, 53 bit normalized mantissa). The real so
a double probably could. The other issue is that I'm not sure that 5.12
is exactly representable as a double (It may be an infinitely recurring
binary fraction).
|
Okay. This is my test progam. I get the right value, but I want to make
sure my conversion is okay.
#include <cmath>
#include <iostream>
int main(int, char **) {
double factor = 256.0 / 50.0;
double time = (0xFFFFFFFF * factor);
double temp;
temp = time / 3600;
std::cout << "hours = " << static_cast
temp = fmod(time / 60, 60);
std::cout << "minutes = " << static_cast
temp = fmod(time, 60);
if ((temp - floor(temp)) >= 0.5) ++temp;
std::cout << "seconds = " << static_cast
return 0;
}
When I round the seconds, will that be valid, or do I need to do
something more like:
if ((floor((temp - floor(temp)) * 10) / 10) >= 0.5) ++temp;
Thanks,
--John Ratliff
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|