$powerof(N,I) <-- Calculate N to power I

By vaseline28 on Jun 14, 2008

$powerof(N,I) Calculates N to the Power of I, can list also.

; $powerof(N,I) <-- Usage: Calculates N to the power of I
; Other use: $powerof(N,I).all <-- Calculates N to the power of I, but lists N to the power of all numbers up to I
; Example I: $powerof(12,4).all <-- Returns 144 1728 20736
; Example II: $powerof(10,6) <-- Returns 1000000

Specify any prop (.<>) for it to list.

; $powerof(N,I) <-- Usage: Calculates N to the power of I
; Other use: $powerof(N,I).all <-- Calculates N to the power of I, but lists N to the power of all numbers up to I
; Example I: $powerof(12,4).all <-- Returns 144 1728 20736
; Example II: $powerof(10,6) <-- Returns 1000000
alias powerof {
  if ($isid) {
    var %x 1 | var %t $1 | set %y
    while (%x < $2) {
      inc %x
      var %t $calc(%t * $1) 
      $iif($prop,set %y %y %t,)
    }
    if ($prop) { var %t %y | unset %y }
    return %t
  }
}

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.