[Programming] How can these line set a var to a non-real #?

BlueSin

New Member
Reaction score
37
I have here a line from ActionScript:

x = x - landy * Math.sin(1.745329E-002 * rot) / 2;

In general terms, real x is assigned x minus a variable multiplied by the sine of pi/2-2 * a variable rot (rotation), all over 2.

More simply:

x = x - (var1*Sin( (pi/2)- 2(var2) ))/2

However, this declaration is causing x to occasionally become Nan (not-a-number, or non-real number). I know things like square root of a negative number and anything divided by 0 cause unreal numbers, but what coudl be causing this?

Thanks, plus rep to anyone who can help in any way. :)
 

The Helper

Necromancy Power over 9000
Staff member
Reaction score
1,688
Well if you can test for the conditions that you know about. You could convert your division into a multiplication (multiply by .5 instead of / 2). If Action Script allows you to declare varialbles - make sure all the variables you use are declared and with the right type.

Also, make sure that your variables are always there because if it is not it might show up like zero or blank which could mess up the calculation.
 

BlueSin

New Member
Reaction score
37
>>make sure all the variables you use are declared and with the right type

Hah, yes I had just realized this about 5 minutes before you posted, thanks. :) Apparnetly landy has been set to NaN. Unfotunately, Flash's debugger isn't very good (or I just suck at using it) so I'll be doing a lot of toString()'s to trace the variable. :D

Thanks again though for pointing that out, I'll post back if I solve or fail at solving my problem. :)
 

mase

____ ___ ____ __
Reaction score
154
FYI, nan = undefined
 

BlueSin

New Member
Reaction score
37
I know being a non-real number is CONSIDERED undefined, but are they actually equal?

Like, for example:

i=0;
i=i/i;

*j hasn't been defined.*

if(j==i){
return true;
}

Would that return true?

As for problem... I'm still trying to trace why the other variable screws up.
 

The Helper

Necromancy Power over 9000
Staff member
Reaction score
1,688
In Microsoft world VBA land a null is your undefined and it does not equal zero. I bet it is the same for you. Is there a function in your language like is undefined? In VBA or VB it is isnull and it return true if the value is null.

If you can find that function or write a function like that you can solve your problem by just testing the variables before you call the function to make sure they are real - and if any are not then just load the answer 0.

To help you find out where your value is going bad place statements to print or write the value of the variable somewhere in different parts of the code so you can get an idea of where it is losing its value. In VB I use stop statements or debug.print statements to see what variable values are at different points in the process, stop the code and walk through it to see exactly what happens. Have it break on a certain condition in the debugger so you have less to walk through.

Hope this helps.
 

mase

____ ___ ____ __
Reaction score
154
I know being a non-real number is CONSIDERED undefined, but are they actually equal?

Like, for example:

i=0;
i=i/i;

*j hasn't been defined.*

if(j==i){
return true;
}

Would that return true?

As for problem... I'm still trying to trace why the other variable screws up.

No, you never set j at all.

If it was like
Code:
var j:Number = 0
var i:Number = 0
i = i / i

if (j == i){
return true
}

Unless you set j in another part of your code that you didn't show :eek:
 

BlueSin

New Member
Reaction score
37
In Microsoft world VBA land a null is your undefined and it does not equal zero. I bet it is the same for you. Is there a function in your language like is undefined? In VBA or VB it is isnull and it return true if the value is null.

If you can find that function or write a function like that you can solve your problem by just testing the variables before you call the function to make sure they are real - and if any are not then just load the answer 0.

To help you find out where your value is going bad place statements to print or write the value of the variable somewhere in different parts of the code so you can get an idea of where it is losing its value. In VB I use stop statements or debug.print statements to see what variable values are at different points in the process, stop the code and walk through it to see exactly what happens. Have it break on a certain condition in the debugger so you have less to walk through.

Hope this helps.

Thanks for the tips. Thanks to you, I looked it up and found a IsNaN() function, which helped me pinpoint the source of all the craziness (though I still haven't had time to actually fix it, but hey it's a start ). I was also using Flash's print equivalent, trace, to help follow the variable values.

Thanks again. :)

_________________________

>>No, you never set j at all.

Yes, I know, meaning it has a value of 'undefined' (you can see in the Variable List), since the Actionscript syntax checker is way too lenient and allows uninitialized variables. What I was wondering is if Nan==undefined, since that was what you had said, I was just too lazy to check myself. :)

I'll go check now I guess.

But that's besides the point, I've found the source of the problem and I am working on it! :D

I'd add to both of your reputations (not that an administrator needs it) but I have to spread some more first.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top