ktsu.SemanticQuantity
1.1.0
Prefix Reserved
See the version list below for details.
dotnet add package ktsu.SemanticQuantity --version 1.1.0
NuGet\Install-Package ktsu.SemanticQuantity -Version 1.1.0
<PackageReference Include="ktsu.SemanticQuantity" Version="1.1.0" />
<PackageVersion Include="ktsu.SemanticQuantity" Version="1.1.0" />
<PackageReference Include="ktsu.SemanticQuantity" />
paket add ktsu.SemanticQuantity --version 1.1.0
#r "nuget: ktsu.SemanticQuantity, 1.1.0"
#:package ktsu.SemanticQuantity@1.1.0
#addin nuget:?package=ktsu.SemanticQuantity&version=1.1.0
#tool nuget:?package=ktsu.SemanticQuantity&version=1.1.0
ktsu.SemanticQuantity
Overview
The ktsu.SemanticQuantity library provides a base class for creating semantic quantities with a specific storage type. This allows for defining quantities with meaningful semantics, such as length, mass, time, etc., and performing arithmetic operations on them while preserving their semantics.
Features
- Define semantic quantities with meaningful semantics.
- Perform arithmetic operations on semantic quantities.
- Support for a wide range of numeric types for storage.
- Integration with .NET numeric interfaces.
Table of Contents
Installation
To install the ktsu.SemanticQuantity library, you can use the .NET CLI:
dotnet add package ktsu.SemanticQuantity
Or, add the package reference directly in your project file:
<PackageReference Include="ktsu.SemanticQuantity" Version="1.0.0" />
Usage
Creating a Semantic Quantity
You can create a semantic quantity from various numeric types using the Create method:
using ktsu.SemanticQuantity;
using System.Numerics;
// Define a specific semantic quantity type
public record Length : SemanticQuantity<Length, double>;
var length = Length.Create(123.45);
Console.WriteLine(length.Quantity); // Output: 123.45
Arithmetic Operations
You can perform various arithmetic operations on semantic quantities:
var length1 = Length.Create(100.0);
var length2 = Length.Create(200.0);
var sum = length1 + length2;
var difference = length1 - length2;
var product = length1 * 2.0;
var quotient = length2 / 2.0;
var ratio = length2 / length1;
Supported Numeric Types
The SemanticQuantity class supports a wide range of numeric types for storage through the INumber interface. The following types are supported:
intlongshortsbyteuintulongushortbyteBigIntegerdoublefloatHalfdecimal
API Reference
SemanticQuantity<TStorage>
TStorage Quantity { get; protected set; }: Gets the stored quantity value.
Methods
static TQuantity Create<TQuantity>(TStorage quantity): Creates a new instance of the specifiedSemanticQuantity<TQuantity>type with the given quantity.
SemanticQuantity<TSelf, TStorage>
- Inherits from
SemanticQuantity<TStorage>and implements various arithmetic operators.
Methods
static TResult Multiply<TResult>(SemanticQuantity<TStorage> self, SemanticQuantity<TStorage> other): Multiplies two semantic quantities and returns the result as a new instance of the specified type.static TResult Multiply<TResult>(SemanticQuantity<TStorage> self, TStorage other): Multiplies a semantic quantity by a scalar value and returns the result as a new instance of the specified type.static TResult Divide<TResult>(SemanticQuantity<TStorage> self, SemanticQuantity<TStorage> other): Divides one semantic quantity by another and returns the result as a new instance of the specified type.static TResult Divide<TResult>(SemanticQuantity<TStorage> self, TStorage other): Divides a semantic quantity by a scalar value and returns the result as a new instance of the specified type.static TStorage DivideToStorage(SemanticQuantity<TStorage> self, SemanticQuantity<TStorage> other): Divides one semantic quantity by another and returns the result as a scalar value.static TResult Add<TResult>(SemanticQuantity<TStorage> self, SemanticQuantity<TStorage> other): Adds two semantic quantities and returns the result as a new instance of the specified type.static TResult Subtract<TResult>(SemanticQuantity<TStorage> self, SemanticQuantity<TStorage> other): Subtracts one semantic quantity from another and returns the result as a new instance of the specified type.static TResult Negate<TResult>(SemanticQuantity<TStorage> self): Negates a semantic quantity and returns the result as a new instance of the specified type.
Operators
static TSelf operator +(SemanticQuantity<TSelf, TStorage> left, TSelf right): Adds two semantic quantities.static TSelf operator -(SemanticQuantity<TSelf, TStorage> left, TSelf right): Subtracts one semantic quantity from another.static TSelf operator -(SemanticQuantity<TSelf, TStorage> value): Negates a semantic quantity.static TSelf operator *(SemanticQuantity<TSelf, TStorage> left, TStorage right): Multiplies a semantic quantity by a scalar value.static TSelf operator /(SemanticQuantity<TSelf, TStorage> left, TStorage right): Divides a semantic quantity by a scalar value.static TStorage operator /(SemanticQuantity<TSelf, TStorage> left, SemanticQuantity<TSelf, TStorage> right): Divides one semantic quantity by another.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue.
License
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ktsu.SemanticQuantity:
| Package | Downloads |
|---|---|
|
ktsu.PhysicalQuantity
Physical Quantity |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.1.1-pre.1 | 243 | 4/26/2025 | |
| 1.1.0 | 351 | 4/13/2025 | |
| 1.0.16-pre.3 | 126 | 2/6/2025 | |
| 1.0.16-pre.2 | 119 | 2/5/2025 | |
| 1.0.16-pre.1 | 136 | 2/5/2025 | |
| 1.0.15-pre.29 | 120 | 2/4/2025 | |
| 1.0.15-pre.28 | 123 | 2/3/2025 | |
| 1.0.15-pre.27 | 128 | 2/2/2025 | |
| 1.0.15-pre.26 | 128 | 1/31/2025 | |
| 1.0.15-pre.25 | 116 | 1/29/2025 | |
| 1.0.15-pre.24 | 124 | 1/27/2025 | |
| 1.0.15-pre.23 | 127 | 1/25/2025 | |
| 1.0.15-pre.22 | 117 | 1/23/2025 | |
| 1.0.15-pre.21 | 117 | 1/21/2025 | |
| 1.0.15-pre.20 | 120 | 1/20/2025 | |
| 1.0.15-pre.19 | 122 | 1/19/2025 | |
| 1.0.15-pre.18 | 129 | 1/17/2025 | |
| 1.0.15-pre.17 | 113 | 1/15/2025 | |
| 1.0.15-pre.16 | 111 | 1/13/2025 | |
| 1.0.15-pre.15 | 122 | 1/11/2025 |
## v1.1.0 (minor)
Changes since v1.0.0:
- Add automation scripts for metadata management and versioning ([@matt-edmondson](https://github.com/matt-edmondson))
- Add LICENSE template ([@matt-edmondson](https://github.com/matt-edmondson))
- Refactor test project and update method names ([@matt-edmondson](https://github.com/matt-edmondson))
- Remove old tests and add new SemanticQuantity tests ([@matt-edmondson](https://github.com/matt-edmondson))
- Renamed metadata files ([@matt-edmondson](https://github.com/matt-edmondson))
- Replace LICENSE file with LICENSE.md and update copyright information ([@matt-edmondson](https://github.com/matt-edmondson))
- Update namespace to ktsu.SemanticQuantity ([@matt-edmondson](https://github.com/matt-edmondson))
## v1.0.15 (patch)
Changes since v1.0.15-pre.29:
- Add automation scripts for metadata management and versioning ([@matt-edmondson](https://github.com/matt-edmondson))
## v1.0.9 (patch)
Changes since v1.0.8:
- Refactor test project and update method names ([@matt-edmondson](https://github.com/matt-edmondson))
- Replace LICENSE file with LICENSE.md and update copyright information ([@matt-edmondson](https://github.com/matt-edmondson))
## v1.0.2 (patch)
Changes since v1.0.1:
- Update namespace to ktsu.SemanticQuantity ([@matt-edmondson](https://github.com/matt-edmondson))
## v1.0.0 (major)
Changes since 0.0.0.0:
- Add a self overloaded create method ([@matt-edmondson](https://github.com/matt-edmondson))
- Add crtp and unary negation ([@matt-edmondson](https://github.com/matt-edmondson))
- Add crtp operator implementations ([@matt-edmondson](https://github.com/matt-edmondson))
- Add documentation comments to the public API ([@matt-edmondson](https://github.com/matt-edmondson))
- Added new test record types and tests ([@matt-edmondson](https://github.com/matt-edmondson))
- Code style ([@matt-edmondson](https://github.com/matt-edmondson))
- Fix build ([@matt-edmondson](https://github.com/matt-edmondson))
- Fix coverage badge ([@matt-edmondson](https://github.com/matt-edmondson))
- Initial commit ([@matt-edmondson](https://github.com/matt-edmondson))
- Made SemanticQuantity classes non-abstract ([@matt-edmondson](https://github.com/matt-edmondson))
- Mark the assembly as CLS compliant and invisible to COM ([@matt-edmondson](https://github.com/matt-edmondson))
- Method parameters should be declared with base types csharpsquid:S3242 ([@matt-edmondson](https://github.com/matt-edmondson))
- Public the static methods so interfaces can access them ([@matt-edmondson](https://github.com/matt-edmondson))
- Remove unnescessary record constructors ([@matt-edmondson](https://github.com/matt-edmondson))
- Renamed test class `SemanticQuantityTests` to `AITests` ([@matt-edmondson](https://github.com/matt-edmondson))
- Renames to be more in line with SI definitions ([@matt-edmondson](https://github.com/matt-edmondson))
- Suppress CA2260 warning in Directory.Build.props as this analyzer seems broken in roslyn ([@matt-edmondson](https://github.com/matt-edmondson))
- Update Directory.Build.props ([@matt-edmondson](https://github.com/matt-edmondson))
- Update Directory.Build.targets ([@matt-edmondson](https://github.com/matt-edmondson))
- Update dotnet.yml ([@matt-edmondson](https://github.com/matt-edmondson))
- Update LICENSE ([@matt-edmondson](https://github.com/matt-edmondson))
- Update readme ([@matt-edmondson](https://github.com/matt-edmondson))
- Update README.md ([@matt-edmondson](https://github.com/matt-edmondson))
- Update README.md and library description in ktsu.io.SemanticQuantity ([@matt-edmondson](https://github.com/matt-edmondson))
- Update README.md for clarity and accuracy ([@matt-edmondson](https://github.com/matt-edmondson))
- Updated Directory.Build.props and Directory.Build.targets files ([@matt-edmondson](https://github.com/matt-edmondson))
- Updated software version to 1.0.0 ([@matt-edmondson](https://github.com/matt-edmondson))