Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 14, 2025

πŸš€ Implementation Complete

This pull request implements comprehensive generic operator functionality comparable to JonSkeet.MiscUtil, addressing issue #31.

πŸ“‹ Issue Reference

Fixes #31

✨ Key Features Implemented

Basic Arithmetic Operations

  • Add<T>(T, T) - Generic addition
  • Subtract<T>(T, T) - Generic subtraction
  • Multiply<T>(T, T) - Generic multiplication
  • Divide<T>(T, T) - Generic division
  • Negate<T>(T) - Generic negation

Comparison Operations

  • Min<T>(T, T) - Returns smaller value
  • Max<T>(T, T) - Returns larger value
  • Abs<T>(T) - Absolute value
  • Sign<T>(T) - Sign indication (-1, 0, 1)

Aggregate Operations

  • Sum<T>(IEnumerable<T>) - Sums sequence of values
  • Average<T>(IEnumerable<T>) - Computes average of sequence

Identity Constants

  • Zero<T>() - Gets additive identity
  • One<T>() - Gets multiplicative identity

🎯 Modern .NET 8 Approach

This implementation uses .NET 8's modern generic math system instead of JonSkeet.MiscUtil's legacy approach:

Feature JonSkeet.MiscUtil Platform.Numbers
Type Safety Runtime resolution Compile-time constraints
Performance Expression compilation Direct operator calls
Framework .NET Framework 3.5 .NET 8
Method Reflection-based Interface-based

βœ… Testing

  • 22 comprehensive tests covering all new operators
  • Tests for multiple numeric types: int, long, double, ulong
  • Edge case testing (empty sequences, etc.)
  • Backward compatibility verification for existing functionality

πŸ“ˆ Benefits

  1. Type Safety: Compile-time guarantees using static interface members
  2. Performance: No runtime expression compilation overhead
  3. Modern: Leverages C# 11+ and .NET 8 generic math features
  4. Extensible: Works with any type implementing relevant interfaces
  5. Comprehensive: Covers all major operator categories from MiscUtil

πŸ”„ Backward Compatibility

All existing functionality remains unchanged:

  • Factorial<T> methods
  • Catalan<T> methods
  • IsPowerOfTwo<T> methods

This PR was implemented using modern .NET 8 patterns to provide superior functionality compared to JonSkeet.MiscUtil

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #31
@konard konard self-assigned this Sep 14, 2025
Added comprehensive generic operator support using modern .NET 8 interfaces:

β€’ Basic arithmetic operations: Add, Subtract, Multiply, Divide, Negate
β€’ Comparison operations: Min, Max, Abs, Sign
β€’ Aggregate operations: Sum, Average
β€’ Identity constants: Zero, One

Key advantages over JonSkeet.MiscUtil:
- Compile-time type safety using static interface members
- Better performance (no runtime expression compilation)
- Modern .NET 8 generic math approach
- Comprehensive test coverage with 22 passing tests

Fixes #31

πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Compare to Operators from JonSkeet.MiscUtil Implement generic operators comparable to JonSkeet.MiscUtil Sep 14, 2025
@konard konard marked this pull request as ready for review September 14, 2025 07:40
πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compare to Operators from JonSkeet.MiscUtil

2 participants