/// <summary> /// Returns a specified number raised to the specified power. Saturates /// </summary> /// <exception cref="DivideByZeroException"> /// The base was zero, with a negative exponent /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// The base was negative, with a non-zero exponent /// </exception> public static Fix32 Pow(this Fix32 b, Fix32 exp) { #if USE_DOUBLES return(Math.Pow(b.ToDouble(), exp.ToDouble()).ToFix32()); #endif if ((int)b == (int)Fix32.One) { return(Fix32.One); } if ((int)exp == 0) { return(Fix32.One); } if ((int)b == 0) { if ((int)exp < 0) { throw new DivideByZeroException(); } return(Fix32.Zero); } if (b < 0 && exp != 0) { throw new ArgumentOutOfRangeException("Non-positive value passed to Ln", "x"); } return(exp.Mul(b.Log2()).Pow2()); }