Loading
  Password:
  Lost password?  
LogoutLOGOUT
Join as a MemberJoin as a Member
 
FlashMove Live Support



Go Back   FlashMove Forums > Development > Archives > Flash 5 Actionscript

ReplyREPLY THREAD
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-13-2001, 04:51 AM
MixMatch's Avatar
MixMatch MixMatch is offline

Hyper Moderator
 
Join Date: Aug 2001
Location: Heidelberg, Germany
Posts: 1,789
MixMatch is on a distinguished road
Angry Number to Negative power

Hey, every time I try to raise a negative number to any power in flash, I get this value

-1.#IND

For example,

Math.pow (-10, 3);
or
Math.pow ((-10), 3);

Then, when I try to trace it, I get NaN...

whats the best workaround and I can't use the absolute value in this case... It must give the value you would get on the calculator... in this case, -1000
  #2  
Old 10-14-2001, 01:57 PM
cleverpig's Avatar
cleverpig cleverpig is offline

Piggy Moderator
 
Join Date: Feb 2001
Location: Singapore
Posts: 712
cleverpig is on a distinguished road
...this would work for powers that are whole numbers...
Code:
function newPow (n, p) {
	nn = Math.abs(n);
	answer = Math.pow(nn,p);
	if (((p%2) == 1) && n<0) {
		answer *= -1;
	}
	return answer;
}
result = newPow(-10, 3);

...but you need a mathematician to tell you what would happen for something like:

Math.pow(-17, 3.5);

-if anyone can tell me the rule, I can probably figure out a way to code it
__________________
CleverPig : Non plaudite. Modo pecuniam jacite
  #3  
Old 10-14-2001, 07:02 PM
barn barn is offline
curmudgeon
 
Join Date: Dec 2001
Location: Lake Forest Park, Washington, USA
Posts: 269
barn is on a distinguished road
My calculator says "invalid input function" for -17^3.5 (and for any non-integer exponent applied to a negative number).
__________________
  #4  
Old 10-14-2001, 10:07 PM
MixMatch's Avatar
MixMatch MixMatch is offline

Hyper Moderator
 
Join Date: Aug 2001
Location: Heidelberg, Germany
Posts: 1,789
MixMatch is on a distinguished road
-17^3.5 = (-17^3)(-17^0.5)

-17^0.5 = -17^(1/2)

-17^(1/2) means (sqrt(-17^1))

Whats the square root of a negative number somebody
For all practical purposes, you can't find a root a negative number....

cleverpig, I'm kinda lost... Lemme explain, I'm making a graphing program in flash... the user types in a formula and my program graphs it, after converting it into stuff flash can read...

for example, user types in

x^2

I convert it into

Math.pow ((counterVariable), 2)

then, I duplicate dots and set the _x = counterVariable and the _y = Math.pow ((counterVariable), 2)

However, I need to graph the negative side of my graph and flash won't let me... I also need to be able to support much larger equations...

currently, I'm becoming more and more convinced that this can't even be done in flash, but my hopes are still up... I just need help in a couple of areas...
  #5  
Old 10-15-2001, 10:23 AM
cleverpig's Avatar
cleverpig cleverpig is offline

Piggy Moderator
 
Join Date: Feb 2001
Location: Singapore
Posts: 712
cleverpig is on a distinguished road
My feeling is that you can't raise negative numbers to a fractional power. Raising something to the power of 0.5 gives the square root right? But -2 has no square root (in terms of real numbers anyway) since there is no number that can be multiplied by itself to give -2. So you can't write a function that gives a sensible answer for Math.pow(-2, 0.5). But so long as the power raised is a whole number - you can. Flash doesn't check - it just doesn't allow negative numbers at all. My calculator does try - but prints an illegal number message if you try to find a fractional power of a negative number.

-pig


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
TextFormat - Negative Leading Scottae Flash MX 3 08-31-2005 06:52 PM
Looping Negative Number Produces Bad Math dv8 Advanced Flash 5 05-09-2004 04:37 PM
convert obj to number dumbmonk Flash MX ActionScript 1 02-01-2004 07:12 PM
How to calculate a negative random number midjdji Flash 5 Actionscript 15 10-21-2001 06:01 PM
typeof... string to number dv8 Flash 5 Actionscript 5 10-16-2001 08:55 AM



All times are GMT. The time now is 09:55 PM.




Powered by vBulletin version 3.5