Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #305 Calculate exponentiation of real numbers

Compute and print a^b, and a^n, where a and b are floating point numbers and n is an integer.

puts a ** b, a ** n
  print *,a**b, a**n
import static java.lang.Math.pow;
import static java.lang.System.out;
out.println(pow(a, b));
out.println(pow(a, n));
math
writeln('a^b=',power(a,b));
writeln('a^n=',power(a,n));
use feature 'say';
my ($a, $b, $n) = (4.0, 0.5, 3);

say $a**$b;  # prints 2
say $a**$n;  # prints 64
print(a ** b, a ** n)

New implementation...