Shop OBEX P1 Docs P2 Docs Learn Events
For a change — Parallax Forums

For a change

ReinhardReinhard Posts: 489
edited 2012-02-06 10:54 in Propeller 1
What outputs this programm ?
#include <cstdlib>
#include <complex>
#include <stdio.h>
using namespace std;
int main(int argc, char *argv[])
{
    double epsilon = 0.0000002;
    complex<double>Z (0,0);
    complex<double>C (-0.75,epsilon);
    int iter;
       
    for (iter = 1 ; iter < 400000000; iter++)
    {
        Z = Z * Z + C; 
        
        if(abs(Z) > 2)
        {
           printf("%f\n",(double)(epsilon * (double)iter));
           break;    
        } 
    }
    return EXIT_SUCCESS;
}
// propeller-elf-g++ -mxmmc -o i.elf p.cpp

Don't think to hard about it, if you run it you get a surprise.
But don't ask me for an explanation ;-)


Reinhard

Comments

  • Heater.Heater. Posts: 21,230
    edited 2012-02-06 09:31
    Can't run it on my phone but that z = z * z + c is the iteration step from the Mandlebrot set calculation.
  • sevssevs Posts: 50
    edited 2012-02-06 09:40
    Mandelbrot is my guess as well without being able to run it. :)
  • Heater.Heater. Posts: 21,230
    edited 2012-02-06 10:04
    It is performing the mandlebrot iterations for only one point in the complex plane (-0.75, epsilon) and the loop bails out when it decides that point is not a member of the Mandlebrot set.
    What the significance of the printed value is I have no idea.
  • denominatordenominator Posts: 242
    edited 2012-02-06 10:06
    sevs wrote: »
    Mandelbrot is my guess as well without being able to run it. :)

    Bingo! https://home.comcast.net/~davejanelle/mandel.html
  • Heater.Heater. Posts: 21,230
    edited 2012-02-06 10:30
    Fantastic. I was about to guess pi or multiple or fraction of it. Not through any great insight just because it's the kind of answer you start to expect to this kind of question.
  • ReinhardReinhard Posts: 489
    edited 2012-02-06 10:35
    Yep,
    this is the slowest method to generate PI, that I know.
    But is a mystery in math since 1991.

    I do not know a waterproofed explanation.

    Reinhard
  • sevssevs Posts: 50
    edited 2012-02-06 10:54
    That is very very cool!

    A lucky guess on my part, but still very interesting.
Sign In or Register to comment.