Camion added the comment:
@mark.dickinson, I fell on this problem in the reached precision evaluation, of
a multiprecision algorithm designed to compute decimals of PI (using "John
Machin like" formulas).
The fact is that fractions module is really nice to implement this kind of
multipreci
Steven D'Aprano added the comment:
Guido wrote:
> it would require the math.log function to recognize rationals
I don't think it would. You don't need a type-check, you just need to check for
a pair of numerator and denominator attributes.
So we could do something like this, except in C:
Mark Dickinson added the comment:
@Camion: Can you say more about your use-case? One thing that's on my
would-be-nice-to-do-one-day list is 'e', 'f' and 'g'-style decimal formatting
for Fraction objects. Without that, it's often hard to get a quick sense of the
magnitude of a Fraction withou
Guido van Rossum added the comment:
The problem with that formulation of the feature request is that it would
require the math.log function to recognize rationals, or at least the Fraction
type. Since the numeric tower and the fractions module are implemented in pure
Python that would be som
Raymond Hettinger added the comment:
> Any principled change costs more than it's worth :-(
For anyone wanting to go forward with this, here's a summary of the feature
request:
Given two non-zero same signed integers x and y,
log10(Fraction(x, y)) does the same as log10(x / y).
Tim Peters added the comment:
Any principled change costs more than it's worth :-(
I'm mostly sympathetic with Guido's view, and have long advocated a new `imath`
module to hold the ever-growing number of functions that are really part of
integer combinatorics. But it's become nearly imposs
Raymond Hettinger added the comment:
> math.log10 works perfectly on integers which are too large
> to be converted to floats. I see no reason why it couldn't
> work as well with fractions.
This is tricky territory. Mathematically, a common logarithm can and often
will have a irrational res
Camion added the comment:
A generic solution might be to consider all number as fractions (which they
are) (floats have denominators being 2^n, decimals have denominators being
10^n, integers have denominators being 1, and fractions have denominators being
integers... but this would be a hea
Camion added the comment:
math.log10 works perfectly on integers which are too large to be converted to
floats. I see no reason why it couldn't work as well with fractions.
>>> math.log10(math.factorial(1))
35659.45427452078
>>> math.log10(math.factorial(100))
5565708.917186718
>>> ma
Guido van Rossum added the comment:
I guess another approach might be to change the math module so that all its
functions support franctions (and decimal, and other esoteric number types).
But that would require having __log__ and many others as methods on the numeric
types.
Personally I wi
Raymond Hettinger added the comment:
Internally, the math.log10() function only works on floats. By way of the
__float__() method, the input to the the math.log10() function is asked to
convert itself to a float. Fractions implement __float__() by just dividing
the numerator and denominato
New submission from Camion :
Python is able to computer the logarithms of very large integers and fractions
(by using log(num)-log(denom)), However the fractions.Fraction class fails to
do it and raises a math domain error exception.
>>> import math, fractions
>>> f=fractions.Fraction(math.fa
12 matches
Mail list logo