Jump to content
  • Advertisement
Sign in to follow this  
CMRM

Bug on complex division

This topic is 2261 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

I just found a small bug in the complex division operation that is available in the scriptmath addon. In scriptmathcomplex.cpp the division is defined like this:

Complex Complex::operator/(const Complex &other) const
{
float len = other.length();
if( len == 0 ) return Complex(0,0);
Complex res((r*other.r + i*other.i)/len, (i*other.r - r*other.i)/len);
return res;
}


when it should be

Complex Complex::operator/(const Complex &other) const
{
float squaredLen = other.squaredlength();
if( squaredLen == 0 ) return Complex(0,0);
Complex res((r*other.r + i*other.i)/squaredLen, (i*other.r - r*other.i)/squaredLen);
return res;
}



And of course, you have to define the function squaredlength:

float Complex::squaredlength() const
{
return r*r + i*i;
}


And then works fine.

I've been using Angelscript in my fractal generating app and it works nicely, and the process of integrating it was painless thanks to it's clean API and good documentation. Thanks a lot for your work!

Share this post


Link to post
Share on other sites
Advertisement
Thanks. I'll have this corrected.

I just created the complex type for the add-on to provide a simple example on a value type. I haven't really tested it to make sure it performing the proper math calculations. rolleyes.gif

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!