math.pow vs pow

C

Clueless Moron

Why do they act differently with respect to complex numbers?

Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last):

Apart from handling complex numbers, the built-in pow also has a
modulo efficiency hack.

When would I want to use math.pow?
 
J

John J. Lee

Clueless Moron said:
Why do they act differently with respect to complex numbers? [...]
Apart from handling complex numbers, the built-in pow also has a
modulo efficiency hack.

When would I want to use math.pow?

For some applications, getting a complex result means you've made a
mistake. And some people don't know what a complex number is, and
would rather have their teeth drilled than find out.


John

You wouldn't know a subtle plan if it painted itself purple and danced
naked on top of a harpsichord singing 'Subtle Plans Are Here Again'

Blackadder
 
C

Clueless Moron

John said:
For some applications, getting a complex result means you've made a
mistake. And some people don't know what a complex number is, and
would rather have their teeth drilled than find out.

Perhaps, but why should pow() be different from math.pow() in python?
 
G

Georgy Pruss

| For some applications, getting a complex result means you've made a
| mistake. And some people don't know what a complex number is, and
| would rather have their teeth drilled than find out.

Can you provide an example when pow with real arguments gives a complex result,
please?

Georgy

|
|
| John
|
| You wouldn't know a subtle plan if it painted itself purple and danced
| naked on top of a harpsichord singing 'Subtle Plans Are Here Again'
|
| Blackadder
 
P

Peter Otten

Georgy said:
| For some applications, getting a complex result means you've made a
| mistake. And some people don't know what a complex number is, and
| would rather have their teeth drilled than find out.

Can you provide an example when pow with real arguments gives a complex
result, please?

He could, if Python were not so reluctant:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: negative number cannot be raised to a fractional power

Sad day for the dentist:)
But:
(1.3691515264124976e-16+2.2360679774997898j)
(1.3691515264124976e-16+2.2360679774997898j)

as you might expect.

Peter
 
J

John J. Lee

Georgy Pruss said:
| For some applications, getting a complex result means you've made a
| mistake. And some people don't know what a complex number is, and
| would rather have their teeth drilled than find out.

Can you provide an example when pow with real arguments gives a complex result,
please?
[...]

I was thinking about results of earlier calculations providing the
argument for pow.


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top