Try these. fc() is just an Inline C version of f().

I'm pretty sure that they are now correct, but you should verify them yourself.

#! perl -slw use strict; use Inline C => << '__C__', NAME => "_627288"; # => CLEAN_AFTER_BUILD +=> 0; #include <stdio.h> int fc( double x, double y, int d ) { double bsize = pow( 4, ( d-1 ) ); if( x == y ) return d; else if( (int)( x / 4 ) == (int)( y / 4 ) ) return d-1; else if( (int)( x / bsize ) == (int)( y / bsize ) ) return 1 + fc( fmod( x, bsize ), fmod( y, bsize ), d-1 ); else return fc( fmod( x, bsize ), fmod( y, bsize ), d-1 ); } __C__ sub f{ my( $x, $y, $d ) = @_; my $bsize = 4**($d-1); if( $x == $y ) { return $d } elsif( int( $x / 4 ) == int( $y / 4 ) ) { return $d-1; } elsif( int( $x / $bsize ) == int( $y / $bsize ) ) { return 1 + f( $x % $bsize, $y % $bsize, $d-1 ); } else{ return f( $x % $bsize, $y % $bsize, $d-1 ); } }

Using this I have produced plots of 1000x1000 chunks upto level 31 successfully. At that point the coordinates get so large that they blow the limits of doubles. I'm also fairly sure that you are loosing precision long before level 31. At level 16 everything appears to check out.

I don't think any single set of 20 lines of code has ever (in the best part of 30 years), given me as much trouble to wrap my brain around as this!


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^3: Fractal structure: PDL, memory, time by BrowserUk
in thread Fractal structure: PDL, memory, time by FFRANK

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.