//Title: Mathematical Raise-to-Power Proc
//Credit to: Jtgibson
//Contributed by: Jtgibson
/*
This is a simple recursive procedure which multiples a number by itself a number
of times. It's an integer-based version of the floating-point "**" operator,
thereby saving a little bit of CPU time.
*/
proc/raisetopower(num, power)
if(!power) return 1
return (power-- > 1 ? num * raisetopower(num, power) : num)
/*
//Testing code/sample implementation:
mob/verb/test_raisetopower(num as num)
usr << "[num] squared = [raisetopower(num,2)]"
usr << "[num] cubed = [raisetopower(num,3)]"
usr << "[num] dodecahedroned = [raisetopower(num,4)]"
*/
ID:195146
Nov 21 2006, 7:02 am
|
|