Sign in to follow this  
rakoon2

sqrt returns -1.IND / -1.INF -- mandelbrot fractal

Recommended Posts

Hello guys! I try to make a mandelbrot picture. I am new to this stuff.. ( i am only 16! ) and havn't learnd it in school yet.. maybe my code is wrong. Thank you. sqrt((c1*c1) + (c2*c2)) returns -1.INF / -1.IND how? what do I wrong? :/ :) Here is my code:
    double c1 = 0, c2 = 0, c1_temp = 0;
    int t = 0; 
    bool draw = false;
    
    for( double x=-2; x<=1; x+=0.01)
    {
        for( double y=-1; y<= 1;y+=0.01 )
        {
           for( t = 0; t <= 400; t++)
           {   
               c1_temp = c1;
               c1 = ((c1*c1) - (c2*c2)) + x;               
               c2 =  (2*c1_temp*c2) + y;
               draw = pixel_vector.testSqrt(c1, c2);
               if(draw == false)
               {
                    break;
               }             
           }
           if( draw == true )
           {
               // add pixel to the screen buffer
               pixel_vector.addPixel
               ( 
                           static_cast<int>( 100 * x )+200,
                           static_cast<int>( 100 * y )+100
                           , g_Blue, screen
               );
           }         
        }
 
    }




bool CPixelVector::testSqrt( double c1, double c2 )
{
   if( sqrt((c1*c1) + (c2*c2)) > 2 )
     return false;
   else
     return true;  
}




sqrt((c1*c1) + (c2*c2)) returns:
2.23607
3.17177
11.252
126.206
15929.4
2.53745e+008
6.43866e+016
4.14564e+033
1.71863e+067
2.95369e+134
1.#INF
1.#INF
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
//...




Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this