value

G

green.sany

Hi everyone,

I need to store some very big positive floating values in my C++
program. For example, 50e+15. Which number type I should use? Is
"double" big enough?

Thanks.
 
J

Jens Theisen

Hi everyone,

I need to store some very big positive floating values in my C++
program. For example, 50e+15. Which number type I should use? Is
"double" big enough?

It's fine on x86 platforms, though I'm not sure on the language
requirements.

If double wasn't enough, there wouldn't be much feasible alternative
anyway.

Regards,

Jens
 
K

Kai-Uwe Bux

To the OP: you can find out using

#include <iostream>
#include <limits>

int main ( void ) {
std::cout << "float max: "
<< std::numeric_limits<float>::max() << '\n';
std::cout << "double max: "
<< std::numeric_limits<double>::max() << '\n';
std::cout << "long double max: "
It's fine on x86 platforms, though I'm not sure on the language
requirements.

If double wasn't enough, there wouldn't be much feasible alternative
anyway.

Well, there is long double.


Best

Kai-Uwe Bux
 
P

Phlip

Jens said:
(e-mail address removed) writes:

It's fine on x86 platforms, though I'm not sure on the language
requirements.

If double wasn't enough, there wouldn't be much feasible alternative
anyway.

Big numbers lose precision before their technical limits. The problem might
need a "rational" type, a "decimal" type, a "fixnum" type, or a "bigint"
type. Googling for those will reveal many arbitrary-precision libraries, and
one will probably fit the problem.
 
H

Hooyoo

Jens Theisen 写é“:
It's fine on x86 platforms, though I'm not sure on the language
requirements.

If double wasn't enough, there wouldn't be much feasible alternative
anyway.

Regards,

Jens

You can store the base number and the index number sparately.
 
P

Pete Becker

I need to store some very big positive floating values in my C++
program. For example, 50e+15. Which number type I should use? Is
"double" big enough?

double will always be big enough to hold 50e+15 (which isn't all that
big). Querying your implementation for its limits tells you what its
limits are, but doesn't tell you what you can rely on from other
compilers. The language definition does that, and it says that double
must support exponents ranging from -37 to 37, inclusive, and that it
must support at least 10 decimal digits. (That's spelled out in sections
12.2.2 and 12.2.3 of my book) Despite the advice you've been given, you
shouldn't design new data types until you've determined that the builtin
ones won't do what you need. From what you've described so far, that's
not the case.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top