Powers/Exponents

by Unknown

Back to Mechanic's Corner.

celahir2005-02-25 12:20:54
Out of interest what are you going to use this for?
Unknown2005-02-26 00:12:37
QUOTE(Avator @ Feb 26 2005, 12:34 AM)
Erm, didn't Zmud allow you to use vbscript/jscript inline? I think I saw some scripts that accessed jscript through some "%something" syntax. If you manage to find out what it is then in Jscript the functions are:

Math.pow(base, exponent) - Returns the value of a base expression taken to a specified power.

Math.sqrt(number) - Returns the square root of a number.

Math.log(number) - The return value is the natural logarithm of number. The base is e.

Math.exp(number) - The return value is enumber. The constant e is Euler's constant, approximately equal to 2.178 and number is the supplied argument.

Plus there are all the derived math functions (sine, cosine, etc), and most other stuff.

And why you would want to convert a float into a ratio of integers is simply beyond me.
59514


*thwaps himself*

D'oh, how did I (and everyone else, except you) forget about Jscript and VBscript in zMUD?

Thank you for posting them. biggrin.gif

Is there any functions for doing any types of roots, e.g. cube roots? I could make a function using Math.pow() to get it, though.
Unknown2005-02-26 00:13:47
QUOTE(celahir @ Feb 26 2005, 01:20 AM)
Out of interest what are you going to use this for?
59524


I might make a mini "Operating System". tongue.gif
Unknown2005-02-26 00:17:59
And this is an example of how you do what Avator said:

CODE
%mss( "Math.pow(2,2)", ######)


Which would return:

4
Unknown2005-02-26 00:34:04
Bleh, what the hell? The hashes should be "######".

Also, in zMUD,
CODE
%mss( "Math.log(10)", "######")

returns 2.30258509299405, when it should return 1. wacko.gif

Isn't it log to base 10?

Also, what is the VBScript version of these functions (Math.pow() etc.)?
Unknown2005-02-26 00:35:13
Argh! Why are these forums gagging "J-a-v-a-S-c-r-i-p-t"?
Unknown2005-02-26 00:40:22
Oh, Math.log(x) returns the natural logarithm of x. Bleh, I dunno, I've only just begun 6th form maths (6th form = ages 16-17).

Here is a useful site on the J-avaScript math functions: http://members.ozemail.com.au/~dcrombie/J A V A S C R I P T/chap11.html
Remove the spaces and make lowercase to "J A V A S C R I P T".
Daganev2005-02-26 01:33:06
The word J a v a yeah... is the command to start a script, so I think its to prevent people from running malicious code.
Unknown2005-02-26 01:36:55
Oh, okay.

echo "Hello World.";
?>

*cough*


Back on topic, what's natural logarithm, and how can I get a function which can find the base 10 logarithm of x?
Unknown2005-02-26 05:36:38
You can get the Microsoft Script Documentation, I think there was a link to that (well hidden) download somewhere on the Scripting section of www.mushclient.com

Natural logarithm is a log to the base of e which is the natural number. If you want a base-10 log then you should do:

Log10 = Math.Log(number)/Math.Log(10)

The same way you can calculate a logarithm of a number to any any base N:

LogN = Math.Log(number)/Math.Log(N)

Vbscript's versions of these functions are the same, only you don't need the Math object, so the above would be:

LogN = Log(number)Log(N)

Unknown2005-02-26 08:40:01
doh.gif Expressing my stupidity even more, I already have the documentation (which I got for MUSHclient).

Thanks for that Log information. wink.gif

About the VBScript math functions -- they don't have the power (pow) function.
Unknown2005-02-26 08:54:34
I think in vbs you can just do x^y, though I might be wrong. There's certainly a way, I am just not sure what it is exactly.
Unknown2005-02-26 09:13:51
Ah, x^y does work. Thank you.
Unknown2005-02-26 09:41:35
I made this script to calculate which language is faster, VBScript or ######:

CODE
#CLASS {MathTest}
#ALIAS math_test {
 #CLR
 #LOOP %1 {
   #VARIABLE MathTest %secs
   #VARIABLE MathTest2 %mss( "133.2^7.25")
   #VARIABLE MathTest {%eval( %secs - @MathTest)}
   #ADDITEM MathTest3 %float( @MathTest)
   #VARIABLE MathTest %secs
   #VARIABLE MathTest2 %mss( "Math.pow(133.2,7.25)", "######")
   #VARIABLE MathTest {%eval( %secs - @MathTest)}
   #ADDITEM MathTest4 %float( @MathTest)
   #CLR
   #ECHO %eval( %i / (%1 / 100))~%
   }
 #CLR
 #ECHO {VBScript average speed per calculation:"   "%eval( (%expandlist( @MathTest3, " + ")) / %float( %numitems( @MathTest3))) ms.}
 #ECHO {###### average speed per calculation:" "%eval( (%expandlist( @MathTest4, " + ")) / %float( %numitems( @MathTest4))) ms.}
 #ECHO %crlf%if( @MathTest3 = @MathTest4, "Both scripts calculated at an equal speed.", %if( @MathTest3 < @MathTest4, "VBScript", "######")" calculated at a faster speed.")
 #VARIABLE MathTest3 %null
 #VARIABLE MathTest4 %null
 }
#VARIABLE MathTest2 {2.52729320701342E+15}
#VARIABLE MathTest3 {}
#VARIABLE MathTest4 {}
#VARIABLE MathTest {0}
#CLASS 0

But the both calculate to quickly that is doesn't really show anything, usually they're the same.

Test syntax: math_test x

Where x is the amount of times it loops -- I recommend 1000+ (1000 takes about 20 seconds).
Daganev2005-02-26 09:45:14
you should add a line that takes the start of the loop, and subtracts the time from the end of the loop so you have the speed in miliseconds instead of your perceived time.
Unknown2005-02-26 10:06:53
They should be the same - jscript and vbscript use the same interpreter, so the difference is going to be negligible. But a thousand iterations in 20 seconds?! Ouch! You should try using vbscript's Timer function instead and maybe a vbscript/jscript loop instead of Zmud's, since a 1000 iterations shouldn't even be measurable. Granted that I have a P4-2.8GHz system, Timer only starts picking up something other than zero on two power operations at 6,000 iterations,
Unknown2005-02-26 10:18:43
Bleh. As you said, this script is useless anyway.
Drago2005-02-26 10:40:49
..am I the only person who can't figure out what you'd need powers or exponents for in Zmud?

I really just can't figure it out.
Daganev2005-02-26 10:42:40
I can think of a few reasons.

1) something to do with math and formulas

2)something to do with timing and random number generation

3)something to do with money
Unknown2005-02-26 21:23:03
How exactly are numbers randomly generated? I mean, a computer can't just pick a number out of nowhere...