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

Mandelbrot trouble

P: 93
Hi,
I wrote this little piece of code for a very simple Mandelbrot explorer some time ago. The main problem I came across was that after zooming in to a certain depth, the double data type I used couldn't go further. Is there a way to solve this problem? Thank you.
Jun 10 '07 #1
Share this Question
Share on Google+
15 Replies


AdrianH
Expert 100+
P: 1,251
Hi,
I wrote this little piece of code for a very simple Mandelbrot explorer some time ago. The main problem I came across was that after zooming in to a certain depth, the double data type I used couldn't go further. Is there a way to solve this problem? Thank you.
You can do one of two things. Use a long double, or find the repeating pattern and back off to that position when you get there.

The long double is definitely easier.


Adrian
Jun 10 '07 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
You can do one of two things. Use a long double, or find the repeating pattern and back off to that position when you get there.
Be sure to do a sizeof(long double). On Windows, double and long double are the same.
Jun 10 '07 #3

P: 93
Be sure to do a sizeof(long double). On Windows, double and long double are the same.
Yep. You are right. Actually I used long double in my code, but later I found out that both double and long double are only 8 bytes long. I said double because it doesn't matter. However, is there a way around this problem in another way?
Jun 10 '07 #4

P: 93
Just as an afterthought, I thought the patterns never actually repeat - so what do you mean by "Find the repeating pattern"?
Jun 10 '07 #5

AdrianH
Expert 100+
P: 1,251
Just as an afterthought, I thought the patterns never actually repeat - so what do you mean by "Find the repeating pattern"?
A mandelbrot is a fractal. Fractals always repeat.

As for double and long double being the same, that is just a MSism. Try a real compiler. ;)


Adrian
Jun 10 '07 #6

Banfa
Expert Mod 5K+
P: 8,916
I would have though you could achieve something by scaling.

That is initially when you start your calculations you (and everyone else) tends to assume a unit scale, that is that 1 == 1.

However once you have zoomed into a certain level a double can no longer hold the difference between your scale minimum and maximum. But if a some point prior to that you instead start assuming something like 1 == 10e-100 and scale all your calculations similarly then you can actually hold much much lower values.

Another alternative if you are using C++ is rather than using a plain old double write yourself a class to hold you numbers, you can then choose the number of bits required in the significand and the exponent to suit you application.


Oh have fractals do not "repeat" they are "self similar" that is when you look at the they appear similar, however use enough decimal places they will be different. A chaotic fractal by it's nature never actually repeats, it just comes close. Not that I am saying the suggested method won't work (because i have really taken the time to understand what has been suggested) I am merely being picky about the terminology.
Jun 10 '07 #7

P: 93
Are you suggesting that I write my own data type, which is maybe 32, 64 bytes long?
Jun 11 '07 #8

Banfa
Expert Mod 5K+
P: 8,916
Are you suggesting that I write my own data type, which is maybe 32, 64 bytes long?
Yes or (assuming you meant bits not bytes) even 128 bits.
Jun 11 '07 #9

Banfa
Expert Mod 5K+
P: 8,916
BTW in the clear light of morning (as opposed to the middle of the night like my last post) I have realised that scaling wont work, the problem you are running into is running out of precision and scaling the value will not alter this so writing your own data type is the only option.

While you could do this in C or C++ a C++ class is ideally suited to do the job, in C you would end up with a structure and a bunch of functions (which is essentially what a stand alone i.e. 1 that isn't part of a class hierarchy, class is) but the C++ solution using operator overloading is more elegant.
Jun 11 '07 #10

AdrianH
Expert 100+
P: 1,251
BTW in the clear light of morning (as opposed to the middle of the night like my last post) I have realised that scaling wont work, the problem you are running into is running out of precision and scaling the value will not alter this so writing your own data type is the only option.

While you could do this in C or C++ a C++ class is ideally suited to do the job, in C you would end up with a structure and a bunch of functions (which is essentially what a stand alone i.e. 1 that isn't part of a class hierarchy, class is) but the C++ solution using operator overloading is more elegant.
I liked the scaling idea. You are right. Floating point numbers are scaled, that is why the point is floating. ;) But thinking about this out loud. If precision is being lost that would mean that either 1) the numbers are spanning too many bits requiring more significant figures (I don't think this is as likely) or 2) the exponent has reached its limit (I think this is more likely). If the latter is the case, scaling still may be what you need.

If I am right, then you can make a class that contains a double and a long for an extended exponential value, giving you an exponential range of +-2 billion, much greater than what a double has. For ease, I would lookup the IEEE definition of a double and use that for you base. I would, for simplicity, keep the the exponent on the double to 0 as much as possible (remember that e is not a signed value but a biased value, so 0 is actually pow(2,11-1)-1 for a double equalling 1023, wikipedia has a fairly good article on this) and move your long exponent around instead. Doing it this way should reduce the amount of coding you would have to do. Be careful and check that the value is normilised or not or your exponent can be off by 1 changing the value of your number by a factor of 2 or 1/2. Alternatively, you can just rewrite the entire floating point yourself.

As for the bot being self-similar, I thought with the right transform, they were identical, but precision was the only reason why that they are not. Granted, it would require more than a scale, it would probably need a scale and rotate at the minimum. Perhaps a skew or stretch as well. But of course, this isn't a course of study for me, so I could just be spewing out crap. ;)


Adrian
Jun 11 '07 #11

Banfa
Expert Mod 5K+
P: 8,916
I liked the scaling idea. You are right. Floating point numbers are scaled, that is why the point is floating. ;) But thinking about this out loud. If precision is being lost that would mean that either 1) the numbers are spanning too many bits requiring more significant figures (I don't think this is as likely) or 2) the exponent has reached its limit (I think this is more likely). If the latter is the case, scaling still may be what you need.
Sorry Adrian but

The Mandlebrot fractal is contained in the area defined by the 2 points

-2 - i
1 + i

Where i is the sqrt(-1).

So when you are specifying the limits of the current bit of the fractal that you wish to examine then you are not pushing the exponent but the presision because it is likely to be a range in the order of

-1 + 0.25i
-.9999999999999999999 + 0.2500000000000000001i

It's the precision that is the problem not the exponent which is very happily in range which is why scaling wont work.

A problem with the exponent is really on likely if you happen to be examining along 1 or more of the axis i.e. where real is very close to 0 or imaginary is very close to 0.
Jun 11 '07 #12

AdrianH
Expert 100+
P: 1,251
Sorry Adrian but

The Mandlebrot fractal is contained in the area defined by the 2 points

-2 - i
1 + i

Where i is the sqrt(-1).

So when you are specifying the limits of the current bit of the fractal that you wish to examine then you are not pushing the exponent but the presision because it is likely to be a range in the order of

-1 + 0.25i
-.9999999999999999999 + 0.2500000000000000001i

It's the precision that is the problem not the exponent which is very happily in range which is why scaling wont work.

A problem with the exponent is really on likely if you happen to be examining along 1 or more of the axis i.e. where real is very close to 0 or imaginary is very close to 0.
So you are saying that all of the bits are going to be in use for the calculation when zooming in? What i'm saying is, are all of those significant figures? I've not dealt with fractals in a long while, so forgive my ignorance. ;)

If so, then an entirely new class would have to be made. Fun stuff. :D


Adrian
Jun 11 '07 #13

Expert 10K+
P: 11,448
Google for "mandelbrot integer". It can be done and has been done before.

kind regards,

Jos
Jun 11 '07 #14

Banfa
Expert Mod 5K+
P: 8,916
Google for "mandelbrot integer". It can be done and has been done before.
But that's so boring when you can re-invent the wheel.
Jun 11 '07 #15

AdrianH
Expert 100+
P: 1,251
But that's so boring when you can re-invent the wheel.
;) :D


Adrian
Jun 12 '07 #16

Post your reply

Sign in to post your reply or Sign up for a free account.