Square Root?

Help section from before the user variable changes that broke all macros

Moderator: MacroQuest Developers

kagonis
a hill giant
a hill giant
Posts: 228
Joined: Sat May 24, 2003 8:48 pm

Square Root?

Post by kagonis » Mon Jun 02, 2003 6:59 am

Is it possible to calculate the square root of a number with MQ?
When calculating a distance the Z axis is not used by default, wich makes the distance for ranged events inaccurate.

I was then thinking that it doesn't matter, cause I just calculate the actual distance myself, but this requires the ability to calculate the square root.

/echo Actual distance: $calc($target(distance)+$calc(sqrt($target(distance)^2-$target(distance,z)^2)))

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Mon Jun 02, 2003 8:17 am

I don't believe that square root is currently supported, but I can't see that it would be that hard to add. Lemme get a fresh CVS download and take a look.
MQ2: Think of it as Evolution in action.

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Mon Jun 02, 2003 8:38 am

If I'm not way off base, this should work:

Code: Select all

					// $sqrt(xxx)
					} else if (!strncmp("sqrt(",szVar,5)) {
						if (!strstr(szVar,")")) {
							DebugSpew("PMP - Bad $sqrt() '%s'",szVar);
							i--;
							szOutput[j] = '@';
							j++;
						} else {
							CHAR Formula[MAX_STRING] = {0};
							while (szOriginal[i]!=')') i++;
							strcpy(Formula,szVar+5);
							Formula[strstr(Formula,")")-Formula] = 0;
							sprintf(Formula,"%1.2f",(sqrt(Calculate(Formula))));
							strcat(szOutput,Formula);
							j+=strlen(Formula);
						}
Put this in EQLib_MacroParser.cpp, just before the $sin function.
MQ2: Think of it as Evolution in action.

kagonis
a hill giant
a hill giant
Posts: 228
Joined: Sat May 24, 2003 8:48 pm

Post by kagonis » Mon Jun 02, 2003 12:44 pm

Thanks, will try that when I get the MSVS.NET I ordered at work :)
Gonna be a bit though, they are slow at work :p

wassup
Official Guardian and Writer of TFM
Official Guardian and Writer of TFM
Posts: 1487
Joined: Sat Oct 26, 2002 5:15 pm

Try this instead?

Post by wassup » Mon Jun 02, 2003 12:58 pm

Is there a function to raise a value to a power?

sqrt(xxx) = (xxx)^0.5

Easier than implementing another function.

kagonis
a hill giant
a hill giant
Posts: 228
Joined: Sat May 24, 2003 8:48 pm

Post by kagonis » Mon Jun 02, 2003 1:01 pm

/echo $calc(4^0.5) should work I guess

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Mon Jun 02, 2003 2:46 pm

I dunno, the sqrt code above is really a simple cut and paste job. I just adapted the $sin code, changed the calculation, and extended the string length from 4 to 5 to accomodate the extra letter (sin vs sqrt).
MQ2: Think of it as Evolution in action.