Logo by AGUS - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Visit the official fractalforums.com Youtube Channel
 
*
Welcome, Guest. Please login or register. April 26, 2024, 05:55:39 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: About precision of doubles  (Read 565 times)
Description: Can't understand why zoom levels at low precision get "blocky"?
0 Members and 1 Guest are viewing this topic.
louwin
Forums Newbie
*
Posts: 5


« on: November 21, 2016, 12:13:14 AM »

I'm a retired programmer (assemblers, COBOL and BASIC mainly). A total newbie in C++.

Rather than use one of the few excellent programs available I'd like to write my own  roll eyes

"double" variables SHOULD go to E308 so could someone please explain to me why I can only "zoom" to about 1.0E13 before it gets all "blocky"?

I even tried "long double" and that only went to about 2.0E18    cry

My research seems to suggest this is normal but I'd like to know why?

This is the code I'm using....

Code:
int MAXI, maxIterations;
long double zoom, moveX, moveY;
long double newRe, newIm, oldRe, oldIm;
long double pixelX, pixelY;

for (zoom = 1.0E16L; zoom <= 1.0E18L; zoom *= 1.5) {
for (int y = heightM; y >= 0; y--) {
pixelY = (y - halfheight) / (zoom * halfheight) + moveY;
for (int x = 0; x < width; x++) {
pixelX = /*whscale*/1.5 * (x - halfwidth) / (zoom * halfwidth) + moveX;
newReal = newImaginary = oldReal = oldImaginary = 0;
for (i = 0; i < maxIterations; i++) {
oldReal = newReal; oldImaginary = newImaginary;
newReal = oldReal * oldReal - oldImaginary * oldImaginary + pixelX;
newImaginary = 2 * oldReal * oldImaginary + pixelY;
if ((newReal * newReal + newImaginary * newImaginary) > 4) break;
}
if (i < maxIterations) {
colour = Colours[i % 251];
} else {
colour = BLACK;
}
SetPixel(hdc, x, y, colour);
}
        }       
}

For simplicity I editted out extraneous details like writing bitmaps etc  wink
Logged
quaz0r
Fractal Molossus
**
Posts: 652



« Reply #1 on: November 21, 2016, 12:26:14 AM »

because unfortunately the mandelbrot equation is limited by the mantissa precision, not the exponent.  sad  on the other hand, the perturbation mandelbrot equation, should you choose to go down that rabbit hole, is mostly limited by the exponent, which is most fortunate indeed.   cheesy
Logged
louwin
Forums Newbie
*
Posts: 5


« Reply #2 on: November 21, 2016, 02:43:32 AM »

Thanks for your response   undecided

But bear with me (NEWBIE!) but

Doesn't the mantissa just hold some digits and the exponent the multiplier or divider? If the mantissa "fills up" don't you just add or subtract 1 from the exponent and carry on? crazy eyes confused

Please explain (in newbie terms) or please provide me a link to the explanation   tongue stuck out cry sad
Logged
quaz0r
Fractal Molossus
**
Posts: 652



« Reply #3 on: November 21, 2016, 02:58:31 AM »

well the problem is that C requires more and more mantissa as you go deeper.  basically when you are at 10N C needs around N digits of mantissa.  if you were just doing Z2 maybe it would only be limited by the exponent, but since you add C each iteration you are limited by C needing to have all its digits.
Logged
ciric50
Forums Freshman
**
Posts: 19


« Reply #4 on: November 21, 2016, 02:22:33 PM »

Maybe this will help.

When you're zoomed out, let's say you're looking at values on the x axis something like -2 to +2, so the the range is 2 - (-2) = 4. As you zoom in at some point, the edge values on the x axis get closer and closer together, say 1.00002 to 1.00003, for a range of 1.00003 - 1.00002 = 0.00001. The difference in values is very small. When you zoom in to range values that are very close together, the difference can't be done accurately without high precision. For example 1.00000000000000002 to 1.00000000000000003 in double precision won't work, because the difference between them is less than the smallest number that double precision can represent.

Intuitively it seems like double precision should be more than enough for most calculations (and it is) but in the world of fractals you bump into the precision limitation fairly quickly as you zoom in.

There is a pdf around somewhere with the title "Superfractalthing Maths" where the author explains a technique he found where double precision can be used for these kinds of calculations.
Logged
louwin
Forums Newbie
*
Posts: 5


« Reply #5 on: November 21, 2016, 11:31:28 PM »

Thanks for that VERY informative response ciric50  cheesy

I suppose that also explains why going to "long double" only increased the zoom range by about 100,000....     shocked   I was expecting, like, another 30 zeroes? But, as quaz0r suggested, going from 64 bits to 80 bits the mantissa only increases by a few bits   sad

Now to research VS215 and the Intel Compiler for Quad precision.  Putting off the move to pertubation and arbitary precision    undecided    huh?
« Last Edit: November 22, 2016, 12:15:47 AM by louwin » Logged
quaz0r
Fractal Molossus
**
Posts: 652



« Reply #6 on: November 22, 2016, 02:15:36 AM »

i dont know if using the builtin float128 or float256 types is even worth it compared to just using mpfr.  gmp/mpfr is written to be as efficient as possible, including the utilization of explicit vectorization, which could very well make it the best choice compared to some cheap softfloat implementation.

there is a handy c++ wrapper for mpfr called mpreal:  https://bitbucket.org/advanpix/mpreal/downloads?tab=tags

there is also an old thing called the qd library which gives some sort of supposedly efficient implementation of double-double and quad-double.  internally it is implemented as multiple doubles.
Logged
louwin
Forums Newbie
*
Posts: 5


« Reply #7 on: November 23, 2016, 01:32:21 PM »

Thanks for the mpreal.h suggestion quaz0r. It DOES look interesting.... Have you actually tried it with VS2015 or the like?

I get errors with the embedded #include mpfr.h within mpreal.... commenting it out goes a bit further

//#include <mpfr.h>

But then I get lots of

C:UsersLouisDocumentsVisual Studio 2015ProjectsProjTechProjTech../mpreal.h(365): error : identifier "mp_rnd_t" is undefined
1>        friend const mpreal tan(const mpreal& v, mp_rnd_t rnd_mode);
1>                                                                                    ^

errors?

Nobody else seems to have complained so it could just be me (newbie!?)....

Thanks again....
Logged
Adam Majewski
Fractal Lover
**
Posts: 221


WWW
« Reply #8 on: November 23, 2016, 06:13:30 PM »

You can also try mpc :
https://pl.wikibooks.org/wiki/Programowanie_w_systemie_UNIX/MPC

if you want to try linux you can here find info about installations

https://pl.wikibooks.org/wiki/Programowanie_w_systemie_UNIX/MPFR
https://pl.wikibooks.org/wiki/Programowanie_w_systemie_UNIX/GMP

and here are about perturbation
https://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/Mandelbrot_set#Perturbation_theory

HTH
Adam
« Last Edit: November 23, 2016, 07:52:16 PM by Adam Majewski, Reason: perturbation » Logged
quaz0r
Fractal Molossus
**
Posts: 652



« Reply #9 on: November 23, 2016, 07:25:57 PM »

hmm well mpreal.h is a c++ wrapper for mpfr.h so you need mpfr to be available and working smiley  i know people use mpreal with microsoft compiler but im not sure what the particulars are.
Logged
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
How much more useable precision will I get using quad precision? Programming Duncan C 1 2664 Last post April 15, 2010, 12:16:56 PM
by Botond Kósa
Precision work 3d Art / Composition Axolotl 0 1351 Last post April 29, 2011, 08:35:16 PM
by Axolotl
Extended Precision Fragmentarium M Benesi 5 2016 Last post November 15, 2012, 09:33:43 PM
by M Benesi
Unexpected need for Multi-precision General Discussion element90 0 1237 Last post June 07, 2013, 09:57:50 AM
by element90
End Of Double Precision Gestaltlupe Gallery trafassel 1 1665 Last post November 12, 2013, 04:50:56 PM
by eiffie

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.223 seconds with 24 queries. (Pretty URLs adds 0.014s, 2q)