Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thiagomvas/tmath
A C# Math library using Generics to add support for more number types.
https://github.com/thiagomvas/tmath
contributions-welcome csharp dotnet easing easing-functions generic generics library math numerics open-source statistics
Last synced: 20 days ago
JSON representation
A C# Math library using Generics to add support for more number types.
- Host: GitHub
- URL: https://github.com/thiagomvas/tmath
- Owner: thiagomvas
- License: mit
- Created: 2023-11-25T13:56:28.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-07-20T15:01:10.000Z (5 months ago)
- Last Synced: 2024-11-22T00:39:19.258Z (about 1 month ago)
- Topics: contributions-welcome, csharp, dotnet, easing, easing-functions, generic, generics, library, math, numerics, open-source, statistics
- Language: C#
- Homepage:
- Size: 298 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# TMath - Generics Math Library for C#
[![NUnit Tests](https://github.com/thiagomvas/TMath/actions/workflows/dotnet.yml/badge.svg)](https://github.com/thiagomvas/TMath/actions/workflows/dotnet.yml) [![Version](https://img.shields.io/nuget/v/tmath
)](https://www.nuget.org/packages/TMath/) ![Downloads](https://img.shields.io/nuget/dt/tmath
) ![Stars](https://img.shields.io/github/stars/thiagomvas/tmath
) ![License](https://img.shields.io/github/license/thiagomvas/tmath)TMath is a C# Math library that has function implementations for any number or custom type
that implements ``INumber``. Some functions require other implementations like
``ILogarithmicFunctions`` or ``IPowerFunctions``.## 🌟 • Features
- **Generics Support**: With TFunctions, you can make calculations using all number types with the same
function call, doesn't matter if you're using `float`, `ulong`, `decimal` or your custom
numeric type, as long as it implements `INumber`
- **Generics Constants:** TMath also has a ``TConstants`` class for getting mathematical
constants as any numeric type, such as **Euler's Number, Pi, Golden Ratio** and common square roots
- **Expanded math functions**: More math functions not supported by the default `Math` class
that also work with generics, such as ``Factorial()``.
- **Generics Easings Class:** ``TEasings`` offers a handful of easing functions for usage in
your projects that support any ``INumber``
- **Statistics Functions:** Use TStatistics to get info about a data set of numbers, such as Mean, Variance, etc.
or use the ``DescriptiveStatistics`` class to hold all that info about a data set.## 📙 • Getting Started
### Installation
There are multiple ways of installing TMath on your project:
1. **NuGet Package Manager**: From your IDE, simply open the package manager and search for TMath
2. **.NET CLI**: Open a command line and switch to the directory that contains your project file.
After that, run the following command
```shell
dotnet add package TMath
```
3. **Forking / Cloning the repository**: Clone the repository into your projects and keep the package
saved on your project files.
> [!IMPORTANT]
> Downloading the files manually means you will have to update the package manually if you want the
> latest release whenever the package gets updated## 🔧 • Usage
Using TMath is very simple, simply call the functions like you would with ``Math`` and it'll automatically
return
the correct type for most functions, with the exception of a handful of them like ``Factorial()``.For getting any constants using ``TConstants``, specify your type (for example, ``TConstants``).
```csharp
// Calculating the area of a circle arc.
decimal angle = TConstants.Pi;
decimal radius = 1;
decimal areaOfArc = (TFunctions.Rad2Deg(angle) / 360) * TConstants.Pi * TFunctions.Pow(radius, 2);
Console.WriteLine(areaOfArc);// Calculating 20!
long factorial = TFunctions.Factorial(20);
Console.WriteLine(factorial);// Absolute value
sbyte number = -34;
sbyte abs = TFunctions.Abs(number);
Console.WriteLine(abs);// Getting the info about a data set
float[] data = new float[] { 1, 2, 3, 4, 5, 6}
float mean = TStatistics.Mean(data);DescriptiveStatistics statistics = new(data); // Or get all that info computed into the custom class
Console.WriteLine(statistics);```
## 🤝 • Contributing
If you'd like to contribute in anyways, check out the [Contributing Guidelines](https://github.com/thiagomvas/TMath/blob/master/CONTRIBUTING.md) for info on how you can contribute.## 📄 • License
TMath is licensed under the [MIT License](https://github.com/thiagomvas/TMath/blob/master/LICENSE).