[issue42886] math.log and math.log10 domain error on very large Fractions

2021-01-11 Thread Camion
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

[issue42886] math.log and math.log10 domain error on very large Fractions

2021-01-11 Thread Steven D'Aprano
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:

[issue42886] math.log and math.log10 domain error on very large Fractions

2021-01-11 Thread Mark Dickinson
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

[issue42886] math.log and math.log10 domain error on very large Fractions

2021-01-10 Thread Guido van Rossum
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

[issue42886] math.log and math.log10 domain error on very large Fractions

2021-01-10 Thread Raymond Hettinger
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).

[issue42886] math.log and math.log10 domain error on very large Fractions

2021-01-10 Thread Tim Peters
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

[issue42886] math.log and math.log10 domain error on very large Fractions

2021-01-10 Thread Raymond Hettinger
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

[issue42886] math.log and math.log10 domain error on very large Fractions

2021-01-10 Thread Camion
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

[issue42886] math.log and math.log10 domain error on very large Fractions

2021-01-10 Thread Camion
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 >>>

[issue42886] math.log and math.log10 domain error on very large Fractions

2021-01-10 Thread Guido van Rossum
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

[issue42886] math.log and math.log10 domain error on very large Fractions

2021-01-10 Thread Raymond Hettinger
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

[issue42886] math.log and math.log10 domain error on very large Fractions

2021-01-10 Thread Camion
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 >>>