Genumerics 1.0.2
See the version list below for details.
dotnet add package Genumerics --version 1.0.2
NuGet\Install-Package Genumerics -Version 1.0.2
<PackageReference Include="Genumerics" Version="1.0.2" />
paket add Genumerics --version 1.0.2
#r "nuget: Genumerics, 1.0.2"
// Install Genumerics as a Cake Addin
#addin nuget:?package=Genumerics&version=1.0.2
// Install Genumerics as a Cake Tool
#tool nuget:?package=Genumerics&version=1.0.2
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
, 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 |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.0 netstandard2.1 |
.NET Framework | net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 net481 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.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.