diff --git a/csharp/Platform.Numbers/MathHelpers[T].cs b/csharp/Platform.Numbers/MathHelpers[T].cs
new file mode 100644
index 0000000..b6124d8
--- /dev/null
+++ b/csharp/Platform.Numbers/MathHelpers[T].cs
@@ -0,0 +1,212 @@
+using System;
+using System.Numerics;
+using System.Reflection;
+using System.Reflection.Emit;
+using Platform.Reflection;
+
+// ReSharper disable StaticFieldInGenericType
+
+namespace Platform.Numbers
+{
+ ///
+ /// Represents a set of compiled math operations using object methods instead of delegates.
+ /// Представляет набор скомпилированных математических операций, используя методы объекта вместо делегатов.
+ ///
+ ///
+ /// This implementation uses compiled object methods instead of delegates for better compiler optimization.
+ /// Эта реализация использует скомпилированные методы объекта вместо делегатов для лучшей оптимизации компилятора.
+ ///
+ public static class MathHelpers
+ where T : INumberBase
+ {
+ ///
+ /// Compiled math operations instance.
+ /// Экземпляр скомпилированных математических операций.
+ ///
+ public static readonly IMathOperations Operations;
+
+ static MathHelpers()
+ {
+ Operations = CompileOperationsClass();
+ }
+
+ private static IMathOperations CompileOperationsClass()
+ {
+ // Create a dynamic assembly and module for this specific type T
+ var assemblyName = new AssemblyName($"MathOperations_{typeof(T).Name}_{Guid.NewGuid():N}");
+ var assembly = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
+ var module = assembly.DefineDynamicModule("MathOperationsModule");
+
+ // Create a concrete type that implements IMathOperations
+ var typeBuilder = module.DefineType(
+ $"MathOperations_{typeof(T).Name}",
+ TypeAttributes.Public | TypeAttributes.Class,
+ typeof(object),
+ new[] { typeof(IMathOperations) });
+
+ // Create the Abs method using IL generation
+ CreateAbsMethod(typeBuilder);
+
+ // Create the Negate method using IL generation
+ CreateNegateMethod(typeBuilder);
+
+ // Compile the type and instantiate it
+ var compiledType = typeBuilder.CreateType()!;
+ return (IMathOperations)Activator.CreateInstance(compiledType)!;
+ }
+
+ private static void CreateAbsMethod(TypeBuilder typeBuilder)
+ {
+ var methodBuilder = typeBuilder.DefineMethod(
+ "Abs",
+ MethodAttributes.Public | MethodAttributes.Virtual,
+ typeof(T),
+ new[] { typeof(T) });
+
+ var il = methodBuilder.GetILGenerator();
+
+ // Try to find and use Math.Abs for this specific type
+ var mathAbsMethod = typeof(Math).GetMethod("Abs", new[] { typeof(T) });
+ if (mathAbsMethod != null)
+ {
+ il.Emit(OpCodes.Ldarg_1); // Load the argument
+ il.Emit(OpCodes.Call, mathAbsMethod);
+ }
+ else
+ {
+ // For types without Math.Abs support, implement manually
+ var typeInfo = typeof(T);
+ var isSignedType = typeInfo == typeof(sbyte) || typeInfo == typeof(short) ||
+ typeInfo == typeof(int) || typeInfo == typeof(long) ||
+ typeInfo == typeof(float) || typeInfo == typeof(double) ||
+ typeInfo == typeof(decimal);
+
+ if (isSignedType)
+ {
+ // Implement: value < 0 ? -value : value
+ var positiveLabel = il.DefineLabel();
+ var endLabel = il.DefineLabel();
+
+ il.Emit(OpCodes.Ldarg_1); // Load value for comparison
+ il.Emit(OpCodes.Ldc_I4_0); // Load 0 (works for integer types)
+
+ if (typeInfo == typeof(float) || typeInfo == typeof(double))
+ {
+ il.Emit(OpCodes.Pop); // Remove the int 0
+ if (typeInfo == typeof(float))
+ {
+ il.Emit(OpCodes.Ldc_R4, 0.0f); // Load 0.0f
+ }
+ else
+ {
+ il.Emit(OpCodes.Ldc_R8, 0.0d); // Load 0.0d
+ }
+ il.Emit(OpCodes.Clt); // Compare: value < 0
+ }
+ else if (typeInfo == typeof(long))
+ {
+ il.Emit(OpCodes.Pop); // Remove the int 0
+ il.Emit(OpCodes.Ldc_I8, 0L); // Load 0L
+ il.Emit(OpCodes.Clt); // Compare: value < 0
+ }
+ else
+ {
+ il.Emit(OpCodes.Clt); // Compare: value < 0 (for int, short, sbyte)
+ }
+
+ il.Emit(OpCodes.Brfalse_S, positiveLabel); // If value >= 0, go to positive label
+
+ // value < 0, return -value
+ il.Emit(OpCodes.Ldarg_1);
+ il.Emit(OpCodes.Neg);
+ il.Emit(OpCodes.Br_S, endLabel);
+
+ // value >= 0, return value
+ il.MarkLabel(positiveLabel);
+ il.Emit(OpCodes.Ldarg_1);
+
+ il.MarkLabel(endLabel);
+ }
+ else
+ {
+ // For unsigned types, abs is just the identity
+ il.Emit(OpCodes.Ldarg_1);
+ }
+ }
+
+ il.Emit(OpCodes.Ret);
+ }
+
+ private static void CreateNegateMethod(TypeBuilder typeBuilder)
+ {
+ var methodBuilder = typeBuilder.DefineMethod(
+ "Negate",
+ MethodAttributes.Public | MethodAttributes.Virtual,
+ typeof(T),
+ new[] { typeof(T) });
+
+ var il = methodBuilder.GetILGenerator();
+
+ // Check if the type supports negation by examining if it's signed
+ var typeInfo = typeof(T);
+ var isSignedType = typeInfo == typeof(sbyte) || typeInfo == typeof(short) ||
+ typeInfo == typeof(int) || typeInfo == typeof(long) ||
+ typeInfo == typeof(float) || typeInfo == typeof(double) ||
+ typeInfo == typeof(decimal);
+
+ if (isSignedType)
+ {
+ il.Emit(OpCodes.Ldarg_1); // Load the argument
+ il.Emit(OpCodes.Neg); // Negate it using IL neg instruction
+ }
+ else
+ {
+ // For unsigned types, throw NotSupportedException
+ il.Emit(OpCodes.Ldstr, $"Negate operation is not supported for unsigned type {typeof(T).Name}");
+ il.Emit(OpCodes.Newobj, typeof(NotSupportedException).GetConstructor(new[] { typeof(string) })!);
+ il.Emit(OpCodes.Throw);
+ }
+
+ il.Emit(OpCodes.Ret);
+ }
+ }
+
+ ///
+ /// Interface for compiled math operations.
+ /// Интерфейс для скомпилированных математических операций.
+ ///
+ ///
+ /// The numeric type.
+ /// Числовой тип.
+ ///
+ public interface IMathOperations
+ {
+ ///
+ /// Returns the absolute value of the specified number.
+ /// Возвращает абсолютное значение указанного числа.
+ ///
+ ///
+ /// The number to get absolute value for.
+ /// Число для получения абсолютного значения.
+ ///
+ ///
+ /// The absolute value.
+ /// Абсолютное значение.
+ ///
+ T Abs(T value);
+
+ ///
+ /// Returns the negated value of the specified number.
+ /// Возвращает инвертированное значение указанного числа.
+ ///
+ ///
+ /// The number to negate.
+ /// Число для инверсии.
+ ///
+ ///
+ /// The negated value.
+ /// Инвертированное значение.
+ ///
+ T Negate(T value);
+ }
+}
\ No newline at end of file
diff --git a/csharp/Platform.Numbers/experiments/Program.cs b/csharp/Platform.Numbers/experiments/Program.cs
new file mode 100644
index 0000000..5bc0557
--- /dev/null
+++ b/csharp/Platform.Numbers/experiments/Program.cs
@@ -0,0 +1,62 @@
+using System;
+using Platform.Numbers;
+
+///
+/// Test program to verify MathHelpers works with compiled object methods instead of delegates
+///
+class Program
+{
+ static void Main()
+ {
+ Console.WriteLine("Testing MathHelpers with compiled object methods:");
+ Console.WriteLine("=======================================================");
+
+ Console.WriteLine("\n1. Testing with int (signed type):");
+ TestWithType(-5, 10);
+
+ Console.WriteLine("\n2. Testing with double (signed floating-point type):");
+ TestWithType(-3.14, 2.718);
+
+ Console.WriteLine("\n3. Testing with long (signed type):");
+ TestWithType(-123456789L, 987654321L);
+
+ Console.WriteLine("\n4. Testing with uint (unsigned type - negate should throw):");
+ TestUnsignedType(42u);
+
+ Console.WriteLine("\n5. Testing with float (signed floating-point type):");
+ TestWithType(-1.23f, 4.56f);
+
+ Console.WriteLine("\nAll tests completed successfully!");
+ Console.WriteLine("The MathHelpers implementation uses compiled object methods instead of delegates.");
+ }
+
+ static void TestWithType(T negativeValue, T positiveValue)
+ where T : System.Numerics.INumberBase
+ {
+ var ops = MathHelpers.Operations;
+
+ Console.WriteLine($" Type: {typeof(T).Name}");
+ Console.WriteLine($" Abs({negativeValue}) = {ops.Abs(negativeValue)}");
+ Console.WriteLine($" Abs({positiveValue}) = {ops.Abs(positiveValue)}");
+ Console.WriteLine($" Negate({positiveValue}) = {ops.Negate(positiveValue)}");
+ Console.WriteLine($" Negate({negativeValue}) = {ops.Negate(negativeValue)}");
+ }
+
+ static void TestUnsignedType(T value)
+ where T : System.Numerics.INumberBase
+ {
+ var ops = MathHelpers.Operations;
+
+ Console.WriteLine($" Type: {typeof(T).Name} (unsigned)");
+ Console.WriteLine($" Abs({value}) = {ops.Abs(value)}");
+
+ try
+ {
+ Console.WriteLine($" Negate({value}) = {ops.Negate(value)}");
+ }
+ catch (NotSupportedException ex)
+ {
+ Console.WriteLine($" Negate({value}) threw expected exception: {ex.Message}");
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/Platform.Numbers/experiments/experiments.csproj b/csharp/Platform.Numbers/experiments/experiments.csproj
new file mode 100644
index 0000000..12163d9
--- /dev/null
+++ b/csharp/Platform.Numbers/experiments/experiments.csproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net8
+ enable
+
+
+
+
+
diff --git a/experiments/Program.cs b/experiments/Program.cs
new file mode 100644
index 0000000..8afb978
--- /dev/null
+++ b/experiments/Program.cs
@@ -0,0 +1,62 @@
+using System;
+using Platform.Numbers;
+
+///
+/// Test program to verify MathHelpers works with compiled object methods instead of delegates
+///
+class Program
+{
+ static void Main()
+ {
+ Console.WriteLine("Testing MathHelpers with compiled object methods:");
+ Console.WriteLine("=======================================================");
+
+ Console.WriteLine("\n1. Testing with int (signed type):");
+ TestWithType(-5, 10);
+
+ Console.WriteLine("\n2. Testing with double (signed floating-point type):");
+ TestWithType(-3.14, 2.718);
+
+ Console.WriteLine("\n3. Testing with long (signed type):");
+ TestWithType(-123456789L, 987654321L);
+
+ Console.WriteLine("\n4. Testing with uint (unsigned type - negate should throw):");
+ TestUnsignedType(42u);
+
+ Console.WriteLine("\n5. Testing with float (signed floating-point type):");
+ TestWithType(-1.23f, 4.56f);
+
+ Console.WriteLine("\nAll tests completed successfully!");
+ Console.WriteLine("The MathHelpers implementation uses compiled object methods instead of delegates.");
+ }
+
+ static void TestWithType(T negativeValue, T positiveValue)
+ where T : System.Numerics.INumberBase
+ {
+ var ops = MathHelpers.Operations;
+
+ Console.WriteLine($" Type: {typeof(T).Name}");
+ Console.WriteLine($" Abs({negativeValue}) = {ops.Abs(negativeValue)}");
+ Console.WriteLine($" Abs({positiveValue}) = {ops.Abs(positiveValue)}");
+ Console.WriteLine($" Negate({positiveValue}) = {ops.Negate(positiveValue)}");
+ Console.WriteLine($" Negate({negativeValue}) = {ops.Negate(negativeValue)}");
+ }
+
+ static void TestUnsignedType(T value)
+ where T : System.Numerics.INumberBase
+ {
+ var ops = MathHelpers.Operations;
+
+ Console.WriteLine($" Type: {typeof(T).Name} (unsigned)");
+ Console.WriteLine($" Abs({value}) = {ops.Abs(value)}");
+
+ try
+ {
+ Console.WriteLine($" Negate({value}) = {ops.Negate(value)}");
+ }
+ catch (NotSupportedException ex)
+ {
+ Console.WriteLine($" Negate({value}) threw expected exception: {ex.Message}");
+ }
+ }
+}
diff --git a/experiments/experiments.csproj b/experiments/experiments.csproj
new file mode 100644
index 0000000..e94a247
--- /dev/null
+++ b/experiments/experiments.csproj
@@ -0,0 +1,14 @@
+
+
+
+ Exe
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/test_mathhelpers.cs b/test_mathhelpers.cs
new file mode 100644
index 0000000..eb7f1e3
--- /dev/null
+++ b/test_mathhelpers.cs
@@ -0,0 +1,38 @@
+using System;
+using Platform.Numbers;
+
+class Program
+{
+ static void Main()
+ {
+ Console.WriteLine("Testing MathHelpers with object methods instead of delegates:");
+
+ // Test with int
+ Console.WriteLine("\nTesting with int:");
+ var intOps = MathHelpers.Operations;
+ Console.WriteLine($"Abs(-5) = {intOps.Abs(-5)}");
+ Console.WriteLine($"Negate(5) = {intOps.Negate(5)}");
+
+ // Test with double
+ Console.WriteLine("\nTesting with double:");
+ var doubleOps = MathHelpers.Operations;
+ Console.WriteLine($"Abs(-3.14) = {doubleOps.Abs(-3.14)}");
+ Console.WriteLine($"Negate(3.14) = {doubleOps.Negate(3.14)}");
+
+ // Test with uint (unsigned - negate should throw)
+ Console.WriteLine("\nTesting with uint (should throw for negate):");
+ var uintOps = MathHelpers.Operations;
+ Console.WriteLine($"Abs(5u) = {uintOps.Abs(5u)}");
+
+ try
+ {
+ Console.WriteLine($"Negate(5u) = {uintOps.Negate(5u)}");
+ }
+ catch (NotSupportedException ex)
+ {
+ Console.WriteLine($"Expected exception: {ex.Message}");
+ }
+
+ Console.WriteLine("\nAll tests completed successfully!");
+ }
+}
\ No newline at end of file