How to resolve the algorithm Exponentiation with infix operators in (or operating on) the base step by step in the Ada programming language
How to resolve the algorithm Exponentiation with infix operators in (or operating on) the base step by step in the Ada programming language
Table of Contents
Problem Statement
(Many programming languages, especially those with extended─precision integer arithmetic, usually support one of **, ^, ↑ or some such for exponentiation.)
Some languages treat/honor infix operators when performing exponentiation (raising numbers to some power by the language's exponentiation operator, if the computer programming language has one).
Other programming languages may make use of the POW or some other BIF (Built─In Ffunction), or some other library service. If your language's exponentiation operator is not one of the usual ones, please comment on how to recognize it.
This task will deal with the case where there is some form of an infix operator operating in (or operating on) the base.
A negative five raised to the 3rd power could be specified as:
(Not all computer programming languages have an exponential operator and/or support these syntax expression(s).
Try to present the results in the same format/manner as the other programming entries to make any differences apparent.
The variables may be of any type(s) that is/are applicable in your language.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Exponentiation with infix operators in (or operating on) the base step by step in the Ada programming language
Source code in the ada programming language
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Main is
ivalue : Integer := -5;
fvalue : float := -5.0;
begin
Put_Line("Integer exponentiation:");
for i in 1..2 loop
for power in 2..3 loop
Put("x =" & ivalue'image & " p =" & power'image);
Put(" -x ** p ");
Put(item => -ivalue ** power, width => 4);
Put(" -(x) ** p ");
Put(item => -(ivalue) ** power, width => 4);
Put(" (-x) ** p ");
Put(Item => (- ivalue) ** power, Width => 4);
Put(" -(x ** p) ");
Put(Item => -(ivalue ** power), Width => 4);
New_line;
end loop;
ivalue := 5;
fvalue := 5.0;
end loop;
Put_Line("floating point exponentiation:");
ivalue := -5;
fvalue := -5.0;
for i in 1..2 loop
for power in 2..3 loop
Put("x =" & fvalue'image & " p =" & power'image);
Put(" -x ** p ");
Put(item => -fvalue ** power, fore => 4, Aft => 1, Exp => 0);
Put(" -(x) ** p ");
Put(item => -(fvalue) ** power, fore => 4, Aft => 1, Exp => 0);
Put(" (-x) ** p ");
Put(Item => (- fvalue) ** power, fore => 4, Aft => 1, Exp => 0);
Put(" -(x ** p) ");
Put(Item => -(fvalue ** power), fore => 4, Aft => 1, Exp => 0);
New_line;
end loop;
ivalue := 5;
fvalue := 5.0;
end loop;
end Main;
You may also check:How to resolve the algorithm Reverse words in a string step by step in the 11l programming language
You may also check:How to resolve the algorithm Multi-dimensional array step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Pseudo-random numbers/PCG32 step by step in the Lua programming language
You may also check:How to resolve the algorithm Twelve statements step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Longest common substring step by step in the Julia programming language