473,795 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.769238901363 97211+0.6389612 7631363475j)
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 2708
Clueless Moron <Bi********@Mic rosoft.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.co m> 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.co m> 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.369151526412 4976e-16+2.2360679774 997898j)
pow(-5, complex(.5))

(1.369151526412 4976e-16+2.2360679774 997898j)

as you might expect.

Peter
Jul 18 '05 #5
"Georgy Pruss" <se************ *@hotmail.com> writes:
"John J. Lee" <jj*@pobox.co m> 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
2329
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 tried the example in the text book first, to ensure that I was getting the correct result, but it did not agree. Then my wife had the idea of using the Microsoft calculator in scientific mode, and that one did give the correct result.
0
2301
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: *** Invalid arguments to divll. at test_eng/Testout.pm line 30. ...propagated at t/polyser.t line 9. t/polyser.....dubious
1
2742
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 command line. The amount by which the calculation is off is very small; even though the double data type holds the errant value, it seems to round off when printed (via ToString()) and shows the correct one. The problem is that the errant value is...
17
3629
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 deep. In that case you need much more ram than a PC has to store functions calculated in loops so that you do not have to recalculate every time you cycle through the nest of loops. Using a HD for storage to extend ram is much too slow for many...
7
2453
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
8624
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 almost halfway through writing the over 200 functions needed to implement C99's version of math.h, and I would like to have some feedback and/or expert advice on my implementations. Sincerely, Gregory Pietsch
11
7373
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
1986
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 empowered by Python and Ubuntu than by any King's English I'd warrant, given how the latter has been dumbed down (slowed, degraded) by unimaginative bankers who can't fathom open source and its math-teaching significance to our digitally savvy...
4
10900
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
2949
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 half then lower half?. Is there a rule that says you can't do it in one set of calculated values for all the points as the points
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.