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

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Exponentiation operator step by step in the J 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 J programming language

Source code in the j programming language

   exp  =:  */@:#~ 
   
   10 exp 3
1000
   
   10 exp 0
1


   exp  =:  *@:] %: */@:(#~|)
   
   10 exp _3
0.001


   exp =: dyad def 'x *^:y 1'

   10 exp 3
1000
   10 exp _3
0.001


 exp  =:  ^.^:_1
 
 81 exp 0.5   
9


 exp  =:  %:^:_1~
 
 81 exp 0.5
9


   pi =: 3.14159265358979323846
   e  =: 2.71828182845904523536
   i  =: 2 %: _1                  NB.  Square root of -1
   
   e^(pi*i)
_1


   exp =: %:^:_1~
   
   e exp (pi*i)
_1


  

You may also check:How to resolve the algorithm The Name Game step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Detect division by zero step by step in the Scala programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the Burlesque programming language
You may also check:How to resolve the algorithm Penta-power prime seeds step by step in the Go programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the Elixir programming language