TypedMath 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package TypedMath --version 1.0.3
NuGet\Install-Package TypedMath -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TypedMath" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TypedMath --version 1.0.3
#r "nuget: TypedMath, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TypedMath as a Cake Addin
#addin nuget:?package=TypedMath&version=1.0.3

// Install TypedMath as a Cake Tool
#tool nuget:?package=TypedMath&version=1.0.3

Typed Math

Sometimes when working with calculations I tend to get a touch of Dyscalculia. To avoid this from happening I created this project. At first it seemed like a pretty meaningless project, but soon I realized this could be useful. So I made it a nuget. It's all extensions to number types.

Instead of writing

var x = 10 * 32 + y;

you can write

var x = 10.MultipliedWith(32).Add(y);

The package contains namespaces for each of the data types in Visual Studio.

To use the extensions use any of the namespaces

using MarcusMedinaPro.TypedMath.ByteExtension; // Bytes
using MarcusMedinaPro.TypedMath.CharExtension; // Char
using MarcusMedinaPro.TypedMath.DecimalExtension; // Decimal
using MarcusMedinaPro.TypedMath.DoubleExtension; // Double
using MarcusMedinaPro.TypedMath.IntExtension; // Int
using MarcusMedinaPro.TypedMath.LongExtension; // Long
using MarcusMedinaPro.TypedMath.SByteExtension; // SByte
using MarcusMedinaPro.TypedMath.ShortExtension; // Short
using MarcusMedinaPro.TypedMath.UintExtension; // Uint
using MarcusMedinaPro.TypedMath.UlongExtension; //Ulong
using MarcusMedinaPro.TypedMath.UshorttExtension; //Ushort

Examples

Here is the list of functions available for most of the types. In this example I'm using double

using MarcusMedinaPro.TypedMath.DoubleExtension; // Double

Compares the current double to a value of almost any type.

    // bool GreaterThan(...);
    int x=10;
    double y=15.2;
    if (y.GreaterThan(x))
    { 
        // Do something
    }

    // bool LessThan(...);
    if (y.LessThan(x))
    { 
        // Do something
    }

Compare if the numbers are equal or not (this can be tricky when using decimals though)

    // bool IsEqual(...);
    int x=10;
    double y=15.2;
    if (x.IsEqual(y))
    { 
        // Do something
    }

    // bool IsNotEqual(...);
    if (x.IsNotEqual(y))
    { 
        // Do something
    }

Check if the value is positive or negative

    // bool IsNegative();

    double y=-2;
    if (y.IsNegative())
    { 
        // Do something
    }

    // bool IsPositive();
    if (y.Positive())
    { 
        // Do something
    }

Add and Substract can also be done in typed form.

    // double Add(...);
    double y = 12;
    int x=14;
    var res = y.add(x);

    // double Substract(...);
    res = y.Substract(x);

Divide, Multiply and Modulus are also available

    // double DividedBy(...);
    int x = 10;
    int y = 12;
    var res = y.DividedBy(x);

    // double MultipliedWith(...);
    res = y.MultipliedWith(x);

    // double Modulus(...);
    res = y.Modulus(x);

Cast to another type if you don't like using var x=(int)myDouble;

    // byte CastDoubleToByte();
    double y = 13.37;
    var b= y.CastDoubleToByte()

    // char CastDoubleToChar();
    var c = y.CastDoubleToChar();

    // decimal CastDoubleToDecimal();
    var d = y.CastDoubleToDecimal()    

    // int CastDoubleToInt();
    var i = y.CastDoubleToInt();

    // long CastDoubleToLong(...);
    var l =  = y.CastDoubleToLong();

    // sbyte CastDoubleToSbyte(...);
    var sb= = y.CastDoubleToSbyte(); 

    // short CastDoubleToShort(...);
    var sh= y.CastDoubleToShort()
    
    // uint CastDoubleToUint(...);
    var ui = y.CastDoubleToUint();
    
    // ulong CastDoubleToUlong(...);
    var ul = y.CastDoubleToLong();

    // ushort CastDoubleToUshort(...);
    var usr= = y.CastDoubleToUShort();

Source code

You can find the code at https://github.com/MarcusMedina/TypedMath

Nuget

The nuget is available at https://www.nuget.org/packages/TypedMath/

Collaboration

Feel free to add suggest or send a pull request to my github.

Thanks

Cheers. Marcus

Product Compatible and additional computed target framework versions.
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.10 532 5/7/2020
1.0.9 419 5/7/2020
1.0.8 530 8/8/2019
1.0.6 532 5/29/2019
1.0.3 543 5/23/2019
1.0.2 516 5/14/2019
1.0.1 528 5/14/2019

First release