Giter Club home page Giter Club logo

decimalmath's Introduction

Decimal Math

Portable math support for Decimal that Microsoft forgot and more.

The .NET Decimal data type is included in .NET, but is often overlooked for scientific calculations. It's high precision and exact up to 28 decimal places and it's available in any .NET environment.

You might be in a situation where you just need a lot more precision than Double can provide. I used Decimal for calculating locations in space for CNC manufacturing and pick and place control. I've found the increased precision of Decimal reduces overall errors throughout the set of calculations and it also improves the odds of reversing the calculations if necessary for debugging. In that case it ends up being a kind of oversampling.

Unfortunately, a lot of the usual number functionality is not provided for .NET. For example, you can't calculate a square root or even perform exponentiation. You can cast to Double for these operations, but you can end up with a significant loss of precision.

Note All of this I've used in the "real world", but this is also a hobby. Although the library is performant, I've perferred accuracy and readability to raw performance.

Install

Install via NuGet package manager console:

PM> Install-Package DecimalMath.DecimalEx

Or of course you can clone the repository and pull in the projects directly.

Libraries

This project contains two portable libraries.

DecimalEx

Bridges the gap in .NET support.

  • Decimal versions of the following functions:
    • Sqrt
    • Pow
    • Exp
    • Log
    • Sin, Cos, Tan
    • ASin, ACos, ATan, ATan2
  • General Decimal functionality:
    • Floor / Ceiling to a given number of decimal places
    • Implementations of GCF, AGMean, and a fault-tolerant Average
    • Function to get decimal places of a number (looking at bits, NOT by converting to string)
    • Other minor helper functions
  • Functionality for working with Decimal matrices as 2D arrays and a base class for implementing an NxN matrix for use in affine transformations.

Decimal2D

Provides support for high-accuracy geometric calculations. Note: This is still a work in progress. It's been used in production, but it still needs some more grooming (was originally VB code) and unit tests.

  • Support for 2D geometric objects
    • Point, Line, and Vector
    • Circle and Arc
  • Support for geometric relationships, e.g. tangent to, intersects, etc.
  • A 2D tranformation matrix with a number of provided transforms.
  • An implementation of an abstract right triangle (i.e., the sides and angles but without a location in space).
  • Generic right triangle operations.

License

This project uses the MIT License. See the license file in the same folder as this readme.

decimalmath's People

Contributors

nathanpjones avatar monty241 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.