You might also consider sticking to SymPy Reals unless you need a Python float 
for something else.  Among other things, it can give you arbitrary precision.  

In [23]: a = exp(10) + exp(20)

In [24]: a.evalf(100)
Out[24]: 
485187221.8755850846856237884421858429290053424574658111346850357423332213455283109585550497737155140

You can also use N() as a shortcut to evalf, as in N(a) == a.evalf().


By the way, the float() method works fine for me too, though I don't have 
Python 2.4 to test on right now.

Aaron Meurer
On Jan 13, 2010, at 8:32 AM, Ondrej Certik wrote:

> On Wed, Jan 13, 2010 at 4:30 AM, mindcorrosive <[email protected]> wrote:
>> I've got a problem when evaluating exponents using sympy (class
>> sympy.exp). Small code sample:
>> 
>>   import sympy as sy
>>   a=sy.exp(10)+sy.exp(20)
>>   print a
>>   >>> exp(10) + exp(20)
>> 
>> All is well and good, but I'd like to evaluate the expression (which
>> is obviously a constant). I try simply to convert it into a float:
>> 
>>   b=float(a)
>> 
>> and get an exception
>>   (trace omitted)
>>   TypeError: unsupported operand type(s) for >>: 'long' and 'float'
>> 
>> If "a" would have been
>> 
>>   a=sy.exp(10)
>> 
>> then the conversion works as expected.
>> 
>> Perhaps I'm not doing it the right way? I couldn't find an obvious way
>> to handle this.
>> 
>> If that's relevant, I'm running Py2.4, sympy 0.6.6 on win32.
> 
> This works on linux (latest sympy, both python2.4 and 2.6):
> 
> In [2]: a = exp(10) + exp(20)
> 
> In [3]: a
> Out[3]:
> 10    20
> ℯ   + ℯ
> 
> In [4]: float(a)
> Out[4]: 485187221.876
> 
> so you found a bug. Could you please post the whole traceback? Let's fix it.
> 
> Ondrej
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sympy?hl=en.
> 
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.


Reply via email to