return null on nan or infinite inputs  ( the previous version
probably lead to crashes)