internal static bool TryPulling(TrigTable table, ComplexNumber arg, out Entity res) { if (arg.IsImaginary()) { res = null; return(false); } // arg in [0; 2pi] var dArg = arg.Real.Value; EDecimal Remainder(EDecimal a, EDecimal divisor) => a.RemainderNoRoundAfterDivide(divisor, MathS.Settings.DecimalPrecisionContext); var twoPi = RealNumber.CtxMultiply(2, MathS.DecimalConst.pi); dArg = Remainder( RealNumber.CtxAdd( // ( Remainder(dArg // dArg , // % twoPi) // 2pi , // + twoPi // 2pi ) // ) , // % twoPi // 2pi ); int begin = 0; int end = table.Count - 1; while (end - begin > 1) { var mid = (end + begin) / 2; if (EDecimalWrapper.IsGreater(table[mid].arg, dArg)) { begin = mid; } else { end = mid; } if (end >= table.Count) { res = null; return(false); } } for (var j = begin; j <= end; j++) { if (Number.Functional.IsZero(table[j].arg - dArg)) { res = table[j].res; return(true); } } res = null; return(false); }
/// <summary> /// Transforms a floating number, but this number should be in [0; 1] /// </summary> /// <param name="num"></param> /// <param name="N"></param> /// <returns></returns> internal static string FloatToBaseN(EDecimal num /*should be < 1*/, int N) { if (EDecimalWrapper.IsGreater(num, 1) || EDecimalWrapper.IsLess(num, 0)) { throw new SysException("Error in FloatToBaseN"); } string res = ""; while (EDecimalWrapper.IsGreater(num, 0)) { num = RealNumber.CtxMultiply(num, N); EInteger intPart = num.RoundToIntegerExact(FloorContext).ToEInteger(); res += ALPHABET_TOCHAR[intPart.ToInt32Checked()]; num -= intPart; } return(res); }
private static EDecimal PiOver(int a) => RealNumber.CtxDivide(RealNumber.CtxMultiply(2, MathS.DecimalConst.pi), a);