Pavas.Tools.Math 1.0.0

dotnet add package Pavas.Tools.Math --version 1.0.0                
NuGet\Install-Package Pavas.Tools.Math -Version 1.0.0                
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="Pavas.Tools.Math" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pavas.Tools.Math --version 1.0.0                
#r "nuget: Pavas.Tools.Math, 1.0.0"                
#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 Pavas.Tools.Math as a Cake Addin
#addin nuget:?package=Pavas.Tools.Math&version=1.0.0

// Install Pavas.Tools.Math as a Cake Tool
#tool nuget:?package=Pavas.Tools.Math&version=1.0.0                

Pavas.Tools.Math Library

This project provides a configurable math library that performs basic arithmetic operations such as multiplication, addition, subtraction, division, and average calculations. It supports custom configuration for behaviors such as safe division by zero and decimal rounding.

Features

  • Multiplication: Multiply a series of decimal numbers.
  • Addition: Add a series of decimal numbers.
  • Subtraction: Subtract a series of decimal numbers.
  • Division: Divide a series of decimal numbers with optional safe division by zero handling.
  • Average: Calculate the average of a series of numbers.
  • Configurable options: Customize configuration

Installation

Install the package into your project. Pavas.Tools.Math

Usage

1. Dependency Injection Setup

The library can be injected into your project using a dependency injection manager.

using Microsoft.Extensions.DependencyInjection;
using Pavas.Tools.Math.Contracts;
using Pavas.Tools.Math.Options;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Add MathTool with default options
        services.AddMathTool();
        
        // Or configure custom options
        services.AddMathTool(options =>
        {
            options.Decimals = 4;  // Set decimal rounding precision
            options.SafeDivisionByZero = true;  // Enable safe division by zero handling
        });
    }
}

2. Accessor Manager

The math tool can also be used without dependency injection by accessing it through an accessor.

using Pavas.Tools.Math;

var mathTool = MathToolAccessor.UseDefault(); // Using default options

// Or configure the math tool with custom options
var customMathTool = MathToolAccessor.WithOptions(options =>
{
    options.Decimals = 3;
    options.SafeDivisionByZero = true;
});

3. Arithmetic Operations

You can perform various arithmetic operations using the IMathTool interface:

// Multiplication
decimal result = mathTool.Multiply(10m, 5m, 2m);  // Result: 100.0000 (depending on decimal settings)

// Addition
decimal sum = mathTool.Addition(10m, 5m, 2m);  // Result: 17.0000

// Subtraction
decimal difference = mathTool.Subtract(10m, 5m, 2m);  // Result: 3.0000

// Division
decimal quotient = mathTool.Divide(100m, 2m);  // Result: 50.0000

// Average
decimal average = mathTool.Average(10m, 20m, 30m);  // Result: 20.0000

Configuration Options

The following options are configurable:

  • Decimals: Controls the number of decimal places for rounding results. Default is 10.
  • SafeDivisionByZero: If set to true, division by zero returns decimal.Zero. If set to false, it throws a DivideByZeroException. Default is false.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0 103 9/20/2024