Genumerics 1.0.3

Install-Package Genumerics -Version 1.0.3
dotnet add package Genumerics --version 1.0.3
<PackageReference Include="Genumerics" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Genumerics --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Genumerics, 1.0.3"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// 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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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));

    public void MaxValue<T>(T expected)
        Assert.AreEqual(expected, Number.MaxValue<T>());
  • .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

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.

Version Downloads Last updated
1.0.3 98 3/26/2021
1.0.2 360 12/6/2019
1.0.1 295 10/1/2019