Advertisement

Bug on complex division

Started by July 13, 2012 06:25 PM
1 comment, last by WitchLord 12 years, 5 months ago
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!
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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
Checked in under revision 1362

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement