On 10/6/10 5:54 PM, Steven D'Aprano wrote:
I want the mantissa and decimal exponent of a float, in base 10:

mantissa and exponent of 1.2345e7
=>  (1.2345, 7)

(0.12345, 8) would also be acceptable.


The math module has a frexp() function, but it produces a base-2 exponent:

math.frexp(1.2345e7)
(0.73581933975219727, 24)

Have I missed a built-in or math function somewhere?

|7> def frexp10(x):
..>     exp = int(math.log10(x))
..>     return x / 10**exp, exp
..>

|8> frexp10(1.2345e7)
(1.2344999999999999, 7)

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to