public static Primitive.EventloopEntry Readline(Fun2 <Exception, string, Unit> cb) { return(Primitive.RunBlocking <string>( () => { return Console.In.ReadLine(); }, (Exception exn, string result) => { cb.Apply(exn, result); } )); }
/// <summary> /// Метод, выводящий таблицу значений функции в промежутке от х1 до х2. /// </summary> /// <param name="F">Функция, принимающая два аргумента типа double и возвращающая значение double</param> /// <param name="a">Константа типа "double"</param> /// <param name="x1">Значение, начиная с которого будет выводиться таблица</param> /// <param name="x2">Значение, до которого будет выводиться таблица</param> public static void Table(Fun2 F, double a, double x1, double x2) { Console.WriteLine("----- X ----- Y -----"); while (x1 <= x2) { Console.WriteLine("| {0,8:0.000} | {1,8:0.000} |", x1, F?.Invoke(a, x1) /*F(a)*/); x1 += 1; } Console.WriteLine("---------------------"); }
public static void Table(Fun2 F, double x, double y, double b) { Console.WriteLine("----- X ----- Y -----"); while (x <= b) { Console.WriteLine("| {0,8:0.000} | {1,8:0.000} |", x, y); x += 1; } Console.WriteLine("---------------------"); }
public static void Table(Fun2 J, double x, double b, double a) { Console.WriteLine("----- X ----- Y -----"); while (x <= b) { Console.WriteLine("| {0,8:0.000} | {1,8:0.000} |", x, J(a, x)); x += 1; } Console.WriteLine("---------------------"); }
public static void Table2(Fun2 F2, double start, double finish, double h) { Console.WriteLine("----- X ----- Y -----"); while (start <= finish) { Console.WriteLine("| {0,8:0.000} | {1,8:0.000} |", start, F2(start, h) /*F(a)*/); start += h; } Console.WriteLine("---------------------"); Console.ReadLine(); }
public static void Table(Fun2 F, double x, double a, double b) { Console.WriteLine("----- X ----- Y -----"); Console.WriteLine($"a = {a}"); while (x <= b) { Console.WriteLine("| {0,8:0.000} | {1,8:0.000} |", x, F(x, a)); x += 1; } Console.WriteLine("---------------------"); }
public static void SaveFunc(Fun2 function, string fileName, double a, double b, double h) { FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs); double x = a; while (x <= b) { bw.Write(MyFunc(x)); x += h;// x=x+h; } bw.Close(); fs.Close(); }
static void Main(string[] args) { Fun2 ax2 = new Fun2(MyFuncAX2); double a = 2; double x1 = -5; double x2 = 5; Console.WriteLine($"Таблца для y = {a}*x^2 для значений, x принадлежит от {x1} до {x2}"); Table(ax2, a, x1, x2); Console.WriteLine("---------------------"); Fun2 aSinX = new Fun2(MyFuncASin); Console.WriteLine($"Таблца для y = {a}*sin(x) для значений, x принадлежит от {x1} до {x2}"); Table(aSinX, a, x1, x2); }
public static EventloopEntry RunBlockingPrim <A>(Fun0 <A> blockingAction, Fun2 <Exception, A, Unit> onSuccess) { EventloopEntry entry = GetEventloopEntry(); ThreadPool.QueueUserWorkItem((object info) => { Exception exception = null; A result = default(A); try { result = blockingAction.Call(); } catch (Exception exn) { exception = exn; } entry.Post(() => { onSuccess.Call(exception, result); }); }); return(entry); }
public static void Table2(Fun2 F, double a, double x, double b, double h) { Console.WriteLine("----- A ----- X ----- Y -----"); while (a <= b) { Console.WriteLine("| {0,8:0.000} | {1,8:0.000} | {2,8:0.000} ", a, x, F?.Invoke(a, x)); double x1 = x + h; while (x1 <= b) { Console.WriteLine("| {0,8:0.000} | {1,8:0.000} | {2,8:0.000} ", a, x1, F?.Invoke(a, x1)); x1 += h; } a += h; } Console.WriteLine("-----------------------------"); }
public _DownloadText(string uri, double timeout, Fun2 <Exception, string, Unit> cb) { entry = Primitive.GetEventloopEntry(); webClient = new System.Net.WebClient(); try { webClient.DownloadStringCompleted += (object sender, System.Net.DownloadStringCompletedEventArgs e) => { if (entry != null) { entry.Post(() => cb.Call(e.Error, (e.Error != null ? "" : e.Result))); entry = null; } Dispose(); }; webClient.DownloadStringAsync(new Uri(uri)); } catch (Exception exn) { Dispose(); throw exn; } }
public static void Task1() { int a = 4; int b = 2; Fun fun = new Fun(Math.Atan); Table(fun, a, b, 1); Table(new Fun(Math.Atan), -4, 4, 1); Table(null, -4, 4, 1); //Создаем новый делегат и передаем ссылку на него в метод Table. Console.WriteLine("Таблица функции MyFunc:"); Table(new Fun(MyFunc), -2, 2, 1); //Параметры функции и тип возвращаемого значения, должны совпадать с делегатом Console.WriteLine("Еще раз та же таблица, но вызов организован по новому"); Table(MyFunc, -2, 2, 1); //Упрощение(c C# 2.0). Делегат создается автоматически. Console.WriteLine("Таблица функции Sin:"); Table(Math.Sin, -2, 2, 1); //Можно передавать уже созданные функции Console.WriteLine("Таблица функции x^2:"); //Упрощение(с C# 2.0). Использование анонимного метода Fun2 am = delegate(double x, double y) { return(x * y); }; Table( delegate(double x) { return(x * x); }, 0, 3, 0.5); Table( x => x * x, 0, 3, 0.5 ); Console.WriteLine("y=a*x^2"); Table2(FuncAX2, 1, 1, 4, 1); Console.WriteLine("y=a*sin(x)"); Table2(FuncASinX, 1, 1, 4, 1); Console.ReadKey(); }
public static B Call <A1, A2, B>(this Fun2 <A1, A2, B> f, A1 x1, A2 x2) { return((B)f.Apply(x1, x2)); }
public static Primitive.EventloopEntry ReadTextFile(string path, Fun2 <Exception, string, Unit> cb) { return(Primitive.RunBlocking <string>(() => File.ReadAllText(path, Encoding.UTF8), cb)); }
public static Primitive.EventloopEntry GetModTime(string path, Fun2 <Exception, double, Unit> cb) { return(Primitive.RunBlocking <double>(() => File.GetLastWriteTimeUtc(path).ToUnixSeconds(), cb)); }
private void CalAndPush(Fun2 fun) { IConstant arg2 = core.PopOperand(); IConstant arg1 = core.PopOperand(); core.PushOperand(fun.Invoke(arg1, arg2)); }
public static void SaveFunc(string fileName, double startPoint, double endPoint, double step, Fun2 f) { FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs); double x = startPoint; while (x <= endPoint) { bw.Write(f(x)); x += step; } bw.Close(); fs.Close(); }
public static EventloopEntry RunBlocking <A>(Func <A> blockingAction, Fun2 <Exception, A, Unit> onSuccess) { return(RunBlockingPrim <A>(new FunFunc0 <A>(blockingAction), onSuccess)); }
public static _DownloadText DownloadText(string uri, double timeout, Fun2 <Exception, string, Unit> cb) { return(new _DownloadText(uri, timeout, cb)); }