🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.os.linux.programowanie
Article #72451

Re: DBL_EPSILON i Calculated Machine epsilon

#72451
From: Adam Majewski
Date: Sun, 13 May 2012 11:23
158 lines
5835 bytes
On Sunday, April 15, 2012 3:13:51 PM UTC+2, Adam Majewski wrote:
> Witam.
> 
> Napisałem program w c ( kod poniżej). Oblicza ile potrzeba kroków ( 
> iteracji tu LastIteration) aby punkt z1 uciekł z koła o promieniu ER, 
> czyli sprawdza abs(z1)<ER
> 
> 
> 
> 
> Program działa, ale dla n=27 wpada w nieskończoną pętlę.
> Przypuszczam, że wtedy program nie rozróżnia z1 i zp :
> bo wtedy distance(z1,zp)<Calculated  Machine epsilon
> 
> 
> 
> gdzie :
> distance(z1,zp) = 1.490116e-08
> Calculated  Machine epsilon = 1.19209E-07 ( używając programu z wikipedii )
> http://en.wikipedia.org/wiki/Machine_epsilon
> punkt jest liczbą zespoloną)
> punkt zp jest punktem stałym = nie ucieka z koła o promieniu ER
> 
> 
> Jak to się ma do :
> 
> DBL_EPSILON           = 2.220446e-16  = 
> 0.00000000000000022204460492503130808473 ( z float.h )
> ?
> 
> 
> 
> Pozdrawiam
> 
> Adam
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ============== Uruchomienie==========================
> 
> gcc -lm -Wall i.c
> ./a.out
> 
> 
> =============wyniki ====================
> 
> 
> n=  1 distance(z1,zp) = 5.000000e-01  LastIteration =        3
> n=  2 distance(z1,zp) = 2.500000e-01  LastIteration =        5
> n=  3 distance(z1,zp) = 1.250000e-01  LastIteration =       10
> n=  4 distance(z1,zp) = 6.250000e-02  LastIteration =       19
> n=  5 distance(z1,zp) = 3.125000e-02  LastIteration =       35
> n=  6 distance(z1,zp) = 1.562500e-02  LastIteration =       68
> n=  7 distance(z1,zp) = 7.812500e-03  LastIteration =      133
> n=  8 distance(z1,zp) = 3.906250e-03  LastIteration =      261
> n=  9 distance(z1,zp) = 1.953125e-03  LastIteration =      518
> n= 10 distance(z1,zp) = 9.765625e-04  LastIteration =     1031
> n= 11 distance(z1,zp) = 4.882812e-04  LastIteration =     2055
> n= 12 distance(z1,zp) = 2.441406e-04  LastIteration =     4104
> n= 13 distance(z1,zp) = 1.220703e-04  LastIteration =     8201
> n= 14 distance(z1,zp) = 6.103516e-05  LastIteration =    16394
> n= 15 distance(z1,zp) = 3.051758e-05  LastIteration =    32778
> n= 16 distance(z1,zp) = 1.525879e-05  LastIteration =    65547
> n= 17 distance(z1,zp) = 7.629395e-06  LastIteration =   131084
> n= 18 distance(z1,zp) = 3.814697e-06  LastIteration =   262156
> n= 19 distance(z1,zp) = 1.907349e-06  LastIteration =   524301
> n= 20 distance(z1,zp) = 9.536743e-07  LastIteration =  1048590
> n= 21 distance(z1,zp) = 4.768372e-07  LastIteration =  2097167
> n= 22 distance(z1,zp) = 2.384186e-07  LastIteration =  4194322
> n= 23 distance(z1,zp) = 1.192093e-07  LastIteration =  8388675
> n= 24 distance(z1,zp) = 5.960464e-08  LastIteration = 16778821
> n= 25 distance(z1,zp) = 2.980232e-08  LastIteration = 33604781
> n= 26 distance(z1,zp) = 1.490116e-08  LastIteration = 68563774
> 
> 
> =================== kod ==================
> 
> 
> #include <stdio.h>
> #include <math.h> // pow
> #include <float.h> // DBL_EPSILON
> 
> 
> 
> double GiveLastIteration(double Zx, double Zy, double Cx, double Cy, int 
> IterationMax, int ER2)
>   {
>    double Zx2, Zy2; /* Zx2=Zx*Zx;  Zy2=Zy*Zy  */
>    double i=0.0;
>    Zx2=Zx*Zx;
>    Zy2=Zy*Zy;
>    while  (Zx2+Zy2<ER2)  /* ER2=ER*ER */
>    {
>     Zy=2*Zx*Zy + Cy;
>     Zx=Zx2-Zy2 + Cx;
>     Zx2=Zx*Zx;
>     Zy2=Zy*Zy;
>     i+=1.0;
>     //printf("i = %f Zx = %e = %40.38f \n", i,Zx, Zx);
>    }
>    return i;
>   }
> 
> 
> int main()
> 
> {
>    double distance;
> 
>     int n;
>     // parabolic fixed point zp = zpx = zpy*I = 0.5
>     double zpx = 0.5;
>     double zpy = 0.0;
> // z1 = z1x + z1y*I = point of exterior of Julia set but near parabolic 
> // fixed point zp
>     double z1x;
>     double z1y = zpy;
>     double cx= 0.25;
>     double cy= 0.0;
>     // Escape Radius ; it defines target set  = { z: abs(z)>ER}
>     // all points z in the target set are escaping to infinity
>     double ER=2.0;
>     double ER2;
> 
>     double LastIteration;
> 
> 
>     //n = 1000;
>     ER2= ER*ER;
> 
> 
> 
>     for (n =1; n<101; n++)
>     {
>       distance = pow(2.0,-n);
>       printf("n= %d distance(z1,zp) = %e  = %40.38f ",n, distance, 
> distance);
>       z1x = zpx + distance;
>       LastIteration = GiveLastIteration(z1x,z1y, cx,cy, n+n,ER2 );
>       printf("LastIteration = %.0f \n", LastIteration);
>     }
> 
>   printf("DBL_EPSILON   = %e  = %40.38f ",DBL_EPSILON , DBL_EPSILON );
> 
> 
>    return 0;
> }

POzostaje czekać na GMP dla GPU (:-)
Technical Details
Message-ID: <28094281.1868.1336908221936.JavaMail.geo-discussion-forums@vbjb10>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin1!goblin.stu.neva.ru!ottix-news.ottix.net!nrc-news.nrc.ca!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
References: <jmehj3$mkj$1@news.icm.edu.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin1!goblin.stu.neva.ru!ottix-news.ottix.net!nrc-news.nrc.ca!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From: Adam Majewski <adammaj1@o2.pl>
Newsgroups: pl.comp.os.linux.programowanie
Subject: Re: DBL_EPSILON  i  Calculated  Machine epsilon
Date: Sun, 13 May 2012 04:23:41 -0700 (PDT)
Organization: http://groups.google.com
Lines: 168
Message-ID: <28094281.1868.1336908221936.JavaMail.geo-discussion-forums@vbjb10>
References: <jmehj3$mkj$1@news.icm.edu.pl>
NNTP-Posting-Host: 78.9.28.157
Mime-Version: 1.0
X-Trace: posting.google.com 1336908222 25235 127.0.0.1 (13 May 2012 11:23:42 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 13 May 2012 11:23:42 +0000 (UTC)
In-Reply-To: <jmehj3$mkj$1@news.icm.edu.pl>
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=78.9.28.157; posting-account=8toHEAoAAADQ-dL6A4ljPhheb_AbUIu4
User-Agent: G2/1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit