Information
By: Moikle
Asked: December 14, 2011
Worth: 10 Member Points
Imaginary numbers

Is there any way in game maker to check if a number will be imaginary before calculating it and causing errors? Like a dll or something?


Dev - Warning
Dev - After editing rating, make rating display change
Dev - When editing, update "edited" column
Dev - Restore deleted comments
Dev - Display deleted comments if mod (hidden, then with dropdown)
Dev - After deletion or during edit, make rating dropdown appear again
Dev - Stricter rating rules. Prevent user from rating again
Dev - Pages
Dev - Reporting
Yeah just make sure it's not negative before you square root it.
Posted by Ferret December 14, 2011 17:39 - 1.4 years ago
| [#01]

you mean like checking if a number is negative before trying to take its root?...

if (x >= 0)
//take root
else
//don't take root OR multiply by -1, then take root OR something

EDIT: ninja'd by Ferret. :o
Posted by colseed December 14, 2011 17:40 - 1.4 years ago
| [#02]

hmm, I don't do A level maths so I can't remember the correct term, but I don't just mean the square of a negative, I mean things like division by zero, infinity etc.

I want the user to enter a string (an equation), which is converted to code, then checked to see if it is possible to execute, before executing it.
Posted by Moikle December 14, 2011 18:04 - 1.4 years ago
| [#03]

Then make sure the denominator isn't equal to zero...? Idk sounds like you just need an if statement but I'm not even sure about what you are talking about.
Posted by Ferret December 14, 2011 18:06 - 1.4 years ago
| [#04]

It's for things like this that I become upset with GM for not having exception handling.
Posted by Kilin December 14, 2011 18:07 - 1.4 years ago
| [#05]

Use sqrt(abs(value))
Posted by Taizen Chisou December 14, 2011 18:07 - 1.4 years ago
| [#06]

I basically just want to make sure that the answer to the equation is a real number that the computer can understand.

Sorry, I am obviously not very knowledgeable about this, but I am curious.
Posted by Moikle December 14, 2011 18:08 - 1.4 years ago
| [#07]

I agree with Taizen, surely just use a modulus function (ie abs()) to make it real? On the other hand, you could check if x<=0. Finally, if it's something mathematical like quadratic formula there is a method of checking if there a real solutions... but if its not mathematical like that I won't type it haha
Posted by mattywooda December 14, 2011 18:13 - 1.4 years ago
| [#08]

Imaginary numbers only show up if you square root a negative number. In math it's best to separate the negative by taking out negative 1 like so: sqrt(-4) => sqrt(4*(-1)) and then get 2i and i=sqrt(-1). In GM, if you don't want to deal with imaginary numbers just make sure you use absolute values in the square root (ie, abs(x)).

@matty, it's fine if x=0, just can't be negative.
Posted by Ferret December 14, 2011 18:14 - 1.4 years ago
| [#09]

Opps I meant to say check if x>=0 and then the operation can go ahead. And I thing the easiest thing to do would be abs(), then use other parameters to check if the event is allowed in game.
Posted by mattywooda December 14, 2011 18:19 - 1.4 years ago
| [#10]

hmmm. ok, don't worry maybe this problem was... imaginary

PAHAHAHA i'm so punny.
Posted by Moikle December 14, 2011 18:19 - 1.4 years ago
| [#11]

i should brutally assassinate your face for that comment, Moikle.
Posted by JID December 14, 2011 18:25 - 1.4 years ago
| [#12]

:P but yeah, the problem still stands of checking for the square roots in an equation the user enters in order to replace the value with it's absolute value.
Posted by Moikle December 14, 2011 18:29 - 1.4 years ago
| [#13]

So the user is entering entire equations?
Posted by Ferret December 14, 2011 18:39 - 1.4 years ago
| [#14]

well, sort of. For graphing, I am just experimenting
Posted by Moikle December 14, 2011 21:07 - 1.4 years ago
| [#15]

Recent Activity
 
Active Users (0)