kripken/emscripten — pull request #1207 by gagern (2013-05-24 19:26:12+00:00)
Title: Make division of complex numbers work in the absence of logb.

I noticed that the division operator for `std::complex` does not work as it should, due to the fact that emscripten does not provide a `logb` implementation. I changed the code to work without that function.

This change might increase chances for an overflow, but will handle the most common cases, stay close to the original implementation, and work without too much loops to jump through. It would be possible to implement logb using a loop (probably squaring some variable at each run), but this comes at a much higher cost than the low-level bit-fiddling one would expect in this situation. So until JavaScript Math does provide reasonable primitives for bit operations on floating point numbers, this kind of optimization does not appear worth the effort. Another solution would be a reinterpretation of double variables as long. Portability might be a problem in this case, though, since implementations might use different formats for their numbers.