(-1)**1000

Jean-Michel Pichavant jeanmichel at sequans.com
Wed Oct 22 04:39:04 EDT 2014


----- Original Message -----
> From: "ast" <nomail at invalid.com>
> To: python-list at python.org
> Sent: Wednesday, 22 October, 2014 10:27:34 AM
> Subject: (-1)**1000
> 
> Hello
> 
> If i am writing (-1)**1000 on a python program, will the
> interpreter do (-1)*(-1)*...*(-1) or something clever ?
> 
> In fact i have (-1)**N with N an integer potentially big.
> 
> I do some tests that suggest that Python is clever
> 
> thx

Python will yield the correct results. That is the most clever thing to do.
If you really worried about execution speed (I assume that what your question implies), Python may not be the language you need.

However, know that there are these modules "numpy" and "scipy" which are used by the scientific community which provide a python interface (it's a python module) but most of the heavy lifting is done in C (you can embed C in python code). 

For instance
http://docs.scipy.org/doc/numpy/reference/generated/numpy.power.html

Use this module if speed is what you're looking for.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the Python-list mailing list