Archive: C++ decimal accuracy


22nd November 2002 17:27 UTC

C++ decimal accuracy
How do you increase the decimal accuracy in C++? Do you use multiple double-class variables, or is there some way to increase the decimal accuracy for one variable? If you use multiple variables, how do you set it up so that digits below the 16th decimal get stored in a different variable?
Thanx,
--Atero


22nd November 2002 19:58 UTC

there are various object libraries that have been developed for ultra high precision math. i think there's one freely available from whoever made maple, but search online and you should find one.

if you want to do it yourself, the easiest way to do is to use fixed point math using two unsigned long doubles. (which i think are 8 bytes each).

so then you have l[1]*2^32+l[2]/2^64 would be a number between 0 and 1 accurate to 64 binary decimal places. (if you just used one you'd have 32 places which would do for many things.)

addition and multiplication are then doable, but a bit tricky.

if you really need this kind of accuracy i'd use a class off the net.

what is it you're trying to do?

tom


22nd November 2002 20:55 UTC

calculate pi^(e-sqrt(163)) to fourty jillion decimal places. (or something like that)

tx cfp


23rd November 2002 11:18 UTC

If you want to do that then you could use an array of integer variables and program your own functions for +, -, *, / that populate the array with the digits of the number. It can be done... I did it once to make a pi calculator, although there are better ways to do it, I would say that that would be the easiest.


23rd November 2002 12:59 UTC

if you tell me what you're actually trying to work out i can get maple to do it in seconds as it can do arbitrary precision math and i'll mail/post the answer to you.

here's the answer of what you posted to 400 d.p. to be going on with(^_^)

.100973820111465682874410650721173094203632103468498587185663014682041690912684336047668938329941986903489002861506439185524027123804036676032889280722640215481774991280951432239050165638351552395269104701703089443526429033323788236280041419952679229 5649473344330023293270432420067572074993898433784703104109226270012026766984654248172751633170233449878865427911004996636075705188492540318921641699495e-4

ahh the wonders of modern technology.

tom


23rd November 2002 13:12 UTC

here's the reference i thought was on the maple site but wasn't...

http://www.mathtools.net/C++/Extra_p...ion/index.html

tom


23rd November 2002 13:53 UTC

You could always use Mathematica to calculate pi too. I think I posted a 10,000 (or something like that) digit pi before.


23rd November 2002 22:11 UTC

I wasn't trying to calculate pi, I was mainly thinking of how I could make an uberfast fractal generation program (for my own evil purposes)

Thanx for the links


25th November 2002 00:21 UTC

Another thing to try... download lcc-win (a shitty c++ compiler). If I remember correctly it comes with a doubledouble example code which is where I first 'learned' how to make larger variables. Do a search in your favourite P2P software and you'll likely find it (100 times no doubt).


28th November 2002 18:03 UTC

If you want fast fractal generation, why are you considering higher precision values? Anything larger than 32 bits won't fit into a CPU register and incurs more round-trips to the cache, making working with larger numbers (especially large floating point numbers) really really slow.


28th November 2002 18:32 UTC

delta: the x86 CPU has 64-bit floating point registers... and using SSE you have 128-bit registers at your disposal.


29th November 2002 06:31 UTC

Also, if I didn't I couldn't get past about 10x magnification. One of my gripes about GF4 is how if you get about 500x magnification it loses precision completely....


29th November 2002 15:32 UTC

Originally posted by UnConeD
delta: the x86 CPU has 64-bit floating point registers... and using SSE you have 128-bit registers at your disposal.
Yes, but if you're using an array of integers as your own representation of numbers, ten bucks says your compiler won't figure out how to use MMX/SSE to your advantage. If you go with the array, it will be using general-purpose registers, which are 32 bits.

29th November 2002 15:33 UTC

Originally posted by Atero
Also, if I didn't I couldn't get past about 10x magnification. One of my gripes about GF4 is how if you get about 500x magnification it loses precision completely....
What kind of fractals are you generating? More often than not, fractal generation algorithms have a window size that one can set to achieve arbitrary magnification.

29th November 2002 20:55 UTC

delta, you're a dumbass.

virtually all decent fractal generation programs have the ability to magnify the picture - there'd be almost no point to the program if it didn't.

also, instead of making two posts in the same thread right next to each other, use the 'edit' button. and there's really no point to quoting an entire post in your reply, unless there've been a bunch of posts between the one you're reffering to and your reply.