From 6a85a78ea369cdc6d4191e108cb58b5cccae718d Mon Sep 17 00:00:00 2001 From: konard Date: Sun, 14 Sep 2025 14:40:20 +0300 Subject: [PATCH 1/3] Initial commit with task details for issue #3 Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: https://github.com/linksplatform/Numbers/issues/3 --- CLAUDE.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..560899d --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,5 @@ +Issue to solve: https://github.com/linksplatform/Numbers/issues/3 +Your prepared branch: issue-3-5b75eea3 +Your prepared working directory: /tmp/gh-issue-solver-1757850016074 + +Proceed. \ No newline at end of file From ab53317b7098d02821f66b0e8f80641f367d0854 Mon Sep 17 00:00:00 2001 From: konard Date: Sun, 14 Sep 2025 14:45:52 +0300 Subject: [PATCH 2/3] Add Math[T] class with direct reference to .NET operator methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements Math generic class that provides Abs and Negate methods using direct references to System.Math operator methods instead of dynamically compiled delegates. This approach offers better performance and compile-time optimization compared to reflection-based solutions. Features: - Generic Abs method supporting signed numeric types - Generic Negate method using direct operator reference - Comprehensive test coverage for various numeric types - Follows existing codebase conventions and patterns Fixes #3 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- csharp/Platform.Numbers.Tests/MathTests.cs | 49 ++++++++++++++++++++ csharp/Platform.Numbers/Math[T].cs | 53 ++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 csharp/Platform.Numbers.Tests/MathTests.cs create mode 100644 csharp/Platform.Numbers/Math[T].cs diff --git a/csharp/Platform.Numbers.Tests/MathTests.cs b/csharp/Platform.Numbers.Tests/MathTests.cs new file mode 100644 index 0000000..79934b9 --- /dev/null +++ b/csharp/Platform.Numbers.Tests/MathTests.cs @@ -0,0 +1,49 @@ +using Xunit; + +namespace Platform.Numbers.Tests +{ + public static class MathTests + { + [Fact] + public static void AbsTest() + { + // Test with signed integers + Assert.Equal(5, Math.Abs(-5)); + Assert.Equal(5, Math.Abs(5)); + Assert.Equal(0, Math.Abs(0)); + + // Test with long + Assert.Equal(123L, Math.Abs(-123L)); + Assert.Equal(123L, Math.Abs(123L)); + + // Test with double + Assert.Equal(3.14, Math.Abs(-3.14)); + Assert.Equal(3.14, Math.Abs(3.14)); + + // Test with unsigned types (should return same value) + Assert.Equal(42u, Math.Abs(42u)); + Assert.Equal(0u, Math.Abs(0u)); + } + + [Fact] + public static void NegateTest() + { + // Test with signed integers + Assert.Equal(-5, Math.Negate(5)); + Assert.Equal(5, Math.Negate(-5)); + Assert.Equal(0, Math.Negate(0)); + + // Test with long + Assert.Equal(-123L, Math.Negate(123L)); + Assert.Equal(123L, Math.Negate(-123L)); + + // Test with double + Assert.Equal(-3.14, Math.Negate(3.14)); + Assert.Equal(3.14, Math.Negate(-3.14)); + + // Test with float + Assert.Equal(-2.5f, Math.Negate(2.5f)); + Assert.Equal(2.5f, Math.Negate(-2.5f)); + } + } +} \ No newline at end of file diff --git a/csharp/Platform.Numbers/Math[T].cs b/csharp/Platform.Numbers/Math[T].cs new file mode 100644 index 0000000..799fdf2 --- /dev/null +++ b/csharp/Platform.Numbers/Math[T].cs @@ -0,0 +1,53 @@ +using System; +using System.Numerics; +using System.Runtime.CompilerServices; + +namespace Platform.Numbers +{ + /// + /// Represents a set of math operations using direct reference to operator methods of .NET classes. + /// Представляет набор математических операций, используя прямую ссылку на методы операторов классов .NET. + /// + public static class Math where T : INumberBase + { + /// + /// Returns the absolute value of a number. + /// Возвращает абсолютное значение числа. + /// + /// The number to get the absolute value of. + /// The absolute value of the input number. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T Abs(T x) + { + if (typeof(T) == typeof(sbyte)) + return T.CreateTruncating(System.Math.Abs((sbyte)(object)x)); + if (typeof(T) == typeof(short)) + return T.CreateTruncating(System.Math.Abs((short)(object)x)); + if (typeof(T) == typeof(int)) + return T.CreateTruncating(System.Math.Abs((int)(object)x)); + if (typeof(T) == typeof(long)) + return T.CreateTruncating(System.Math.Abs((long)(object)x)); + if (typeof(T) == typeof(float)) + return T.CreateTruncating(System.Math.Abs((float)(object)x)); + if (typeof(T) == typeof(double)) + return T.CreateTruncating(System.Math.Abs((double)(object)x)); + if (typeof(T) == typeof(decimal)) + return T.CreateTruncating(System.Math.Abs((decimal)(object)x)); + + // For unsigned types, absolute value is the number itself + return x; + } + + /// + /// Returns the negation of a number. + /// Возвращает отрицание числа. + /// + /// The number to negate. + /// The negated value of the input number. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T Negate(T x) + { + return -x; + } + } +} \ No newline at end of file From 963fa1987a5c07c0d152dc3a621b05e48cd7ce9b Mon Sep 17 00:00:00 2001 From: konard Date: Sun, 14 Sep 2025 14:46:48 +0300 Subject: [PATCH 3/3] Remove CLAUDE.md - Claude command completed --- CLAUDE.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index 560899d..0000000 --- a/CLAUDE.md +++ /dev/null @@ -1,5 +0,0 @@ -Issue to solve: https://github.com/linksplatform/Numbers/issues/3 -Your prepared branch: issue-3-5b75eea3 -Your prepared working directory: /tmp/gh-issue-solver-1757850016074 - -Proceed. \ No newline at end of file