Click here to Skip to main content
15,908,455 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: pow(-1, 0.3333333333) doesn't return -1 Pin
Roman Nurik1-May-04 14:01
Roman Nurik1-May-04 14:01 
Generaland it shouldn't Pin
Tim Smith1-May-04 14:17
Tim Smith1-May-04 14:17 
GeneralRe: and it shouldn't Pin
Roman Nurik1-May-04 14:38
Roman Nurik1-May-04 14:38 
GeneralRe: and it shouldn't Pin
Tim Smith1-May-04 15:51
Tim Smith1-May-04 15:51 
GeneralRe: and it shouldn't Pin
Barvus1-May-04 19:49
Barvus1-May-04 19:49 
GeneralRe: and it shouldn't Pin
Tim Smith2-May-04 4:50
Tim Smith2-May-04 4:50 
GeneralRe: and it shouldn't Pin
Barvus2-May-04 5:35
Barvus2-May-04 5:35 
GeneralRe: and it shouldn't Pin
f641-May-04 19:10
f641-May-04 19:10 
Hi there
Tim is absolutely right.
The easiest way to calculate a power is using logarithms, so let say we have this
r = x ^ y
so to calculate r will be something like this
r = e ^ (y * log x)
where e^ and log can be obtained using the Taylor Polynomial

f(x) = f(a) + f'(a) * (x-a)/1! + f"(a) * (x-a)^2/2! + ...+ fN(a) * (x-a)^n/n!

where f', f" ... fN are the first n derivatives of f, and a is a value with which all the funcion can be calculated, for e^ can be 0 for ln, 1.

Anyway, like I was saing the use of logarithm is the reason you are not geting the real root you are looking for, as you can see in your case you would have something like this
r = e ^ ( 1/3 * log -1)
and as we all know log -1 has no solution on the domain of real numbers, the solution is an imaginary number, -PI i, and there is your problem.
So you have some options here, one is to do some analitical preprocessing before the actual calculations, the other one is to redefine pow and/or log to handle complex numbers.



Fabian
GeneralRe: pow(-1, 0.3333333333) doesn't return -1 Pin
Eguru1-May-04 20:46
Eguru1-May-04 20:46 
GeneralRe: pow(-1, 0.3333333333) doesn't return -1 Pin
Roman Nurik2-May-04 4:08
Roman Nurik2-May-04 4:08 
GeneralRe: pow(-1, 0.3333333333) doesn't return -1 Pin
f642-May-04 6:59
f642-May-04 6:59 
GeneralRe: pow(-1, 0.3333333333) doesn't return -1 Pin
Roman Nurik2-May-04 7:04
Roman Nurik2-May-04 7:04 
GeneralNo static linking Pin
jonsson_841-May-04 6:57
jonsson_841-May-04 6:57 
GeneralRe: No static linking Pin
peterchen1-May-04 7:23
peterchen1-May-04 7:23 
GeneralRe: No static linking Pin
PJ Arends1-May-04 14:16
professionalPJ Arends1-May-04 14:16 
QuestionReversal of VkKeyScan? Pin
Abin1-May-04 5:31
Abin1-May-04 5:31 
AnswerRe: Reversal of VkKeyScan? Pin
User 66581-May-04 7:22
User 66581-May-04 7:22 
AnswerRe: Reversal of VkKeyScan? Pin
Mike Dimmick2-May-04 0:14
Mike Dimmick2-May-04 0:14 
Questionhow to trap events and post it to a desired window Pin
shammyrly1-May-04 4:57
shammyrly1-May-04 4:57 
AnswerRe: how to trap events and post it to a desired window Pin
Abin1-May-04 5:36
Abin1-May-04 5:36 
QuestionHow do I load a 16x16 icon? Pin
Barvus1-May-04 4:38
Barvus1-May-04 4:38 
AnswerRe: How do I load a 16x16 icon? Pin
Barvus1-May-04 4:59
Barvus1-May-04 4:59 
AnswerRe: How do I load a 16x16 icon? Pin
Michael Dunn1-May-04 6:06
sitebuilderMichael Dunn1-May-04 6:06 
GeneralRe: How do I load a 16x16 icon? Pin
Barvus1-May-04 6:25
Barvus1-May-04 6:25 
GeneralRe: How do I load a 16x16 icon? Pin
Michael Dunn1-May-04 6:46
sitebuilderMichael Dunn1-May-04 6:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.