diff --git a/MDmisc/numbers.py b/MDmisc/numbers.py index a4ae5dea71b8406feb044d7919672c00a550dca0..4863a8fcde3d86636290047efcbe462640d0e5c3 100644 --- a/MDmisc/numbers.py +++ b/MDmisc/numbers.py @@ -10,3 +10,28 @@ def scientific_format( number, digits = 3 ): '1.337e+07' """ return ( "%%.%de" % digits ) % float( number ) + +def frexp10( x ): + """ + Function to export the mantisse and the power of any number passed in + argument. + + >>> print frexp10( -1337 ) + (-1.337, 3) + >>> print frexp10( -1.337e3 ) + (-1.337, 3) + >>> print frexp10( -0.1337 ) + (-1.337, -1) + >>> print frexp10( -1.337e-1 ) + (-1.337, -1) + >>> print frexp10( 1.337e-1 ) + (1.337, -1) + >>> print frexp10( 0.1337 ) + (1.337, -1) + >>> print frexp10( 1.337e3 ) + (1.337, 3) + >>> print frexp10( 1337 ) + (1.337, 3) + """ + m, e = ( "%e" % float( x ) ).split( 'e' ) + return float( m ), int( e )