/// <summary> /// b^x를 반환함 /// </summary> /// <param name="b">b ≥ 0인 배정밀도 부동 소수점 숫자</param> /// <param name="x"></param> /// <returns></returns> public static double Power(double b, double x) { if (b == 1 || x == 0) { return(1); } if (b < 0) { return(Double.NaN); } if (x == 1) { return(b); } double res = 1; int a = (int)Math.Round(x); double p = 1; double r = (x - a) * Logarithm.Log(b); for (int n = 1; n <= Factorial.Expanded; ++n) { p *= r; res += p * Factorial.Get(n); } return(IntPow(b, a) * res); }
private static double T2(double x) { double res = 0; double r = x * x; double cur = x; for (int i = 1; i <= Factorial.Expanded; i += 2) { if (i != 1) { cur *= r; } res += ((i - 1) % 4 == 0 ? 1 : -1) * cur * Factorial.Get(i); } return(res); }
private static double T1(double x) { double res = 0; double r = (x + Math.PI * 0.5) * (x + Math.PI * 0.5); double cur = 1; for (int i = 0; i <= Factorial.Expanded; i += 2) { if (i != 0) { cur *= r; } res += (i % 4 == 0 ? -1 : 1) * cur * Factorial.Get(i); } return(res); }
/// <summary> /// <see cref="Math.E"/>^x를 반환함 /// </summary> /// <returns></returns> public static double Exp(double x) { if (x == 0) { return(1); } if (x == 1) { return(Math.E); } double res = 1; int a = (int)Math.Round(x); double p = 1; double r = x - a; for (int n = 1; n <= Factorial.Expanded; ++n) { p *= r; res += p * Factorial.Get(n); } return(IntPow(Math.E, a) * res); }