{"id":26800526,"url":"https://github.com/ktsu-dev/significantnumber","last_synced_at":"2026-06-30T01:01:13.406Z","repository":{"id":243056028,"uuid":"811340615","full_name":"ktsu-dev/SignificantNumber","owner":"ktsu-dev","description":"High-precision arithmetic class representing numbers with a significand and exponent.","archived":false,"fork":false,"pushed_at":"2026-06-26T02:29:17.000Z","size":654,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-26T04:10:09.936Z","etag":null,"topics":["csharp","dotnet","exponent","math","numeric-types","precision-arithmetic","significand","significant-figures","significant-number"],"latest_commit_sha":null,"homepage":"https://ktsu.dev","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-06T12:08:44.000Z","updated_at":"2026-06-26T02:29:13.000Z","dependencies_parsed_at":"2026-02-16T05:04:12.101Z","dependency_job_id":null,"html_url":"https://github.com/ktsu-dev/SignificantNumber","commit_stats":null,"previous_names":["ktsu-io/significantnumber","ktsu-dev/significantnumber"],"tags_count":52,"template":false,"template_full_name":null,"purl":"pkg:github/ktsu-dev/SignificantNumber","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FSignificantNumber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FSignificantNumber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FSignificantNumber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FSignificantNumber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktsu-dev","download_url":"https://codeload.github.com/ktsu-dev/SignificantNumber/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FSignificantNumber/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34948227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-29T02:00:05.398Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["csharp","dotnet","exponent","math","numeric-types","precision-arithmetic","significand","significant-figures","significant-number"],"created_at":"2025-03-29T20:17:44.899Z","updated_at":"2026-06-30T01:01:13.373Z","avatar_url":"https://github.com/ktsu-dev.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ktsu.SignificantNumber\n\n![NuGet Version](https://img.shields.io/nuget/v/ktsu.SignificantNumber?logo=nuget\u0026label=stable)\n![NuGet Version](https://img.shields.io/nuget/vpre/ktsu.SignificantNumber?logo=nuget\u0026label=dev)\n![GitHub commit activity](https://img.shields.io/github/commit-activity/m/ktsu-dev/SignificantNumber?label=commits)\n![GitHub branch status](https://img.shields.io/github/checks-status/ktsu-dev/SignificantNumber/main)\n\nThe `SignificantNumber` class represents a number with a significand and an exponent, enabling high-precision arithmetic operations that comply with calculation rules for significant figures. It provides a robust set of functionalities for mathematical computations and formatting.\n\n## Features\n\n- High-precision arithmetic operations (addition, subtraction, multiplication, division)\n- Support for significant figures and exponents\n- Integration with .NET numerical interfaces\n- Comprehensive error handling and validation\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Creating a SignificantNumber](#creating-a-significantnumber)\n    - [Supported Numeric Types](#supported-numeric-types)\n    - [Examples](#examples)\n  - [Arithmetic Operations](#arithmetic-operations)\n  - [Comparison Operations](#comparison-operations)\n  - [Formatting and Parsing](#formatting-and-parsing)\n  - [Extension Methods](#extension-methods)\n  - [Conversion](#conversion)\n- [Precision](#precision)\n  - [Significand and Exponent](#significand-and-exponent)\n  - [Precision Handling](#precision-handling)\n  - [Example of Precision](#example-of-precision)\n- [API Reference](#api-reference)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\n\nTo install the `SignificantNumber` library, you can use the .NET CLI:\n\n```sh\ndotnet add package ktsu.SignificantNumber\n```\n\nOr, add the package reference directly in your project file:\n\n```xml\n\u003cPackageReference Include=\"ktsu.SignificantNumber\" Version=\"x.x.x\" /\u003e\n```\n\n## Usage\n\n### Creating a SignificantNumber\n\nYou can create a `SignificantNumber` from various numeric types using the `ToSignificantNumber` extension method:\n\n#### Supported Numeric Types\n\nThe `SignificantNumber` class supports a wide range of numeric types through the `ToSignificantNumber` extension method, leveraging the `INumber` interface for conversions. The following types are supported:\n\n- **Integer Types**:\n  - `int`\n  - `long`\n  - `short`\n  - `sbyte`\n  - `uint`\n  - `ulong`\n  - `ushort`\n  - `byte`\n  - `BigInteger`\n\n- **Floating-Point Types**:\n  - `double`\n  - `float`\n  - `Half`\n  - `decimal`\n\n### Examples\n\nYou can convert various numeric types to `SignificantNumber` using the `ToSignificantNumber` extension method:\n\n```csharp\nusing ktsu.SignificantNumber;\n\n// Integer types\nint intValue = 12345;\nSignificantNumber significantNumberFromInt = intValue.ToSignificantNumber();\n\nBigInteger bigIntValue = new BigInteger(9876543210);\nSignificantNumber significantNumberFromBigInt = bigIntValue.ToSignificantNumber();\n\n// Floating-point types\ndouble doubleValue = 123.45;\nSignificantNumber significantNumberFromDouble = doubleValue.ToSignificantNumber();\n\nHalf halfValue = (Half)123.45;\nSignificantNumber significantNumberFromHalf = halfValue.ToSignificantNumber();\n\nfloat floatValue = 123.45f;\nSignificantNumber significantNumberFromFloat = floatValue.ToSignificantNumber();\n\ndecimal decimalValue = 123.45m;\nSignificantNumber significantNumberFromDecimal = decimalValue.ToSignificantNumber();\n```\n\n### Arithmetic Operations\n\nYou can perform various arithmetic operations on `SignificantNumber` instances:\n\n```csharp\nvar result1 = number1 + number2;\nvar result2 = number1 - number2;\nvar result3 = number1 * number2;\nvar result4 = number1 / number2;\n\n// Square and cube operations\nvar squared = number1.Squared();\nvar cubed = number1.Cubed();\n\n// Power operation\nvar powerResult = number1.Pow(3); // number1 raised to the power of 3\n```\n\n### Comparison Operations\n\nYou can compare `SignificantNumber` instances using comparison operators:\n\n```csharp\nbool isEqual = number1 == number2;\nbool isGreater = number1 \u003e number2;\nbool isLessOrEqual = number1 \u003c= number2;\n```\n\n### Formatting and Parsing\n\nYou can format a `SignificantNumber` as a string:\n\n```csharp\nstring formatted = number1.ToString(\"G\", CultureInfo.InvariantCulture);\nConsole.WriteLine(formatted);  // Outputs the formatted number\n```\n\nParsing is not supported and will throw `NotSupportedException`:\n\n```csharp\ntry\n{\n    var parsedNumber = SignificantNumber.Parse(\"123.45\", CultureInfo.InvariantCulture);\n}\ncatch (NotSupportedException ex)\n{\n    Console.WriteLine(ex.Message);\n}\n```\n\nInstead, you should parse the number as another numeric type and convert it to a `SignificantNumber`:\n\n```csharp\ndouble parsedDouble = double.Parse(\"123.45\", CultureInfo.InvariantCulture);\nSignificantNumber significantNumberFromDouble = parsedDouble.ToSignificantNumber();\n```\n\n### Extension Methods\n\n#### `ToSignificantNumber`\n\nConverts various numeric types to a `SignificantNumber`.\n\n#### Usage\n\n```csharp\npublic static SignificantNumber ToSignificantNumber\u003cTInput\u003e(this INumber\u003cTInput\u003e input)\n    where TInput : INumber\u003cTInput\u003e\n```\n\n#### Parameters\n\n- `input`: The input number to convert.\n\n#### Returns\n\n- `SignificantNumber`: The converted `SignificantNumber`.\n\n#### Example\n\n```csharp\ndouble floatingPointValue = 123.45;\nSignificantNumber significantNumberFromFloat = floatingPointValue.ToSignificantNumber();\n\nint integerValue = 12345;\nSignificantNumber significantNumberFromInt = integerValue.ToSignificantNumber();\n\nSignificantNumber result = significantNumberFromFloat + significantNumberFromInt;\n// result = 12468.45\n```\n\n### Conversion\n\n#### `To\u003cTOutput\u003e`\n\nConverts a `SignificantNumber` to the specified numeric type.\n\n#### Usage\n\n```csharp\npublic TOutput To\u003cTOutput\u003e()\n    where TOutput : INumber\u003cTOutput\u003e\n```\n\n#### Parameters\n\n- None\n\n#### Returns\n\n- `TOutput`: The converted value of the `SignificantNumber`.\n\n#### Example\n\n```csharp\nSignificantNumber significantNumber = new SignificantNumber(3, 12345); // 12345e3\ndouble result = significantNumber.To\u003cdouble\u003e();\nConsole.WriteLine(result);  // Outputs 12345000\n```\n\n## Precision\n\nThe `SignificantNumber` class is designed to handle high-precision arithmetic operations with significant figures and exponents.\n\nHere's how it ensures precision:\n\n### Significand and Exponent\n\nA `SignificantNumber` consists of two main components:\n\n- **Significand**: This is the significant part of the number, stored as a `BigInteger` to accommodate a wide range of values with high precision.\n- **Exponent**: This is the exponent part of the number, which scales the significand by a power of ten.\n\n### Precision Handling\n\n- **Maximum Significant Digits**: When converting from a floating-point number to a `SignificantNumber` maximum number of significant digits is limited to 7 for `float` values, and 16 for `double` values.\n- **Trailing Zero Removal**: The class automatically sanitizes the significand by removing trailing zeros, ensuring that the number is stored in its most compact and precise form.\n- **Rounding**: You can round a `SignificantNumber` to a specified number of decimal digits, ensuring that you can control the precision of your calculations.\n\n### Example of Precision\n\nConsider the number `123.456000`:\n\n- When stored as a `SignificantNumber`, it will be represented as `123456e-3` after removing the trailing zeros and adjusting the exponent accordingly.\n- This ensures that the number is represented with the exact precision required for your calculations, without unnecessary trailing zeros.\n\nBy using the `SignificantNumber` class, you can perform high-precision arithmetic operations and maintain control over the significant figures and exponent, ensuring accurate and efficient mathematical computations.\n\n## API Reference\n\n### Properties\n\n- `static SignificantNumber NegativeOne` - Gets the value -1 for the type.\n- `static SignificantNumber One` - Gets the value 1 for the type.\n- `static SignificantNumber Zero` - Gets the value 0 for the type.\n- `static int Radix` - Gets the radix, or base, for the type.\n- `static SignificantNumber AdditiveIdentity` - Gets the additive identity of the current type.\n- `static SignificantNumber MultiplicativeIdentity` - Gets the multiplicative identity of the current type.\n\n### Methods\n\n- `bool Equals(SignificantNumber other)` - Determines whether the specified object is equal to the current object.\n- `int CompareTo(object? obj)` - Compares the current instance with another object.\n- `int CompareTo(SignificantNumber other)` - Compares the current instance with another significant number.\n- `int CompareTo\u003cTInput\u003e(TInput other) where TInput : INumber\u003cTInput\u003e` - Compares the current instance with another number.\n- `SignificantNumber Abs()` - Returns the absolute value of the current instance.\n- `SignificantNumber Round(int decimalDigits)` - Rounds the current instance to the specified number of decimal digits.\n- `SignificantNumber Clamp\u003cTNumber\u003e(TNumber min, TNumber max) where TNumber : INumber\u003cTNumber\u003e` - Clamps the specified value between the minimum and maximum values.\n- `string ToString(string? format, IFormatProvider? formatProvider)` - Converts the current instance to its equivalent string representation using the specified format and format provider.\n- `bool TryFormat(Span\u003cchar\u003e destination, out int charsWritten, ReadOnlySpan\u003cchar\u003e format, IFormatProvider? provider)` - Attempts to format the current instance into the provided span.\n- `TOutput To\u003cTOutput\u003e() where TOutput : INumber\u003cTOutput\u003e` - Converts the current significant number to the specified numeric type.\n\n### Static Methods\n\n- `static SignificantNumber Abs(SignificantNumber value)` - Returns the absolute value of a `SignificantNumber`.\n- `static bool IsCanonical(SignificantNumber value)` - Determines whether the specified value is canonical.\n- `static bool IsComplexNumber(SignificantNumber value)` - Determines whether the specified value is a complex number.\n- `static bool IsEvenInteger(SignificantNumber value)` - Determines whether the specified value is an even integer.\n- `static bool IsFinite(SignificantNumber value)` - Determines whether the specified value is finite.\n- `static bool IsImaginaryNumber(SignificantNumber value)` - Determines whether the specified value is an imaginary number.\n- `static bool IsInfinity(SignificantNumber value)` - Determines whether the specified value is infinite.\n- `static bool IsInteger(SignificantNumber value)` - Determines whether the specified value is an integer.\n- `static bool IsNaN(SignificantNumber value)` - Determines whether the specified value is NaN.\n- `static bool IsNegative(SignificantNumber value)` - Determines whether the specified value is negative.\n- `static bool IsNegativeInfinity(SignificantNumber value)` - Determines whether the specified value is negative infinity.\n- `static bool IsNormal(SignificantNumber value)` - Determines whether the specified value is normal.\n- `static bool IsOddInteger(SignificantNumber value)` - Determines whether the specified value is an odd integer.\n- `static bool IsPositive(SignificantNumber value)` - Determines whether the specified value is positive.\n- `static bool IsPositiveInfinity(SignificantNumber value)` - Determines whether the specified value is positive infinity.\n- `static bool IsRealNumber(SignificantNumber value)` - Determines whether the specified value is a real number.\n- `static bool IsSubnormal(SignificantNumber value)` - Determines whether the specified value is subnormal.\n- `static bool IsZero(SignificantNumber value)` - Determines whether the specified value is zero.\n- `static SignificantNumber MaxMagnitude(SignificantNumber x, SignificantNumber y)` - Returns the larger of the magnitudes of two significant numbers.\n- `static SignificantNumber MaxMagnitudeNumber(SignificantNumber x, SignificantNumber y)` - Returns the larger of the magnitudes of two significant numbers.\n- `static SignificantNumber MinMagnitude(SignificantNumber x, SignificantNumber y)` - Returns the smaller of the magnitudes of two significant numbers.\n- `static SignificantNumber MinMagnitudeNumber(SignificantNumber x, SignificantNumber y)` - Returns the smaller of the magnitudes of two significant numbers.\n\n### Operators\n\n- `static SignificantNumber operator -(SignificantNumber value)` - Negates a significant number.\n- `static SignificantNumber operator -(SignificantNumber left, SignificantNumber right)` - Subtracts one significant number from another.\n- `static bool operator !=(SignificantNumber left, SignificantNumber right)` - Determines whether two significant numbers are not equal.\n- `static SignificantNumber operator *(SignificantNumber left, SignificantNumber right)` - Multiplies two significant numbers.\n- `static SignificantNumber operator /(SignificantNumber left, SignificantNumber right)` - Divides one significant number by another.\n- `static SignificantNumber operator +(SignificantNumber value)` - Returns the unary plus of a significant number.\n- `static SignificantNumber operator +(SignificantNumber left, SignificantNumber right)` - Adds two significant numbers.\n- `static bool operator ==(SignificantNumber left, SignificantNumber right)` - Determines whether two significant numbers are equal.\n- `static bool operator \u003e(SignificantNumber left, SignificantNumber right)` - Determines whether one significant number is greater than another.\n- `static bool operator \u003c(SignificantNumber left, SignificantNumber right)` - Determines whether one significant number is less than another.\n- `static bool operator \u003e=(SignificantNumber left, SignificantNumber right)` - Determines whether one significant number is greater than or equal to another.\n- `static bool operator \u003c=(SignificantNumber left, SignificantNumber right)` - Determines whether one significant number is less than or equal to another.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request or open an issue.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsu-dev%2Fsignificantnumber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktsu-dev%2Fsignificantnumber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsu-dev%2Fsignificantnumber/lists"}