TypedMath 1.0.3
See the version list below for details.
dotnet add package TypedMath --version 1.0.3
NuGet\Install-Package TypedMath -Version 1.0.3
<PackageReference Include="TypedMath" Version="1.0.3" />
paket add TypedMath --version 1.0.3
#r "nuget: TypedMath, 1.0.3"
// 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
- The icon is GPL from http://www.iconarchive.com/show/ios7-icons-by-icons8/Science-Math-icon.html.
Cheers. Marcus
Product | Versions 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. |
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.
First release