473,322 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

math.pow vs pow

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.
pow(2, 0+1j) (0.76923890136397211+0.63896127631363475j)
import math
math.pow(2, 0+1j) Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: can't convert complex to float; use e.g. abs(z)


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

When would I want to use math.pow?

Jul 18 '05 #1
5 2693
Clueless Moron <Bi********@Microsoft.com> writes:
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
Jul 18 '05 #2
John J. Lee wrote:
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?

Jul 18 '05 #3

"John J. Lee" <jj*@pobox.com> wrote in message news:87************@pobox.com...
| 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
Jul 18 '05 #4
Georgy Pruss wrote:

"John J. Lee" <jj*@pobox.com> wrote in message
news:87************@pobox.com...
| 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:
pow(-5,.5) 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:
pow(complex(-5), .5) (1.3691515264124976e-16+2.2360679774997898j)
pow(-5, complex(.5))

(1.3691515264124976e-16+2.2360679774997898j)

as you might expect.

Peter
Jul 18 '05 #5
"Georgy Pruss" <se*************@hotmail.com> writes:
"John J. Lee" <jj*@pobox.com> wrote in message news:87************@pobox.com...
| 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
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Frank Millman | last post by:
Hi all I was helping my niece with her trigonometry homework last night. Her calculator's batteries were flat, so I thought I would use Python's math module to calculate sin, cos, and tan. I...
0
by: Jussi Mononen | last post by:
Hi, I'm having problems to successfully execute the test scripts on a Compaq host ( OSF1 tr51bdev V5.1 2650 alpha ). Almost all tests end up with the following error message "PARI: *** ...
1
by: limelight | last post by:
I have discovered a math error in the .NET framework's Log function. It returns incorrect results for varying powers of 2 that depend on whether the program is run from within the IDE or from the...
17
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
7
by: bravesplace | last post by:
Hello, I am using the folling funtion to round a number to a single digit on my form: function round1(num) { return Math.round(num*1)/1 }
110
by: Gregory Pietsch | last post by:
I'm writing a portable implementation of the C standard library for http://www.clc-wiki.net and I was wondering if someone could check the functions in math.h for sanity/portability/whatever. I'm...
11
by: Sambo | last post by:
I have the following module: ------------------------------- import math def ac_add_a_ph( amp1, ph1, amp2, ph2 ): amp3 = 0.0 ph3 = 0.0 ac1 = ( 0, 0j ) ac2 = ( 0, 0j )
0
by: kirby.urner | last post by:
Cyber-curricula have a leveling aspect, as kids nearer Katrina's epicenter tune in and bliss out on 'Warriors of the Net' (why wait for stupid big dummy textbooks to catch up?). They feel more...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
15
by: bH | last post by:
Hi All, I have been looking at javascript drawing from this website : http://www.cwdjr.net/geometricDraw/pentagon_draw.html" and I am wondering why the author made it into two images : upper...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.