{"id":26800541,"url":"https://github.com/ktsu-dev/precisenumber","last_synced_at":"2026-02-16T07:17:51.640Z","repository":{"id":244877810,"uuid":"816183426","full_name":"ktsu-dev/PreciseNumber","owner":"ktsu-dev","description":null,"archived":false,"fork":false,"pushed_at":"2026-02-14T01:48:44.000Z","size":508,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-14T08:39:59.435Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ktsu-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":"COPYRIGHT.md","agents":null,"dco":null,"cla":null}},"created_at":"2024-06-17T07:55:55.000Z","updated_at":"2026-02-14T01:47:45.000Z","dependencies_parsed_at":"2024-11-01T00:17:26.147Z","dependency_job_id":"710c52c6-2e24-4127-bf7e-8e92ed13f1a3","html_url":"https://github.com/ktsu-dev/PreciseNumber","commit_stats":null,"previous_names":["ktsu-io/precisenumber","ktsu-dev/precisenumber"],"tags_count":46,"template":false,"template_full_name":null,"purl":"pkg:github/ktsu-dev/PreciseNumber","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FPreciseNumber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FPreciseNumber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FPreciseNumber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FPreciseNumber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktsu-dev","download_url":"https://codeload.github.com/ktsu-dev/PreciseNumber/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FPreciseNumber/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29502934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T05:57:17.024Z","status":"ssl_error","status_checked_at":"2026-02-16T05:56:49.929Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-29T20:17:47.180Z","updated_at":"2026-02-16T07:17:51.613Z","avatar_url":"https://github.com/ktsu-dev.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ktsu.PreciseNumber  \n\nA high-precision numeric type for .NET that provides arbitrary precision arithmetic with a focus on accuracy. By combining the scale benefits of scientific notation with the precision of `BigInteger`, this library offers reliable and accurate mathematical operations where standard floating point types fall short.  \n\n[![License](https://img.shields.io/github/license/ktsu-dev/PreciseNumber.svg?label=License\u0026logo=nuget)](LICENSE.md)  \n\n[![NuGet Version](https://img.shields.io/nuget/v/ktsu.PreciseNumber?label=Stable\u0026logo=nuget)](https://nuget.org/packages/ktsu.PreciseNumber)  \n[![NuGet Version](https://img.shields.io/nuget/vpre/ktsu.PreciseNumber?label=Latest\u0026logo=nuget)](https://nuget.org/packages/ktsu.PreciseNumber)  \n[![NuGet Downloads](https://img.shields.io/nuget/dt/ktsu.PreciseNumber?label=Downloads\u0026logo=nuget)](https://nuget.org/packages/ktsu.PreciseNumber)  \n\n[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/ktsu-dev/PreciseNumber?label=Commits\u0026logo=github)](https://github.com/ktsu-dev/PreciseNumber/commits/main)  \n[![GitHub contributors](https://img.shields.io/github/contributors/ktsu-dev/PreciseNumber?label=Contributors\u0026logo=github)](https://github.com/ktsu-dev/PreciseNumber/graphs/contributors)  \n[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ktsu-dev/PreciseNumber/dotnet.yml?label=Build\u0026logo=github)](https://github.com/ktsu-dev/PreciseNumber/actions)  \n\n## Table of Contents  \n\n- [Features](#features)  \n\n- [Getting Started](#getting-started)  \n\n- [Installation](#installation)  \n\n- [Requirements](#requirements)  \n\n- [Quick Usage](#quick-usage)  \n\n- [Basic Example](#basic-example)  \n\n- [Common Operations](#common-operations)  \n\n- [When to Use PreciseNumber](#when-to-use-precisenumber)  \n\n- [Advanced Usage](#advanced-usage)  \n\n- [Type Conversions](#type-conversions)  \n\n- [Mathematical Functions](#mathematical-functions)  \n\n- [Parsing and Formatting](#parsing-and-formatting)  \n\n- [Parsing from Strings](#parsing-from-strings)  \n\n- [String Formatting](#string-formatting)  \n\n- [Comparison with Built-in Types](#comparison-with-built-in-types)  \n\n- [PreciseNumber vs. double/float](#precisenumber-vs-doublefloat)  \n\n- [PreciseNumber vs. decimal](#precisenumber-vs-decimal)  \n\n- [PreciseNumber vs. BigInteger](#precisenumber-vs-biginteger)  \n\n- [Technical Details](#technical-details)  \n\n- [Internal Representation](#internal-representation)  \n\n- [Precision Control](#precision-control)  \n\n- [Limitations](#limitations)  \n\n- [API Reference](#api-reference)  \n\n- [PreciseNumber Class](#precisenumber-class)  \n\n- [PreciseNumberExtensions Class](#precisenumberextensions-class)  \n\n- [License](#license)  \n\n- [Contributing](#contributing)  \n\n- [Acknowledgements](#acknowledgements)  \n\n## Features  \n\n- **Arbitrary Precision**: Based on `BigInteger` for the significand, allowing numbers of unlimited size.  \n\n- **Scientific Notation**: Uses an exponent and significand (the coefficient or mantissa in scientific notation) model similar to scientific notation.  \n\n- **Lossless Arithmetic**: Preserves precision during calculations with no rounding errors.  \n\n- **Full .NET Integration**: Implements `INumber\u003cT\u003e` interface for seamless integration with .NET's numeric ecosystem.  \n\n- **Comprehensive Mathematical Support**: Includes advanced mathematical functions like exponential operations (Pow, Exp, Squared, Cubed), constant values (Pi, E, Tau) with high precision, absolute value operations, and specialized numerical checks (isOdd, isEven, etc.)—all with arbitrary precision.  \n\n- **Balanced Performance**: The design prioritizes accuracy and precision while maintaining reasonable performance. For calculations where extreme precision matters more than raw speed, PreciseNumber delivers excellent results, though built-in numeric types remain faster for standard precision needs.  \n\n# Getting Started  \n\n## Installation  \n\nTo install PreciseNumber, you can use the .NET CLI:  \n\n```sh  \ndotnet add package ktsu.PreciseNumber  \n\n```  \n\nOr you can use the NuGet Package Manager in Visual Studio by searching for `ktsu.PreciseNumber`.  \n\n## Requirements  \n\nThis library requires .NET 8.0 or later.  \n\n## Quick Usage  \n\n### Basic Example  \n\n```csharp  \nusing System.Numerics;  \nusing ktsu.PreciseNumber;  \n\n// Create PreciseNumber from various types  \nvar precise1 = 123.456.ToPreciseNumber();  \nvar precise2 = BigInteger.Parse(\"1234567890\").ToPreciseNumber();  \n\n// Perform calculation with high precision  \nvar result = precise1 * precise2 / 7.89.ToPreciseNumber();  \n\nConsole.WriteLine(result); // Displays accurate result with no floating point errors  \n\n```  \n\n### Common Operations  \n\nCreate and perform operations with precise numbers:  \n\n```csharp  \nusing ktsu.PreciseNumber;  \n\n// Create PreciseNumbers from various numeric types  \nvar a = 123.456.ToPreciseNumber();  \nvar b = 2.ToPreciseNumber();  \n\n// Basic arithmetic operations  \nvar sum = a + b;        // 125.456  \n\nvar difference = a - b; // 121.456  \n\nvar product = a * b;    // 246.912  \n\nvar quotient = a / b;   // 61.728  \n\n// Comparison  \nbool isGreater = a \u003e b; // true  \n\n```  \n\n### When to Use PreciseNumber  \n\nPreciseNumber is ideal for:  \n\n- **Financial calculations** where exact precision is required beyond what decimal offers  \n\n- **Scientific computing** involving very large or small numbers with many significant digits  \n\n- **Cryptography** applications requiring arbitrary precision arithmetic  \n\n- **Mathematical algorithms** where rounding errors would accumulate and affect results  \n\nFor everyday calculations where standard precision is sufficient, built-in types like `int`, `double`, or `decimal` will offer better performance.  \n\n# Advanced Usage  \n\n## Type Conversions  \n\nThe library provides seamless round-trip conversions between standard numeric types and PreciseNumber using extension methods:  \n\n```csharp  \nusing System.Numerics;  \nusing ktsu.PreciseNumber;  \n\n// Convert FROM standard types TO PreciseNumber  \nint originalInt = 42;  \ndouble originalDouble = 3.14159;  \ndecimal originalDecimal = 1234.5678m;  \nBigInteger originalBigInt = BigInteger.Parse(\"123456789012345678901234567890\");  \n\n// Convert using the ToPreciseNumber() extension method  \nvar preciseInt = originalInt.ToPreciseNumber();  \nvar preciseDouble = originalDouble.ToPreciseNumber();  \nvar preciseDecimal = originalDecimal.ToPreciseNumber();  \nvar preciseBigInt = originalBigInt.ToPreciseNumber();  \n\n// Perform precise calculations if needed  \npreciseInt *= 10;  \npreciseDouble += PreciseNumber.Pi;  \n\n// Convert back FROM PreciseNumber TO standard types using To\u003cT\u003e()  \nint roundTripInt = preciseInt.To\u003cint\u003e();                  // 420  \ndouble roundTripDouble = preciseDouble.To\u003cdouble\u003e();      // ~6.28318  \ndecimal roundTripDecimal = preciseDecimal.To\u003cdecimal\u003e();  // 1234.5678  \nBigInteger roundTripBigInt = preciseBigInt.To\u003cBigInteger\u003e(); // 123456789012345678901234567890  \n\n// Verify round-trip conversion (for values that weren't modified)  \nConsole.WriteLine(originalDecimal == roundTripDecimal);   // True  \nConsole.WriteLine(originalBigInt == roundTripBigInt);     // True  \n\n```  \n\n### Mathematical Functions  \n\nPreciseNumber supports a wide range of mathematical operations:  \n\n```csharp  \nusing ktsu.PreciseNumber;  \n\nvar number = 2.5.ToPreciseNumber();  \n\n// Exponentiation  \nvar squared = number.Squared();  // 6.25  \nvar cubed = number.Cubed();      // 15.625  \nvar toThe4th = number.Pow(4.ToPreciseNumber());  // 39.0625  \n\n// Constants  \nvar pi = PreciseNumber.Pi;  \nvar e = PreciseNumber.E;  \n\n// Exponential function  \nvar expValue = PreciseNumber.Exp(1.ToPreciseNumber()); // e^1 = e  \n\n// Rounding and precision control  \nvar roundedValue = number.Round(1);  // 2.5 (already at 1 decimal place)  \nvar reducedValue = number.ReduceSignificance(1); // 3 (reduced to 1 significant digit)  \n\n// Min, Max, Abs, and Clamp  \nvar absValue = (-5).ToPreciseNumber().Abs();  // 5  \nvar maxValue = PreciseNumber.Max(2.ToPreciseNumber(), 3.ToPreciseNumber()); // 3  \nvar minValue = PreciseNumber.Min(2.ToPreciseNumber(), 3.ToPreciseNumber()); // 2  \nvar clampedValue = 10.ToPreciseNumber().Clamp(0, 5); // 5 (clamped to maximum)  \n\n```  \n\n## Parsing and Formatting  \n\n### Parsing from Strings  \n\n```csharp  \nusing System.Globalization;  \nusing System.Numerics;  \nusing ktsu.PreciseNumber;  \n\n// Parse from string using various formats  \nvar number1 = PreciseNumber.Parse(\"123.456\", CultureInfo.InvariantCulture);  \nvar number2 = PreciseNumber.Parse(\"1.23E4\", NumberStyles.Any, CultureInfo.InvariantCulture);  \n\n// Try parsing with error handling  \nif (PreciseNumber.TryParse(\"456.789\", out var result))  \n{  \n    Console.WriteLine($\"Parsed successfully: {result}\");  \n}  \n\n```  \n\n### String Formatting  \n\nConvert PreciseNumber to string:  \n\n```csharp  \nusing ktsu.PreciseNumber;  \n\nvar number = 123.456.ToPreciseNumber();  \nstring formatted = number.ToString(); // \"123.456\"  \n\n```  \n\n## Comparison with Built-in Types  \n\n### PreciseNumber vs. double/float  \n\n* *Advantages of PreciseNumber:**  \n\n- **No Rounding Errors**: Unlike floating-point types, PreciseNumber doesn't suffer from binary representation issues (e.g., 0.1 + 0.2 ≠ 0.3 in floating point)  \n\n- **Arbitrary Precision**: Not limited to 15-17 significant digits (double) or 6-9 significant digits (float)  \n\n- **Consistent Results**: Mathematical operations produce identical results regardless of magnitude  \n\n- **No Special Values**: PreciseNumber doesn't have NaN or Infinity values that can propagate through calculations  \n\n```csharp  \n// Double arithmetic issue  \ndouble a = 0.1;  \ndouble b = 0.2;  \nConsole.WriteLine(a + b == 0.3);  // False (equals 0.30000000000000004)  \n\n// PreciseNumber solves this  \nvar pa = 0.1.ToPreciseNumber();  \nvar pb = 0.2.ToPreciseNumber();  \nConsole.WriteLine((pa + pb) == 0.3.ToPreciseNumber());  // True (exactly 0.3)  \n\n```  \n\n### PreciseNumber vs. decimal  \n\n* *Advantages of PreciseNumber:**  \n\n- **Unlimited Range**: Not constrained by decimal's ±7.9E±28 range  \n\n- **Unlimited Precision**: Decimal is limited to 28-29 significant digits  \n\n- **Scientific Operations**: Better suited for scientific calculations requiring extreme precision  \n\n- **More Flexible Format**: Exponent-significand model makes it suitable for both very large and very small numbers  \n\n```csharp  \n// Decimal range/precision limitations  \ndecimal largeDecimal = 1.0m;  \nfor (int i = 0; i \u003c 30; i++)  \n    largeDecimal *= 10; // Will throw OverflowException  \n\n// PreciseNumber handles this easily  \nvar largePrecise = PreciseNumber.One;  \nfor (int i = 0; i \u003c 1000; i++)  \n    largePrecise *= 10; // Works fine with arbitrary large values  \n\n```  \n\n### PreciseNumber vs. BigInteger  \n\n* *Advantages of PreciseNumber:**  \n\n- **Decimal Point Support**: Represents both integer and fractional parts while BigInteger only handles integers  \n\n- **Scientific Notation**: More convenient for very large or small numbers with fraction components  \n\n- **Mathematical Constants**: Built-in support for constants like Pi and E with high precision  \n\n# Technical Details  \n\n## Internal Representation  \n\nPreciseNumber stores values in the form: `significand × 10^exponent`  \n\n- **Significand**: A `BigInteger` that contains all the significant digits  \n\n- **Exponent**: An `int` that determines the decimal place  \n\nThis representation allows for:  \n\n- Exact representation of integers of any size  \n\n- High precision for decimal values  \n\n- Accurate arithmetic without floating-point errors  \n\n## Precision Control  \n\nYou can control precision using:  \n\n- **Round()**: Rounds to a specific number of decimal places  \n\n- **ReduceSignificance()**: Reduces to a specific number of significant digits  \n\n## Limitations  \n\n- Operations that inherently require approximation (like certain roots or logarithms) fall back to `double` precision for calculation  \n\n- Conversion to standard types may throw `OverflowException` if the value is too large  \n\n## API Reference  \n\n### PreciseNumber Class  \n\n- **Constants**: `Zero`, `One`, `NegativeOne`, `Pi`, `E`, `Tau`  \n\n- **Arithmetic**: `+`, `-`, `*`, `/`, `%`, `++`, `--`  \n\n- **Comparison**: `==`, `!=`, `\u003c`, `\u003e`, `\u003c=`, `\u003e=`  \n\n- **Functions**: `Abs()`, `Round()`, `Clamp()`, `Squared()`, `Cubed()`, `Pow()`, `Exp()`  \n\n- **Utility**: `ToString()`, `Parse()`, `TryParse()`, `To\u003cT\u003e()`  \n\n### PreciseNumberExtensions Class  \n\n- **Conversion**: `ToPreciseNumber\u003cT\u003e()`extension method for any`INumber\u003cT\u003e`  \n\n## License  \n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.  \n\n## Contributing  \n\nContributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.  \n\n## Acknowledgements  \n\nThanks to the .NET community and ktsu.dev contributors for their support.  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsu-dev%2Fprecisenumber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktsu-dev%2Fprecisenumber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsu-dev%2Fprecisenumber/lists"}