Raising a "negative" number to the power problem

Recommended Posts

I keep getting -1.#IND as a result for raising a negative number to a power.

Positive numbers work, but negative don't.

4^2=16

3^3=27

(-4)^2=16 ( I get 1.#IND )

(-3)^3=-27 ( I get 1.#IND )

Ironicly if you calculate it manually in autoit, it works ^^.

(-4)*(-4)=16

(-3)*(-3)*(-3)=-27

Makes no sense. Why is this and how do I get around it? You can't square root a negative number, but you can sure raise it to a power.

Edited by valkk

Share on other sites

I keep getting -1.#IND as a result for raising a negative number to a power.

(-4)^2=16 ( I get 1.#IND )

<{POST_SNAPBACK}>

and it does work when you do:

0-4^2

Live for the present,
Dream of the future,
Learn from the past.

Share on other sites

and it does work when you do:

0-4^2

<{POST_SNAPBACK}>

Wouldn't the order of operations make that:

0 - ( 4 ^ 2) ??

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share on other sites

Wouldn't the order of operations make that:

0 - ( 4 ^ 2) ??

<{POST_SNAPBACK}>

No, I think he means (0 - 4) ^ 2

Share on other sites

No, I think he means (0 - 4) ^ 2

<{POST_SNAPBACK}>

Sure, that is what he means, but it too fails just the same as (-4) ^ 2 fails. Try this:

```\$ret = (0 - 4) ^ 2
MsgBox(0, "", \$ret)```

Same problem.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share on other sites

True... I wonder why....

Because I assumed that AutoIt handles all math.

(Can't make a good English sentence of it...)

Share on other sites

Unfortunately, it's true...

Really:

(-1)^1 equals to 1, not indefinite...

Share on other sites

If we remember our algebra lessons, raising an expression x to a negative power is equivalent to dividing 1 by your x expression. However, if your x expression reaches a zero value, your division will not be defined, so, one way of solving your problem is to divide 1 by your x expression and making sure X does not reach a zero value.

IVAN

Edited by ivan

Share on other sites

0-4^2 will do the power first (remember order of operations) and then the subtraction. That is, 0 - (4^2) = 0 - 16 = -16.

Hmm, Negative numbers to integer powers should work, but they do not. The problem comes from the situation when a negative is raised to a non-integer power. The results can be quite complex (as in the complex number set). I will check what is happening and see if I can improve it.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share on other sites

I have submitted a fix for this problem. I expect it will appear in the unstable soon.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Create an account

Register a new account