Genumerics 1.0.3
dotnet add package Genumerics --version 1.0.3
NuGet\Install-Package Genumerics -Version 1.0.3
<PackageReference Include="Genumerics" Version="1.0.3" />
paket add Genumerics --version 1.0.3
#r "nuget: Genumerics, 1.0.3"
// Install Genumerics as a Cake Addin #addin nuget:?package=Genumerics&version=1.0.3 // Install Genumerics as a Cake Tool #tool nuget:?package=Genumerics&version=1.0.3
Genumerics is a high-performance .NET library for generic numeric operations. It is compatible with .NET Framework 4.5+ and .NET Standard 2.0+.
The Problem
You may have come across while working in .NET where you would like to perform numeric operations over a generic numeric type. Unfortunately .NET doesn't provide a way to do that natively.
This library fills that gap by providing most standard numeric operations for the following built-in numeric types and their nullable equivalents with the ability to add support for other numeric types.
sbyte
, byte
, short
, ushort
, int
, uint
, long
, ulong
, float
, double
, decimal
, nint
, nuint
, and BigInteger
Genumerics Demo
Below is a demo of some basic uses of Genumerics in the form of unit tests.
using Genumerics;
using NUnit.Framework;
public class GenumericsDemo
{
[TestCase(4, 5, 9)]
[TestCase(2.25, 6.75, 9.0)]
public void Add<T>(T left, T right, T expected)
{
Assert.AreEqual(expected, Number.Add(left, right));
Assert.AreEqual(expected, AddWithOperator<T>(left, right));
}
private T AddWithOperator<T>(Number<T> left, Number<T> right) => left + right;
[TestCase(9, 6, true)]
[TestCase(3.56, 4.07, false)]
public void GreaterThan<T>(T left, T right, bool expected)
{
Assert.AreEqual(expected, Number.GreaterThan(left, right));
Assert.AreEqual(expected, GreaterThanWithOperator<T>(left, right));
}
private bool GreaterThanWithOperator<T>(Number<T> left, Number<T> right) => left > right;
[TestCase(4, 4.0)]
[TestCase(27.0, 27)]
public void Convert<TFrom, TTo>(TFrom value, TTo expected)
{
Assert.AreEqual(expected, Number.Convert<TFrom, TTo>(value));
Assert.AreEqual(expected, Number.Create(value).To<TTo>());
}
[TestCase("98765", 98765)]
[TestCase("12.3456789", 12.3456789)]
public void Parse<T>(string value, T expected)
{
Assert.AreEqual(expected, Number.Parse<T>(value));
}
[TestCase(123, null, "123")]
[TestCase(255, "X", "FF")]
public void ToString<T>(T value, string format, string expected)
{
Assert.AreEqual(expected, Number.ToString(value, format));
}
[TestCase(sbyte.MaxValue)]
[TestCase(float.MaxValue)]
public void MaxValue<T>(T expected)
{
Assert.AreEqual(expected, Number.MaxValue<T>());
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 is compatible. netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 is compatible. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 2.0
- No dependencies.
-
.NETCoreApp 2.1
- No dependencies.
-
.NETCoreApp 3.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Genumerics:
Package | Downloads |
---|---|
LostTech.LargeCollections
Provides natively sized (64 bit on x64 and ARM64, 32 bit on x86 and ARM) collections. |
GitHub repositories
This package is not used by any popular GitHub repositories.