c# - product of double.PositiveInfinity and i -
i ran following strange product in c#. test below passes.
public void infinitytimesitest() { complex infinity = new complex(double.positiveinfinity, 0); complex = new complex(0, 1); complex product = infinity * i; double real = product.real; double imaginary = product.imaginary; assert.isnan(real); assert.istrue(double.ispositiveinfinity(imaginary)); }
it passes if reverse order of terms in product. thinking mathematically, c# appears saying is:
infinity * = (real nan) + infinity * i.
that seems strange choice. there must thinking behind it. i'm hoping here can provide insight going on.
i think expands complex multiplication this:
(inf + 0i) * (0 + i) = inf * 0 + inf * + 0i * 0 + 0i * = inf * 0 + inf *
first term product of infinity , 0 - nan. second term imaginary infinity.
edit: if @ sources, complex multiplication operator looks this:
public static complex operator *(complex left, complex right) { return new complex(left.m_real * right.m_real - left.m_imaginary * right.m_imaginary, left.m_imaginary * right.m_real + left.m_real * right.m_imaginary); }
Comments
Post a Comment