In some discussion regarding changes to Float that are part of pull # 998 ( https://github.com/sympy/sympy/pull/998 ), the question of whether to allow a high precision Float to be made from a low precision float has arisen.
e.g. in my branch, Float(.3, 20) is disallowed since at face value one might expect this to produce 0.30000000000000000000, but it doesn't. It produced (in master) the 20 decimal digits that represent the floating point approximation of 3/10: 0.29999999999999998890. So, like Decimal (see below), I would prefer to disallow creation of high- precision floats from low-precision input. In this case, an error would be raised in my branch: >>> Float(.3,20) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "sympy\core\numbers.py", line 529, in __new__ raise ValueError('float has insufficient precision; send as Float("%s", %s)? ' % (num, dps)) ValueError: float has insufficient precision; send as Float("0.3", 20)? In order to obtain that high precision value of the *floating point representation* of 0.3, evalf would have to be used: Float(. 3).evalf(20). To obtain a high-precision value of 0.3 one would send (as suggested by the error message) the 0.3 in a string: Float("0.3", 20) will give a 0.3 followed by 19 zeros. In practice, here are 3 different ways one might try to get 21 digits of cos(.3): >>> cos(Float(.3).n(21)) # 21 digits of cos(21-digit approx of 0.3) 0.955336489125606022923 >>> cos(.3).n(21) # 21 digits of the cos(15-digit approx of 0.3) 0.955336489125606022621 >>> cos(Float('.3', 21)) # 21 digits of cos(3/10 - exact) 0.955336489125606019642 Notice that all three of the answers are different. I would like to not allow cos(Float(.3, 21)) to be one of the methods. Instead, the attempt to make a 21 digit value of 0.3 would raise an error since python is mostly using WYSIWYG for floats (e.g. it prints only the most significant digits of things like 0.3 rather than 0.29999999...). The user might mean "0.3" or the more float-savvy user might mean "the floating point approximation of 0.3". I would like them to explicitly use evalf to get that value. Note that Decimal disallows creation of the high precision Decimal instances from floats (all floats, even floats like 0.5): >>> decimal.Decimal(0.5) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\python26\lib\decimal.py", line 649, in __new__ "First convert the float to a string") TypeError: Cannot convert float to Decimal. First convert the float to a string I would like to see Float follow the same convention. Would love to get feedback from others on this so a decision can be made for that branch. -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.