Logo

Programming-Idioms

  • PHP
  • D
  • C#
  • Vb
Function Square(x As Integer) As Integer
    Return x * x
End Function
Function Square(x As Integer) As Double
    Return x ^ 2
End Function

The exponentiation operator is compiled as a Math.Pow() call for numeric types.
declare(strict_types=1);
function square(int $x): int
{
    return $x * $x;
}

// square(4) -> 16
// square(3.4) -> Uncaught TypeError: Argument 1 passed to square() must be of the type int, float given
alias fun = (in a){return a * a;};

Using a delegate literal.
int square(int x) {
   return x*x;
}
void Square(ref int x)
{
    x = x * x;
}

The ref keyword indicates that a value is passed by reference.
To use this function you gonna need to type ref before your value
int Square(int x)
{
    return x * x;
}
double Square(int value) => System.Math.Pow(value, 2);

Math.Pow returns a double.
By default, this method will be private.
int Square(int x) => (int)Math.Pow(x, 2);
function Square (X : Integer) return Integer is
begin
   return X * X;
end Square;

New implementation...
< >
programming-idioms.org