On Wed, Oct 6, 2010 at 6:54 PM, Steven D'Aprano <
Post by Steven D'Apranomantissa and exponent of 1.2345e7
Perhaps not the prettiest, but you can always use string manipulations:
def frexp_10(decimal):
parts = ("%e" % decimal).split('e')
return float(parts[0]), int(parts[1])
You could also create your own mathematical function to do it
def frexp_10(decimal):
import math
logdecimal = math.log10(decimal)
return 10 ** (logdecimal - int(logdecimal)), int(logdecimal)
Testing the timings on those 2 functions for the number 1.235323e+09 on my
machine had the math-version at about 3x faster than the string version
(admittedly it was a single conversion... who knows what the general answer
is). The math module was loaded at the top of the program, so that didn't
add to the time of the math-execution.
Good luck!
Jason
=> (1.2345, 7)
Post by Steven D'Aprano(0.12345, 8) would also be acceptable.
math.frexp(1.2345e7)
(0.73581933975219727, 24)
Have I missed a built-in or math function somewhere?
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
--
Jason M. Swails
Quantum Theory Project,
University of Florida
Ph.D. Graduate Student
352-392-4032
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101006/5e866a2e/attachment.html>