Jump to content

Raising a "negative" number to the power problem


valkk
 Share

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
Link to comment
Share on other sites

  • Developers

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

:ph34r:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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.

Link to comment
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
Link to comment
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...

Link to comment
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...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...