views:

2307

answers:

8

Is there a native c++ variable type that's "bigger" than a double?
float is 7
double is 15 (of course depending on the compiler)
Is there anything bigger that's native, or even non-native?

+14  A: 

C++ has long double, but there is no guarantee that it's any more precise than a plain double. On an x86 platform, usually double is 64 bits, and long double is either 64 or 80 bits (which gives you 19 significant figures, if I remember right).

Your mileage may vary, especially if you're not on x86.

Chris Jester-Young
+1  A: 

long double, but it generally is still 15 places of precision too.

Cipher
+6  A: 

a treble!

(no, not really)

Gareth
typedef double treble;// :)
Cipher
Bit harsh to downmod obvious humour? Oh well, I suppose it's the risk I take
Gareth
probably just someone trying to get their Critic badge...
Mark Heath
And I am addicted to upvoting negative answers. Especially ones this good!
Ali A
+1  A: 

There are also some various bigfloat/bigint libraries around for C++ that allow arbitrary precision math. There's this library on Microsoft Codeplex, but Googling will find you plenty of others.

Dana the Sane
+3  A: 

You can use GNU MP. Its floating-point functions have unlimited mantissa and 32-bit or 64-bit (depending on the native word size) exponent. It also comes with a C++ wrapper.

CesarB
A: 

C++ has long double, but it's still quite limited. For good time try GNU's gmp library. You can set up numbers as big as you like, and it's quite fun and hackishly when you use gmp_add instead of a normal +. I'm sure there's a C++ wrapper somewhere.

gilm
A: 

A long double typically only uses 10 bytes, but due to alignment may actually take up 12 or 16 (depending on the compiler and options) bytes in a structure.

The 10 byte long double provides a 64-bit mantissa; this is very convenient for when you want to store 64 bit integers in floating point without loss of precision.

ysth
why was this downvoted? Is it wrong?
Yar
A: 

long long double only some cpus will allow you to use it though...

Arron Brooks