Complex number implementation in Javascript