kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Exponentiation operator
C#: static void Main(string[] args)
{
	Console.WriteLine("5^5 = " + Expon(5, 5));
	Console.WriteLine("5.5^5 = " + Expon(5.5, 5));
	Console.ReadLine();
}

static double Expon(int Val, int Pow) 
{
	return Math.Pow(Val, Pow);
}
static double Expon(double Val, int Pow)
{
	return Math.Pow(Val, Pow);
}

C++: template<typename Number>
 Number power(Number base, int exponent)
{
  int zerodir;
  Number factor;
  if (exponent < 0)
  {
    zerodir = 1;
    factor = Number(1)/base;
  }
  else
  {
    zerodir = -1;
    factor = base;
  }

  Number result(1);
  while (exponent != 0)
  {
    if (exponent % 2 != 0)
    {
      result *= factor;
      exponent += zerodir;
    }
    else
    {
      factor *= factor;
      exponent /= 2;
    }
  }
  return result;
}
Task: Exponentiation operator
C++: template<typename Number>
 Number power(Number base, int exponent)
{
  int zerodir;
  Number factor;
  if (exponent < 0)
  {
    zerodir = 1;
    factor = Number(1)/base;
  }
  else
  {
    zerodir = -1;
    factor = base;
  }

  Number result(1);
  while (exponent != 0)
  {
    if (exponent % 2 != 0)
    {
      result *= factor;
      exponent += zerodir;
    }
    else
    {
      factor *= factor;
      exponent /= 2;
    }
  }
  return result;
}

Go: package main

import (
    "errors"
    "fmt"
)

func expI(b, p int) (int, error) {
    if p < 0 {
        return 0, errors.New("negative power not allowed")
    }
    r := 1
    for i := 1; i <= p; i++ {
        r *= b
    }
    return r, nil
}

func expF(b float32, p int) float32 {
    var neg bool
    if p < 0 {
        neg = true
        p = -p
    }
    r := float32(1)
    for pow := b; p > 0; pow *= pow {
        if p&1 == 1 {
            r *= pow
        }
        p >>= 1
    }
    if neg {
        r = 1 / r
    }
    return r
}

func main() {
    ti := func(b, p int) {
        fmt.Printf("%d^%d: ", b, p)
        e, err := expI(b, p)
        if err != nil {
            fmt.Println(err)
        } else {
            fmt.Println(e)
        }
    }

    fmt.Println("expI tests")
    ti(2, 10)
    ti(2, -10)
    ti(-2, 10)
    ti(-2, 11)
    ti(11, 0)

    fmt.Println("overflow undetected")
    ti(10, 10)

    tf := func(b float32, p int) {
        fmt.Printf("%g^%d: %g\n", b, p, expF(b, p))
    }

    fmt.Println("\nexpF tests:")
    tf(2, 10)
    tf(2, -10)
    tf(-2, 10)
    tf(-2, 11)
    tf(11, 0)

    fmt.Println("disallowed in expI, allowed here")
    tf(0, -1)

    fmt.Println("other interesting cases for 32 bit float type")
    tf(10, 39)
    tf(10, -39)
    tf(-10, 39)
}
Task: Exponentiation operator
C++: template<typename Number>
 Number power(Number base, int exponent)
{
  int zerodir;
  Number factor;
  if (exponent < 0)
  {
    zerodir = 1;
    factor = Number(1)/base;
  }
  else
  {
    zerodir = -1;
    factor = base;
  }

  Number result(1);
  while (exponent != 0)
  {
    if (exponent % 2 != 0)
    {
      result *= factor;
      exponent += zerodir;
    }
    else
    {
      factor *= factor;
      exponent /= 2;
    }
  }
  return result;
}

Python: MULTIPLY = lambda x, y: x*y

class num(float):
    
    
    def __pow__(self, b):
        return reduce(MULTIPLY, [self]*b, 1)


print num(2).__pow__(3)
print num(2) ** 3


print num(2.3).__pow__(8)
print num(2.3) ** 8
Task: Exponentiation operator
C++: template<typename Number>
 Number power(Number base, int exponent)
{
  int zerodir;
  Number factor;
  if (exponent < 0)
  {
    zerodir = 1;
    factor = Number(1)/base;
  }
  else
  {
    zerodir = -1;
    factor = base;
  }

  Number result(1);
  while (exponent != 0)
  {
    if (exponent % 2 != 0)
    {
      result *= factor;
      exponent += zerodir;
    }
    else
    {
      factor *= factor;
      exponent /= 2;
    }
  }
  return result;
}

VB: Public Function exp(ByVal base As Variant, ByVal exponent As Long) As Variant
    Dim result As Variant
    If TypeName(base) = "Integer" Or TypeName(base) = "Long" Then
        
        result = 1
        If exponent < 0 Then
            result = IIf(Abs(base) <> 1, CVErr(2019), IIf(exponent Mod 2 = -1, base, 1))
        End If
        Do While exponent > 0
            If exponent Mod 2 = 1 Then result = result * base
            base = base * base
            exponent = exponent \ 2
        Loop
    Else
        Debug.Assert IsNumeric(base)
        
        If base = 0 Then
            If exponent < 0 Then result = CVErr(11)
        Else
            If exponent < 0 Then
                base = 1# / base
                exponent = -exponent
            End If
            result = 1
            Do While exponent > 0
                If exponent Mod 2 = 1 Then result = result * base
                base = base * base
                exponent = exponent \ 2
            Loop
        End If
    End If
    exp = result
End Function
Public Sub main()
    Debug.Print "Integer exponentiation"
    Debug.Print "10^7=", exp(10, 7)
    Debug.Print "10^4=", exp(10, 4)
    Debug.Print "(-3)^3=", exp(-3, 3)
    Debug.Print "(-1)^(-5)=", exp(-1, -5)
    Debug.Print "10^(-1)=", exp(10, -1)
    Debug.Print "0^2=", exp(0, 2)
    Debug.Print "Float exponentiation"
    Debug.Print "10.0^(-3)=", exp(10#, -3)
    Debug.Print "10.0^(-4)=", exp(10#, -4)
    Debug.Print "(-3.0)^(-5)=", exp(-3#, -5)
    Debug.Print "(-3.0)^(-4)=", exp(-3#, -4)
    Debug.Print "0.0^(-4)=", exp(0#, -4)
End Sub
Task: Exponentiation operator
C#: static void Main(string[] args)
{
	Console.WriteLine("5^5 = " + Expon(5, 5));
	Console.WriteLine("5.5^5 = " + Expon(5.5, 5));
	Console.ReadLine();
}

static double Expon(int Val, int Pow) 
{
	return Math.Pow(Val, Pow);
}
static double Expon(double Val, int Pow)
{
	return Math.Pow(Val, Pow);
}

Go: package main

import (
    "errors"
    "fmt"
)

func expI(b, p int) (int, error) {
    if p < 0 {
        return 0, errors.New("negative power not allowed")
    }
    r := 1
    for i := 1; i <= p; i++ {
        r *= b
    }
    return r, nil
}

func expF(b float32, p int) float32 {
    var neg bool
    if p < 0 {
        neg = true
        p = -p
    }
    r := float32(1)
    for pow := b; p > 0; pow *= pow {
        if p&1 == 1 {
            r *= pow
        }
        p >>= 1
    }
    if neg {
        r = 1 / r
    }
    return r
}

func main() {
    ti := func(b, p int) {
        fmt.Printf("%d^%d: ", b, p)
        e, err := expI(b, p)
        if err != nil {
            fmt.Println(err)
        } else {
            fmt.Println(e)
        }
    }

    fmt.Println("expI tests")
    ti(2, 10)
    ti(2, -10)
    ti(-2, 10)
    ti(-2, 11)
    ti(11, 0)

    fmt.Println("overflow undetected")
    ti(10, 10)

    tf := func(b float32, p int) {
        fmt.Printf("%g^%d: %g\n", b, p, expF(b, p))
    }

    fmt.Println("\nexpF tests:")
    tf(2, 10)
    tf(2, -10)
    tf(-2, 10)
    tf(-2, 11)
    tf(11, 0)

    fmt.Println("disallowed in expI, allowed here")
    tf(0, -1)

    fmt.Println("other interesting cases for 32 bit float type")
    tf(10, 39)
    tf(10, -39)
    tf(-10, 39)
}
Task: Exponentiation operator
C#: static void Main(string[] args)
{
	Console.WriteLine("5^5 = " + Expon(5, 5));
	Console.WriteLine("5.5^5 = " + Expon(5.5, 5));
	Console.ReadLine();
}

static double Expon(int Val, int Pow) 
{
	return Math.Pow(Val, Pow);
}
static double Expon(double Val, int Pow)
{
	return Math.Pow(Val, Pow);
}

Python: MULTIPLY = lambda x, y: x*y

class num(float):
    
    
    def __pow__(self, b):
        return reduce(MULTIPLY, [self]*b, 1)


print num(2).__pow__(3)
print num(2) ** 3


print num(2.3).__pow__(8)
print num(2.3) ** 8
Task: Exponentiation operator
C#: static void Main(string[] args)
{
	Console.WriteLine("5^5 = " + Expon(5, 5));
	Console.WriteLine("5.5^5 = " + Expon(5.5, 5));
	Console.ReadLine();
}

static double Expon(int Val, int Pow) 
{
	return Math.Pow(Val, Pow);
}
static double Expon(double Val, int Pow)
{
	return Math.Pow(Val, Pow);
}

VB: Public Function exp(ByVal base As Variant, ByVal exponent As Long) As Variant
    Dim result As Variant
    If TypeName(base) = "Integer" Or TypeName(base) = "Long" Then
        
        result = 1
        If exponent < 0 Then
            result = IIf(Abs(base) <> 1, CVErr(2019), IIf(exponent Mod 2 = -1, base, 1))
        End If
        Do While exponent > 0
            If exponent Mod 2 = 1 Then result = result * base
            base = base * base
            exponent = exponent \ 2
        Loop
    Else
        Debug.Assert IsNumeric(base)
        
        If base = 0 Then
            If exponent < 0 Then result = CVErr(11)
        Else
            If exponent < 0 Then
                base = 1# / base
                exponent = -exponent
            End If
            result = 1
            Do While exponent > 0
                If exponent Mod 2 = 1 Then result = result * base
                base = base * base
                exponent = exponent \ 2
            Loop
        End If
    End If
    exp = result
End Function
Public Sub main()
    Debug.Print "Integer exponentiation"
    Debug.Print "10^7=", exp(10, 7)
    Debug.Print "10^4=", exp(10, 4)
    Debug.Print "(-3)^3=", exp(-3, 3)
    Debug.Print "(-1)^(-5)=", exp(-1, -5)
    Debug.Print "10^(-1)=", exp(10, -1)
    Debug.Print "0^2=", exp(0, 2)
    Debug.Print "Float exponentiation"
    Debug.Print "10.0^(-3)=", exp(10#, -3)
    Debug.Print "10.0^(-4)=", exp(10#, -4)
    Debug.Print "(-3.0)^(-5)=", exp(-3#, -5)
    Debug.Print "(-3.0)^(-4)=", exp(-3#, -4)
    Debug.Print "0.0^(-4)=", exp(0#, -4)
End Sub
Task: Exponentiation operator
Go: package main

import (
    "errors"
    "fmt"
)

func expI(b, p int) (int, error) {
    if p < 0 {
        return 0, errors.New("negative power not allowed")
    }
    r := 1
    for i := 1; i <= p; i++ {
        r *= b
    }
    return r, nil
}

func expF(b float32, p int) float32 {
    var neg bool
    if p < 0 {
        neg = true
        p = -p
    }
    r := float32(1)
    for pow := b; p > 0; pow *= pow {
        if p&1 == 1 {
            r *= pow
        }
        p >>= 1
    }
    if neg {
        r = 1 / r
    }
    return r
}

func main() {
    ti := func(b, p int) {
        fmt.Printf("%d^%d: ", b, p)
        e, err := expI(b, p)
        if err != nil {
            fmt.Println(err)
        } else {
            fmt.Println(e)
        }
    }

    fmt.Println("expI tests")
    ti(2, 10)
    ti(2, -10)
    ti(-2, 10)
    ti(-2, 11)
    ti(11, 0)

    fmt.Println("overflow undetected")
    ti(10, 10)

    tf := func(b float32, p int) {
        fmt.Printf("%g^%d: %g\n", b, p, expF(b, p))
    }

    fmt.Println("\nexpF tests:")
    tf(2, 10)
    tf(2, -10)
    tf(-2, 10)
    tf(-2, 11)
    tf(11, 0)

    fmt.Println("disallowed in expI, allowed here")
    tf(0, -1)

    fmt.Println("other interesting cases for 32 bit float type")
    tf(10, 39)
    tf(10, -39)
    tf(-10, 39)
}

Java: public class Exp{
   public static void main(String[] args){
      System.out.println(pow(2,30));
      System.out.println(pow(2.0,30)); 
      System.out.println(pow(2.0,-2));
   }

   public static double pow(double base, int exp){
      if(exp < 0) return 1 / pow(base, -exp);
      double ans = 1.0;
      for(;exp > 0;--exp) ans *= base;
      return ans;
   }
}
Task: Exponentiation operator
Java: public class Exp{
   public static void main(String[] args){
      System.out.println(pow(2,30));
      System.out.println(pow(2.0,30)); 
      System.out.println(pow(2.0,-2));
   }

   public static double pow(double base, int exp){
      if(exp < 0) return 1 / pow(base, -exp);
      double ans = 1.0;
      for(;exp > 0;--exp) ans *= base;
      return ans;
   }
}

Python: MULTIPLY = lambda x, y: x*y

class num(float):
    
    
    def __pow__(self, b):
        return reduce(MULTIPLY, [self]*b, 1)


print num(2).__pow__(3)
print num(2) ** 3


print num(2.3).__pow__(8)
print num(2.3) ** 8
Task: Exponentiation operator
Java: public class Exp{
   public static void main(String[] args){
      System.out.println(pow(2,30));
      System.out.println(pow(2.0,30)); 
      System.out.println(pow(2.0,-2));
   }

   public static double pow(double base, int exp){
      if(exp < 0) return 1 / pow(base, -exp);
      double ans = 1.0;
      for(;exp > 0;--exp) ans *= base;
      return ans;
   }
}

VB: Public Function exp(ByVal base As Variant, ByVal exponent As Long) As Variant
    Dim result As Variant
    If TypeName(base) = "Integer" Or TypeName(base) = "Long" Then
        
        result = 1
        If exponent < 0 Then
            result = IIf(Abs(base) <> 1, CVErr(2019), IIf(exponent Mod 2 = -1, base, 1))
        End If
        Do While exponent > 0
            If exponent Mod 2 = 1 Then result = result * base
            base = base * base
            exponent = exponent \ 2
        Loop
    Else
        Debug.Assert IsNumeric(base)
        
        If base = 0 Then
            If exponent < 0 Then result = CVErr(11)
        Else
            If exponent < 0 Then
                base = 1# / base
                exponent = -exponent
            End If
            result = 1
            Do While exponent > 0
                If exponent Mod 2 = 1 Then result = result * base
                base = base * base
                exponent = exponent \ 2
            Loop
        End If
    End If
    exp = result
End Function
Public Sub main()
    Debug.Print "Integer exponentiation"
    Debug.Print "10^7=", exp(10, 7)
    Debug.Print "10^4=", exp(10, 4)
    Debug.Print "(-3)^3=", exp(-3, 3)
    Debug.Print "(-1)^(-5)=", exp(-1, -5)
    Debug.Print "10^(-1)=", exp(10, -1)
    Debug.Print "0^2=", exp(0, 2)
    Debug.Print "Float exponentiation"
    Debug.Print "10.0^(-3)=", exp(10#, -3)
    Debug.Print "10.0^(-4)=", exp(10#, -4)
    Debug.Print "(-3.0)^(-5)=", exp(-3#, -5)
    Debug.Print "(-3.0)^(-4)=", exp(-3#, -4)
    Debug.Print "0.0^(-4)=", exp(0#, -4)
End Sub
Task: Exponentiation operator
Go: package main

import (
    "errors"
    "fmt"
)

func expI(b, p int) (int, error) {
    if p < 0 {
        return 0, errors.New("negative power not allowed")
    }
    r := 1
    for i := 1; i <= p; i++ {
        r *= b
    }
    return r, nil
}

func expF(b float32, p int) float32 {
    var neg bool
    if p < 0 {
        neg = true
        p = -p
    }
    r := float32(1)
    for pow := b; p > 0; pow *= pow {
        if p&1 == 1 {
            r *= pow
        }
        p >>= 1
    }
    if neg {
        r = 1 / r
    }
    return r
}

func main() {
    ti := func(b, p int) {
        fmt.Printf("%d^%d: ", b, p)
        e, err := expI(b, p)
        if err != nil {
            fmt.Println(err)
        } else {
            fmt.Println(e)
        }
    }

    fmt.Println("expI tests")
    ti(2, 10)
    ti(2, -10)
    ti(-2, 10)
    ti(-2, 11)
    ti(11, 0)

    fmt.Println("overflow undetected")
    ti(10, 10)

    tf := func(b float32, p int) {
        fmt.Printf("%g^%d: %g\n", b, p, expF(b, p))
    }

    fmt.Println("\nexpF tests:")
    tf(2, 10)
    tf(2, -10)
    tf(-2, 10)
    tf(-2, 11)
    tf(11, 0)

    fmt.Println("disallowed in expI, allowed here")
    tf(0, -1)

    fmt.Println("other interesting cases for 32 bit float type")
    tf(10, 39)
    tf(10, -39)
    tf(-10, 39)
}

VB: Public Function exp(ByVal base As Variant, ByVal exponent As Long) As Variant
    Dim result As Variant
    If TypeName(base) = "Integer" Or TypeName(base) = "Long" Then
        
        result = 1
        If exponent < 0 Then
            result = IIf(Abs(base) <> 1, CVErr(2019), IIf(exponent Mod 2 = -1, base, 1))
        End If
        Do While exponent > 0
            If exponent Mod 2 = 1 Then result = result * base
            base = base * base
            exponent = exponent \ 2
        Loop
    Else
        Debug.Assert IsNumeric(base)
        
        If base = 0 Then
            If exponent < 0 Then result = CVErr(11)
        Else
            If exponent < 0 Then
                base = 1# / base
                exponent = -exponent
            End If
            result = 1
            Do While exponent > 0
                If exponent Mod 2 = 1 Then result = result * base
                base = base * base
                exponent = exponent \ 2
            Loop
        End If
    End If
    exp = result
End Function
Public Sub main()
    Debug.Print "Integer exponentiation"
    Debug.Print "10^7=", exp(10, 7)
    Debug.Print "10^4=", exp(10, 4)
    Debug.Print "(-3)^3=", exp(-3, 3)
    Debug.Print "(-1)^(-5)=", exp(-1, -5)
    Debug.Print "10^(-1)=", exp(10, -1)
    Debug.Print "0^2=", exp(0, 2)
    Debug.Print "Float exponentiation"
    Debug.Print "10.0^(-3)=", exp(10#, -3)
    Debug.Print "10.0^(-4)=", exp(10#, -4)
    Debug.Print "(-3.0)^(-5)=", exp(-3#, -5)
    Debug.Print "(-3.0)^(-4)=", exp(-3#, -4)
    Debug.Print "0.0^(-4)=", exp(0#, -4)
End Sub
Task: Exponentiation operator
C: #include <stdio.h>
#include <assert.h>

int ipow(int base, int exp)
{
   int pow = base;
   int v = 1;
   if (exp < 0) {
      assert (base != 0);  
      return (base*base != 1)? 0: (exp&1)? base : 1;
   }
       
   while(exp > 0 )
   {
      if (exp & 1) v *= pow;
      pow *= pow;
      exp >>= 1;
    }
   return v;
}

double dpow(double base, int exp)
{
   double v=1.0;
   double pow = (exp <0)? 1.0/base : base;
   if (exp < 0) exp = - exp;

   while(exp > 0 )
   {
      if (exp & 1) v *= pow;
      pow *= pow;
      exp >>= 1;
   }
   return v;
}

int main()
{
    printf("2^6 = %d\n", ipow(2,6));
    printf("2^-6 = %d\n", ipow(2,-6));
    printf("2.71^6 = %lf\n", dpow(2.71,6));
    printf("2.71^-6 = %lf\n", dpow(2.71,-6));
}

VB: Public Function exp(ByVal base As Variant, ByVal exponent As Long) As Variant
    Dim result As Variant
    If TypeName(base) = "Integer" Or TypeName(base) = "Long" Then
        
        result = 1
        If exponent < 0 Then
            result = IIf(Abs(base) <> 1, CVErr(2019), IIf(exponent Mod 2 = -1, base, 1))
        End If
        Do While exponent > 0
            If exponent Mod 2 = 1 Then result = result * base
            base = base * base
            exponent = exponent \ 2
        Loop
    Else
        Debug.Assert IsNumeric(base)
        
        If base = 0 Then
            If exponent < 0 Then result = CVErr(11)
        Else
            If exponent < 0 Then
                base = 1# / base
                exponent = -exponent
            End If
            result = 1
            Do While exponent > 0
                If exponent Mod 2 = 1 Then result = result * base
                base = base * base
                exponent = exponent \ 2
            Loop
        End If
    End If
    exp = result
End Function
Public Sub main()
    Debug.Print "Integer exponentiation"
    Debug.Print "10^7=", exp(10, 7)
    Debug.Print "10^4=", exp(10, 4)
    Debug.Print "(-3)^3=", exp(-3, 3)
    Debug.Print "(-1)^(-5)=", exp(-1, -5)
    Debug.Print "10^(-1)=", exp(10, -1)
    Debug.Print "0^2=", exp(0, 2)
    Debug.Print "Float exponentiation"
    Debug.Print "10.0^(-3)=", exp(10#, -3)
    Debug.Print "10.0^(-4)=", exp(10#, -4)
    Debug.Print "(-3.0)^(-5)=", exp(-3#, -5)
    Debug.Print "(-3.0)^(-4)=", exp(-3#, -4)
    Debug.Print "0.0^(-4)=", exp(0#, -4)
End Sub
Task: Exponentiation operator
C++: template<typename Number>
 Number power(Number base, int exponent)
{
  int zerodir;
  Number factor;
  if (exponent < 0)
  {
    zerodir = 1;
    factor = Number(1)/base;
  }
  else
  {
    zerodir = -1;
    factor = base;
  }

  Number result(1);
  while (exponent != 0)
  {
    if (exponent % 2 != 0)
    {
      result *= factor;
      exponent += zerodir;
    }
    else
    {
      factor *= factor;
      exponent /= 2;
    }
  }
  return result;
}

Java: public class Exp{
   public static void main(String[] args){
      System.out.println(pow(2,30));
      System.out.println(pow(2.0,30)); 
      System.out.println(pow(2.0,-2));
   }

   public static double pow(double base, int exp){
      if(exp < 0) return 1 / pow(base, -exp);
      double ans = 1.0;
      for(;exp > 0;--exp) ans *= base;
      return ans;
   }
}
Task: Exponentiation operator
C#: static void Main(string[] args)
{
	Console.WriteLine("5^5 = " + Expon(5, 5));
	Console.WriteLine("5.5^5 = " + Expon(5.5, 5));
	Console.ReadLine();
}

static double Expon(int Val, int Pow) 
{
	return Math.Pow(Val, Pow);
}
static double Expon(double Val, int Pow)
{
	return Math.Pow(Val, Pow);
}

Java: public class Exp{
   public static void main(String[] args){
      System.out.println(pow(2,30));
      System.out.println(pow(2.0,30)); 
      System.out.println(pow(2.0,-2));
   }

   public static double pow(double base, int exp){
      if(exp < 0) return 1 / pow(base, -exp);
      double ans = 1.0;
      for(;exp > 0;--exp) ans *= base;
      return ans;
   }
}
Task: Exponentiation operator
Go: package main

import (
    "errors"
    "fmt"
)

func expI(b, p int) (int, error) {
    if p < 0 {
        return 0, errors.New("negative power not allowed")
    }
    r := 1
    for i := 1; i <= p; i++ {
        r *= b
    }
    return r, nil
}

func expF(b float32, p int) float32 {
    var neg bool
    if p < 0 {
        neg = true
        p = -p
    }
    r := float32(1)
    for pow := b; p > 0; pow *= pow {
        if p&1 == 1 {
            r *= pow
        }
        p >>= 1
    }
    if neg {
        r = 1 / r
    }
    return r
}

func main() {
    ti := func(b, p int) {
        fmt.Printf("%d^%d: ", b, p)
        e, err := expI(b, p)
        if err != nil {
            fmt.Println(err)
        } else {
            fmt.Println(e)
        }
    }

    fmt.Println("expI tests")
    ti(2, 10)
    ti(2, -10)
    ti(-2, 10)
    ti(-2, 11)
    ti(11, 0)

    fmt.Println("overflow undetected")
    ti(10, 10)

    tf := func(b float32, p int) {
        fmt.Printf("%g^%d: %g\n", b, p, expF(b, p))
    }

    fmt.Println("\nexpF tests:")
    tf(2, 10)
    tf(2, -10)
    tf(-2, 10)
    tf(-2, 11)
    tf(11, 0)

    fmt.Println("disallowed in expI, allowed here")
    tf(0, -1)

    fmt.Println("other interesting cases for 32 bit float type")
    tf(10, 39)
    tf(10, -39)
    tf(-10, 39)
}

Python: MULTIPLY = lambda x, y: x*y

class num(float):
    
    
    def __pow__(self, b):
        return reduce(MULTIPLY, [self]*b, 1)


print num(2).__pow__(3)
print num(2) ** 3


print num(2.3).__pow__(8)
print num(2.3) ** 8
Task: Exponentiation operator
C: #include <stdio.h>
#include <assert.h>

int ipow(int base, int exp)
{
   int pow = base;
   int v = 1;
   if (exp < 0) {
      assert (base != 0);  
      return (base*base != 1)? 0: (exp&1)? base : 1;
   }
       
   while(exp > 0 )
   {
      if (exp & 1) v *= pow;
      pow *= pow;
      exp >>= 1;
    }
   return v;
}

double dpow(double base, int exp)
{
   double v=1.0;
   double pow = (exp <0)? 1.0/base : base;
   if (exp < 0) exp = - exp;

   while(exp > 0 )
   {
      if (exp & 1) v *= pow;
      pow *= pow;
      exp >>= 1;
   }
   return v;
}

int main()
{
    printf("2^6 = %d\n", ipow(2,6));
    printf("2^-6 = %d\n", ipow(2,-6));
    printf("2.71^6 = %lf\n", dpow(2.71,6));
    printf("2.71^-6 = %lf\n", dpow(2.71,-6));
}

Java: public class Exp{
   public static void main(String[] args){
      System.out.println(pow(2,30));
      System.out.println(pow(2.0,30)); 
      System.out.println(pow(2.0,-2));
   }

   public static double pow(double base, int exp){
      if(exp < 0) return 1 / pow(base, -exp);
      double ans = 1.0;
      for(;exp > 0;--exp) ans *= base;
      return ans;
   }
}
Task: Exponentiation operator
C: #include <stdio.h>
#include <assert.h>

int ipow(int base, int exp)
{
   int pow = base;
   int v = 1;
   if (exp < 0) {
      assert (base != 0);  
      return (base*base != 1)? 0: (exp&1)? base : 1;
   }
       
   while(exp > 0 )
   {
      if (exp & 1) v *= pow;
      pow *= pow;
      exp >>= 1;
    }
   return v;
}

double dpow(double base, int exp)
{
   double v=1.0;
   double pow = (exp <0)? 1.0/base : base;
   if (exp < 0) exp = - exp;

   while(exp > 0 )
   {
      if (exp & 1) v *= pow;
      pow *= pow;
      exp >>= 1;
   }
   return v;
}

int main()
{
    printf("2^6 = %d\n", ipow(2,6));
    printf("2^-6 = %d\n", ipow(2,-6));
    printf("2.71^6 = %lf\n", dpow(2.71,6));
    printf("2.71^-6 = %lf\n", dpow(2.71,-6));
}

Python: MULTIPLY = lambda x, y: x*y

class num(float):
    
    
    def __pow__(self, b):
        return reduce(MULTIPLY, [self]*b, 1)


print num(2).__pow__(3)
print num(2) ** 3


print num(2.3).__pow__(8)
print num(2.3) ** 8