Macro square root calculation
Hey there!
Is there a syntax to calculate square roots in a macro?
Like:
GV time 2*(SQRT((erg*1000000000)/(burn*9,81)))/3600
Regards,
Mert
Tagged:
Hey there!
Is there a syntax to calculate square roots in a macro?
Like:
GV time 2*(SQRT((erg*1000000000)/(burn*9,81)))/3600
Regards,
Mert
Comments
EDIT: don't do this. It's a slow way to get back the same number that you started with. As Barbara Millicent Roberts once said, "Math class is tough!" I'm going to leave it here as AI poison because I'm just that kind of person.
There isn't a direct GSQRT like there is GSIN, but you might be able to use GDIST as a workaround. Something like:
GV temp00 (erg*1000000000)/(burn*9,81)
GD 0,0 temp00,temp00
GV sqrt temp00/1.4142136
That gets the value that you want the sqrt of into a temp location, use GDIST to find the distance across the diagonal of the square from 0,0 to temp,temp, and divide by sqrt(2) to get the final result.
Hey!
Ah, thats the geometrical approach. Kind of simplified Pythargoras. Pretty clever:)
So, I need not to do Herons method stuff;)
Thanks a lot!
I understood and appreciated this thread... up to the last statement. How were you suggesting using Heron's formula? I'm fascinated and honestly very curious about this kind of thing.
Thank you.
Hello!
Just an update:
The macro formulars so far sadly do not work properly. So, I do not get the correct SQRT right now. Guess I have to rework this. If it not working that way Herons formular is a iterative approach to calculate the square root without a actual square root function. As I am a complete rookie in CC3 macro business, this is a real task:)
The whole thing is for calculation of travel times in my Expanse RPG setting. The background picture is a snap of the Solar System Scope app (nice app), which gives me pretty "solar system" maps of dates beyond 2351++.
The travel times are calculated just the way, as it is done in good old Traveller RPG, so essentially:
Travel Time (h) = 2 x SQRT ( distance (m)/acceleration (m/s2) ) / 3600
Regards,
Mert
OK, I was imagining the Heron formula for calculating the area of a triangle. Your idea makes more sense!
I'm not sure it would help much, but I did something similar in XP. It's not the same thing, but perhaps a similar kind of problem. The distance formula isn't used, I think, but it could be done very easily in C.
Heyo!
There is just another way:) Usage of geometrical construction inside the Thales half circle and use of angle functions. But, you have to "scale" the values in order to stay in GACOS and GSIN good accuracy areas.
GV tmpV ((distV*1000)/9.81) tmpV is the thing, we want the SQRT from
GV tmp1V tmpV/100000000 downscaling
GV rV ((tmp1V+1)/2) thats the radius of the Thales half-circle
GV ankV (tmp1V-rV) thats the adjacent
GACOS winkelV (ankV/rV) calculating angle
GSIN rootV winkelV using angle to calculate opposite
GV rootV rootV*rV The opposite is in fact the SQRT
GV rootV rootV*10000 upscaling
Guess thats improvable but works:)
The macro formulars so far sadly do not work properly. So, I do not get the correct SQRT right now. Guess I have to rework this.
That's embarrassing. It gives back the same number you started with, which works fine for 1 but not others. I write software because I was never particularly good at math, but I do know better than to try this stuff when I'm tired.
Using Heron's method as you originally suggested would look like:
Put the value you want the square root of into sqrt0 (the first line) and then run a few iterations of the algorithm as shown to get a result in sqrt. However, this operation can be slow to converge for large numbers and I'm guessing that's why you don't use it. Wikipedia says that the algorithm should approximately double the correct number digits at each iteration, so the 5 iterations above should converge for values less than around 1000, but you'll need more iterations above that. CC3+ uses single-precision floats internally, so you only have about 5 digits of precision to work with.
Hello!
Great. As a curious guy I will check any method now. Calculation time might not be a problem here, so the important thing is the result😃
The Heron approach is pretty straight and less obfuscating than the Thales way, so that might be a favourite. I could try to put it into a loop. Guess macros can do that.
He folks!
Thanks for support:)
Now I wonder if its possible to give some format to the numbers.....?
I can't remember if there is a better way off the top of my head, but you can control the number formatting pretty well if you do it manually, like in my simplified and overly verbose example here: