How to resolve the algorithm Exponentiation operator step by step in the Quackery programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Exponentiation operator step by step in the Quackery programming language

Table of Contents

Problem Statement

Most programming languages have a built-in implementation of exponentiation.

Re-implement integer exponentiation for both   intint   and   floatint   as both a procedure,   and an operator (if your language supports operator definition). If the language supports operator (or procedure) overloading, then an overloaded form should be provided for both   intint   and   floatint   variants.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Exponentiation operator step by step in the Quackery programming language

Source code in the quackery programming language

  [ $ "bigrat.qky" loadfile ] now!
  
  forward                         is **    (   n n --> n   )
  
  [ dup 1 < iff
     [ 2drop 1 ] done
    dup 1 & iff
        [ 1 - dip dup ** * ] 
    else
      [ 1 >> dip [ dup * ] 
        ** ] ]              resolves **    (   n n --> n   )

  forward                         is (v**) ( n/d n --> n/d )

  [ dup 0 = iff
      [ drop 2drop 1 n->v ]
      done
    dup 1 & iff
      [ 1 - dip 2dup (v**)
        v* ]
    else
      [ 1 >> 
        dip [ 2dup v* ] 
        (v**) ] ]           resolves (v**) ( n/d n --> n/d )
    
  [ dup 0 < iff
      [ abs (v**) 1/v ]
    else (v**) ]                  is v**   ( n/d n --> n/d )
    
say "The 10th power of 2 is: "
2 10 ** echo cr cr
 
say "The -10th power of 2.5 is: " 
$ "2.5" $->v drop -10 v** 20 point$ echo$

  

You may also check:How to resolve the algorithm 99 bottles of beer step by step in the VBScript programming language
You may also check:How to resolve the algorithm Largest proper divisor of n step by step in the Arturo programming language
You may also check:How to resolve the algorithm Chowla numbers step by step in the Delphi programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Plain TeX programming language
You may also check:How to resolve the algorithm URL encoding step by step in the REALbasic programming language