The Dink Network

Reply to Re: Square Root

If you don't have an account, just leave the password field blank.
Username:
Password:
Subject:
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
Message:
 
 
February 1st 2004, 10:13 PM
custom_odd.gif
Well to raise to a power, you'd be multiplying something by itself a number of times.

Let's say the power you want to raise it to is x.

int &x = 4;

loop:
if (&x > 1)
{
&var *= &var;
&x -= 1;
goto loop
}

Thus &var is now &var^4

It's been a while since I wrote this stuff, so it may not be exactly right, but you get the idea.

So if you want to find the square root of a distance (to use the distance formula) I'm not sure if there's a way you could do it other than guess and check...

I'm tempted to say the best way to do it may just be to have ranges, because that's how it'll end up in the end since you can't use variables. What you'd do here is know that the range of 1 is 1 to 1 (well, not really a range I guess) and 2 is 2-4 and 3 is 3-9 and so on, finding what range it's in via simple subtraction would be quite easy.

If you're nit picky and you actually need those decimals to get this to work, you'd have to multiply you're distances by 100000 and you could have 6 decimal places. To find it this way, though, you'd have to set up a guess and check system:

&d = 100;
//I trust you can find the distance on your own by subtracting x's and y's
&d-carry = &d;
//just so we don't mess up &d
&var1 = 1;
//var1 will be the square root we're checking
&var1-carry = &var;
//this'll just keep us from messing with &var1
&var2 = 2;
&var2-carry = 2;
&checker;
//we'll use this at the end to check (duh)

//ok wow, i started making a formula where you could do it with anything, not just square roots, and decided it was too complicated... how about just square roots this time.

check:

&var1-carry = &var1;
&var1-carry *= &var1-carry;

&var2 = &var1;
&var2 += 1;
&var2-carry = &var2;

&d-carry = &d;
&d-carry -= &var2;
if (&d-carry < 0)
{
//var2 was too much, use var1
goto next;
}

&var1 += 1;
goto check;

//ok stop for now, i'm not sure of a few things. i'm not sure that it'll go into negatives easily like this. also, this is likely not the most efficient way. meh. this is all basically if you're too lazy to just do a simple range method like i mentioned earlier. in fact, i dunno why i wrote that, just use ranges. really the only good way i can think of is to use the range system (or the more one above, which may be easier on the engine) to find the range, for instance the square root of 27 is between 5-6, you know that because 6 is too much, and you are left with &var1 = 5. Thus, if you multiply the distance by 1000000 you can narrow it down further and further with guess and check like this, depending on how much you want to code and how exact you want it to be...

wait... now for a question i should have asked a long time ago...

wtf do you need a distance formula for? i'll bet you can work around having to use it much easier than bothering to write a long enough script to check decimals into the variable.