[IronPython] Math accuracy?
Keith J. Farmer
kfarmer at thuban.org
Wed Aug 24 13:01:58 CEST 2005
Or just:
if (Math.Truncate(c) == c && d == 0 && c >= 0)
{
return this.pow((int)c);
}
Where you uncomment some better code already provided, and adjust:
internal Complex64 pow(int power)
{
if (power == 0) return new Complex64(1, 0);
if (power < 0) throw new
ArgumentOutOfRangeException("power", power, "power must be >= 0");
Complex64 factor = this;
Complex64 result = new Complex64(1, 0); //!!! want a
mutable here for efficiency
while (power != 0)
{
if ((power & 1) != 0) result = result * factor;
factor = factor * factor;
power >>= 1;
}
return result;
}
-----
Keith J. Farmer
kfarmer at thuban.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20050824/3763038e/attachment.html>
More information about the Ironpython-users
mailing list