2

Apologies for the poorly phrased title. I tried to do better, but perhaps someone can suggest a better title.

As a test case for another project, I'm working with the Mandelbrot set, using only value that can be properly represented, ie. n/2^k. (at least that's how I understand it) I'm trying to figure out how many iteration, will potentially hurt precision, but while I understand the gist of it, I never really did grasp how floating point values are represented in memory, not completely anyway, and the conclusion I've reached doesn't seem right.

For example, I've concluded that if any remotely reasonable resolution is to be achieved, for example 1025 by 1025, requiring steps of 1/2^8 through the range -2 to +2 on the x and y axis, the maximum number of iteration for each point, guaranteeing 100% precision, would be 16, using 128 bit floating point precision, and that's not even accounting for the sign bit or the fact that the values exceed 1.

So, what is it that I don't understand? Or in other words, how much precision is needed to represent n/2^k, given a boundary of -2 to +2? (I should probably use that as the title)

NB: If it matters at all, which it shouldn't, I'm working in C.

Zacariaz
  • 537
  • 2
  • 7
  • 13
  • It is possible to generate deeper iterations that generate "smaller" numbers, and add them together keeping precision, before adding them to the shallower iterations with "bigger" numbers. While the absolute precision of those deeper numbers is lost, they can still have a slight effect cumulatively. Consider also that as you zoom in, the shallower iterations for the area you are looking at will be similar values in the upper digits, so you may need to "basically ignore" the upper digits if you want to maintain enough resolution to zoom in indefinitely. – Gem Taylor Nov 01 '19 at 11:21
  • 1
    It's hard to see what the actual question is. The *step* in coordinate values requires 1 bit precision, so at the first (positive) tick you need 1 bit, second tick 1 bit, 3rd tick 2 bits, 4th tick 1 bit, 5th tick 3 bits, 6th tick 2 bits – the number of significant bits in the normalised tick ordinal. The number of bits produced in multiplying is the sum of the number of bits of the operands. So roughly you are doubling the bit requirement in every iteration. – Weather Vane Nov 01 '19 at 11:51
  • 2
    For an integer n and a number n/2^k between −2 and +2, then n/2^k can be represented exactly in the IEEE-754 binary64 format if and only if |n| < 2^53 or can be made such an integer by adjusting k. But your question is not clear about **which** numbers you need to represent exactly (Coordinates in the square with corners at (−2, −2) and (+2, +2)? All numbers involved in calculation?) or whether you just need to represent some numbers (Which?) accurately (not necessarily exactly). – Eric Postpischil Nov 01 '19 at 12:37
  • To answer the question in the title literally, the precision (number of bits in the significand) needed to represent n/2^k is the number of bits in n (a.k.a. ceil(log[2](n))), after k is adjusted so that n is an odd integer. For example, if n is 5, you need three bits of precision (including the leading bit, which is usually encoded implicitly). For 65537, you need 17 bits. If n/2^k is 20/2^8, change it to 5/2^6, and then we see you need three bits. – Eric Postpischil Nov 01 '19 at 12:39
  • @EricPostpischil I think perhaps I've got it now. So, basically, the precision needed is roughly equivalent to the bits needed to represent the numerator plus the bits needed to represent the exponent of the denominator? Also I do regret not being able to explain it better, but I literally don't know how. – Zacariaz Nov 01 '19 at 15:44
  • @Zacariaz: Precision is usually the number of digits in the significand, which is effectively the numerator. The total width it takes to store a floating-point number depends on the format. With a binary base, it commonly has a primary encoding of the significand that has one less bit than the significand (because the leading bit is derived from the exponent encoding), one bit for the sign, and some number of bits for the exponent. The total number of bits may be called the width of the format but not the precision. – Eric Postpischil Nov 01 '19 at 21:19

0 Answers0