Jump to content
  • Advertisement
Sign in to follow this  
rakoon2

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

This topic is 5228 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!