Fix for NAN/INF converted to invalid numbers in write(). Closes #30