|
#1
|
||||
|
||||
|
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
|
||||
|
||||
|
...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
|
|
#4
|
||||
|
||||
|
-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
|
||||
|
||||
|
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 |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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.




TODAY'S POSTS



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

