Skip to content

Commit

Permalink
Add support for Ratio<i128> as an underlying storage type.
Browse files Browse the repository at this point in the history
  • Loading branch information
iliekturtles committed Apr 9, 2022
1 parent 66d3e85 commit c41ae8e
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-full-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --no-run --no-default-features --features "autoconvert usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 bigint biguint rational rational32 rational64 bigrational f32 f64 std use_serde"
args: --verbose --no-run --no-default-features --features "autoconvert usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 bigint biguint rational rational32 rational64 rational128 bigrational f32 f64 std use_serde"
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ biguint = ["bigint-support"]
rational = ["rational-support"]
rational32 = ["rational-support"]
rational64 = ["rational-support"]
rational128 = ["rational-support"]
bigrational = ["bigint-support"]
f32 = []
f64 = []
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ uom = {
"usize", "u8", "u16", "u32", "u64", "u128", # Unsigned integer storage types.
"isize", "i8", "i16", "i32", "i64", "i128", # Signed integer storage types.
"bigint", "biguint", # Arbitrary width integer storage types.
"rational", "rational32", "rational64", "bigrational", # Integer ratio storage types.
# Integer ratio storage types.
"rational", "rational32", "rational64", "rational128", "bigrational",
"f32", "f64", # Floating point storage types.
"si", "std", # Built-in SI system and std library support.
"use_serde", # Serde support.
Expand All @@ -99,10 +100,10 @@ uom = {
The feature exists to account for compiler limitations where zero-cost code is not generated for
non-floating point underlying storage types.
* `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, `isize`, `i8`, `i16`, `i32`, `i64`, `i128`, `bigint`,
`biguint`, `rational`, `rational32`, `rational64`, `bigrational`, `f32`, `f64` -- Features to
enable underlying storage types. At least one of these features must be enabled. `f32` and `f64`
are enabled by default. See the [Design](#design) section for implications of choosing different
underlying storage types.
`biguint`, `rational`, `rational32`, `rational64`, `rational128`, `bigrational`, `f32`, `f64`
-- Features to enable underlying storage types. At least one of these features must be enabled.
`f32` and `f64` are enabled by default. See the [Design](#design) section for implications of
choosing different underlying storage types.
* `si` -- Feature to include the pre-built [International System of Units][si] (SI). Enabled by
default.
* `std` -- Feature to compile with standard library support. Disabling this feature compiles `uom`
Expand Down Expand Up @@ -134,7 +135,7 @@ storage type (e.g. `f32`).
Alternative base units can be used by executing the macro defined for the system of quantities
(`ISQ!` for the SI). `uom` supports `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, `isize`, `i8`,
`i16`, `i32`, `i64`, `i128`, `bigint`, `biguint`, `rational`, `rational32`, `rational64`,
`bigrational`, `f32`, and `f64` as the underlying storage type.
`rational128`, `bigrational`, `f32`, and `f64` as the underlying storage type.

A consequence of normalizing values to the base unit is that some values may not be able to be
represented or can't be precisely represented for floating point and rational underlying storage
Expand Down
19 changes: 10 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
//! "usize", "u8", "u16", "u32", "u64", "u128", # Unsigned integer storage types.
//! "isize", "i8", "i16", "i32", "i64", "i128", # Signed integer storage types.
//! "bigint", "biguint", # Arbitrary width integer storage types.
//! "rational", "rational32", "rational64", "bigrational", # Integer ratio storage types.
//! # Integer ratio storage types.
//! "rational", "rational32", "rational64", "rational128", "bigrational",
//! "f32", "f64", # Floating point storage types.
//! "si", "std", # Built-in SI system and std library support.
//! "use_serde", # Serde support.
Expand All @@ -86,11 +87,10 @@
//! directly interact. The feature exists to account for compiler limitations where zero-cost
//! code is not generated for non-floating point underlying storage types.
//! * `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, `isize`, `i8`, `i16`, `i32`, `i64`, `i128`,
//! `bigint`, `biguint`, `rational`, `rational32`, `rational64`, `bigrational`, `f32`, `f64` --
//! Features to enable underlying storage types. At least one of these features must be enabled.
//! `f32` and `f64` are enabled by default. See the [Design](#design) section for implications
//! of choosing different
//! underlying storage types.
//! `bigint`, `biguint`, `rational`, `rational32`, `rational64`, `rational128`, `bigrational`,
//! `f32`, `f64` -- Features to enable underlying storage types. At least one of these features
//! must be enabled. `f32` and `f64` are enabled by default. See the [Design](#design) section
//! for implications of choosing different underlying storage types.
//! * `si` -- Feature to include the pre-built [International System of Units][si] (SI). Enabled by
//! default.
//! * `std` -- Feature to compile with standard library support. Disabling this feature compiles
Expand Down Expand Up @@ -122,7 +122,7 @@
//! quantity. Alternative base units can be used by executing the macro defined for the system of
//! quantities (`ISQ!` for the SI). `uom` supports `usize`, `u8`, `u16`, `u32`, `u64`, `u128`,
//! `isize`, `i8`, `i16`, `i32`, `i64`, `i128`, `bigint`, `biguint`, `rational`, `rational32`,
//! `rational64`, `bigrational`, `f32`, and `f64` as the underlying storage type.
//! `rational64`, `rational128`, `bigrational`, `f32`, and `f64` as the underlying storage type.
//!
//! A consequence of normalizing values to the base unit is that some values may not be able to be
//! represented or can't be precisely represented for floating point and rational underlying
Expand Down Expand Up @@ -198,7 +198,8 @@
feature = "isize", feature = "i8", feature = "i16", feature = "i32", feature = "i64",
feature = "i128",
feature = "bigint", feature = "biguint",
feature = "rational", feature = "rational32", feature = "rational64", feature = "bigrational",
feature = "rational", feature = "rational32", feature = "rational64", feature = "rational128",
feature = "bigrational",
feature = "f32", feature = "f64", )))]
compile_error!("A least one underlying storage type must be enabled. See the features section of \
uom documentation for available underlying storage type options.");
Expand Down Expand Up @@ -592,7 +593,7 @@ storage_types! {
}

storage_types! {
types: Rational, Rational32, Rational64;
types: Rational, Rational32, Rational64, Rational128;

impl crate::Conversion<V> for V {
type T = V;
Expand Down
2 changes: 1 addition & 1 deletion src/si/thermodynamic_temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ mod tests {

mod non_big {
storage_types! {
types: PrimInt, Rational, Rational32, Rational64, Float;
types: PrimInt, Rational, Rational32, Rational64, Rational128, Float;

use crate::tests::*;
use super::super::*;
Expand Down
15 changes: 11 additions & 4 deletions src/storage_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
/// * `$T`: Types to generate a module for. Accepts all underlying storage types along with a number
/// of different categories:
/// * `All`: `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, `isize`, `i8`, `i16`, `i32`, `i64`,
/// `i128`, `BigInt`, `BigUint`, `Rational`, `Rational32`, `Rational64`, `BigRational`, `f32`,
/// and `f64`.
/// `i128`, `BigInt`, `BigUint`, `Rational`, `Rational32`, `Rational64`, `Rational128`,
/// `BigRational`, `f32`, and `f64`.
/// * `PrimInt`: `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, `isize`, `i8`, `i16`, `i32`, `i64`,
/// and `i128`.
/// * `Ratio`: `Rational`, `Rational32`, `Rational64`, and `BigRational`.
/// * `Ratio`: `Rational`, `Rational32`, `Rational64`, `Rational128`, and `BigRational`.
/// * `Float`: `f32` and `f64`.
/// * `Signed`: `isize`, `i8`, `i16`, `i32`, `i64`, `i128`, `BigInt`, `Rational`, `Rational32`,
/// `Rational64`, `BigRational`, `f32`, and `f64`.
/// `Rational64`, `Rational128`, `BigRational`, `f32`, and `f64`.
/// * `Unsigned`: `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, and `BigUint`.
/// * `$tt`: Code to place into each storage type module.
///
Expand Down Expand Up @@ -97,6 +97,9 @@ macro_rules! storage_types {
(@type ($(#[$attr:meta])*) @$M:ident Rational64 ($($tt:tt)*)) => {
storage_type_rational64!(($(#[$attr])*) @$M ($($tt)*));
};
(@type ($(#[$attr:meta])*) @$M:ident Rational128 ($($tt:tt)*)) => {
storage_type_rational128!(($(#[$attr])*) @$M ($($tt)*));
};
(@type ($(#[$attr:meta])*) @$M:ident BigRational ($($tt:tt)*)) => {
storage_type_bigrational!(($(#[$attr])*) @$M ($($tt)*));
};
Expand Down Expand Up @@ -124,6 +127,7 @@ macro_rules! storage_types {
storage_types!(@type ($(#[$attr])*) @$M Rational ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M Rational32 ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M Rational64 ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M Rational128 ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M BigRational ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M f32 ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M f64 ($($tt)*));
Expand All @@ -146,6 +150,7 @@ macro_rules! storage_types {
storage_types!(@type ($(#[$attr])*) @$M Rational ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M Rational32 ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M Rational64 ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M Rational128 ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M BigRational ($($tt)*));
};
(@type ($(#[$attr:meta])*) @$M:ident Float ($($tt:tt)*)) => {
Expand All @@ -163,6 +168,7 @@ macro_rules! storage_types {
storage_types!(@type ($(#[$attr])*) @$M Rational ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M Rational32 ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M Rational64 ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M Rational128 ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M BigRational ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M f32 ($($tt)*));
storage_types!(@type ($(#[$attr])*) @$M f64 ($($tt)*));
Expand Down Expand Up @@ -244,6 +250,7 @@ storage_type_types! {
storage_type_rational!("rational", rational, $crate::num::Rational);
storage_type_rational32!("rational32", rational32, $crate::num::rational::Rational32);
storage_type_rational64!("rational64", rational64, $crate::num::rational::Rational64);
storage_type_rational128!("rational128", rational128, $crate::num::rational::Ratio<i128>);
storage_type_bigrational!("bigrational", bigrational, $crate::num::BigRational);
storage_type_f32!("f32", f32, f32);
storage_type_f64!("f64", f64, f64);
Expand Down
2 changes: 1 addition & 1 deletion src/tests/asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ storage_types! {
}

storage_types! {
types: Rational, Rational32, Rational64;
types: Rational, Rational32, Rational64, Rational128;

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion src/tests/quantity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ mod fmt {
#[cfg(feature = "autoconvert")]
mod non_big {
storage_types! {
types: Float, PrimInt, Rational, Rational32, Rational64;
types: Float, PrimInt, Rational, Rational32, Rational64, Rational128;

use crate::tests::*;

Expand Down
2 changes: 1 addition & 1 deletion src/tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ mod non_ratio {

mod non_big {
storage_types! {
types: PrimInt, Rational, Rational32, Rational64, Float;
types: PrimInt, Rational, Rational32, Rational64, Rational128, Float;

use crate::tests::*;

Expand Down

0 comments on commit c41ae8e

Please sign in to comment.