1
Vote

Pow (exponentiation)

description

C#:

I tried to add a small section for exponentiation (and an operator "**"), but the compiler just vomited all over.

Code tried:

[Starting as line #2109]
2109 #region Exponentiation
2110 /// Custom code by me
... public static BigInteger operator ** (BigInteger leftSide, BigInteger rightSide) {
        if (object.ReferenceEquals(leftSide, null)) { throw new ArgumentNullException("leftSide"); }
        if (object.ReferenceEquals(rightSide, null)) { throw new ArgumentNullException("rightSide"); }

        BigInteger TEMP = 1;
        for ( long i = 1 ; i <= rightSide ; i++ )  { TEMP = TEMP * leftSide; }
        BigInteger result = new BigInteger(TEMP);
        return result;
    }

    /// <summary>
    /// Exponentiate two BigIntegers returning the result.
    /// </summary>
    /// <param name="leftSide">A BigInteger.</param>
    /// <param name="rightSide">A BigInteger</param>
    /// <returns></returns>
    public static BigInteger Pow(BigInteger leftSide, BigInteger rightSide) {
        return leftSide ** rightSide;
    }
    #endregion

    #region Bitwise Operator Overloads
Compiler results:

[2017-04-08 19:26:29.28] c:\code\C#\Float>csc /out:_float.exe float.cs
Running with options: /NOLOGO
float.cs(2111,38): error CS1003: Syntax error, '(' expected
float.cs(2111,37): error CS1019: Overloadable unary operator expected
float.cs(2111,73): error CS1044: Cannot use more than one type in a for, using, fixed, or
    declaration statement
float.cs(2111,82): error CS1002: ; expected
float.cs(2112,14): error CS1519: Invalid token '.' in class, struct, or interface member
    declaration
float.cs(2112,15): error CS1520: Method must have a return type
float.cs(2112,39): error CS1001: Identifier expected
float.cs(2112,41): error CS1031: Type expected
float.cs(2112,60): error CS1520: Method must have a return type
float.cs(2112,82): error CS1031: Type expected
float.cs(2113,4): error CS0116: A namespace cannot directly contain members such as fields
    or methods
float.cs(2113,61): error CS1518: Expected class, delegate, enum, interface, or struct
float.cs(2115,4): error CS0116: A namespace cannot directly contain members such as fields
    or methods
float.cs(2117,28): error CS1518: Expected class, delegate, enum, interface, or struct
float.cs(2119,3): error CS1022: Type or namespace definition, or end-of-file expected

Now, I am new to C# and this project is ambitious for first-time C# coder, but the rest of my code works fine (calculating various parameters for different floating-point word sizes).

Help please?

comments

garakuta wrote Apr 9 at 3:52 AM

Forgot to mention, rather importantly):

Using framework 4.5 (I believe 4.5.2), however, it doesn't properly accept "system.numbers" to I had to find a manual version of BIGINTEGER to use. Link to code:

https://biginteger.codeplex.com/releases/view/16762