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

value

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

Sep 14 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
gr********@gmail.com writes:
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
Sep 14 '06 #2

P: n/a
Jens Theisen wrote:
gr********@gmail.com writes:
>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.
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.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Sep 15 '06 #3

P: n/a
Jens Theisen wrote:
gr********@gmail.com writes:
>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?
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: "
<< std::numeric_limits<long double>::max() << '\n';
}
>
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
Sep 15 '06 #4

P: n/a

Jens Theisen 写道:
gr********@gmail.com writes:
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
You can store the base number and the index number sparately.

Sep 15 '06 #5

P: n/a
gr********@gmail.com wrote:
>
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.
Sep 15 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.