uom-0.35.0/.cargo_vcs_info.json0000644000000001360000000000100117210ustar { "git": { "sha1": "57d076b0e3ff07007e18f5fe49cc823a7b082715" }, "path_in_vcs": "" }uom-0.35.0/.github/workflows/ci-full-test-suite.yml000064400000000000000000000030621046102023000202710ustar 00000000000000name: CI - full test suite on: [pull_request, push] jobs: full_test_suite: name: Run full test suite (Rust stable on ubuntu-latest) runs-on: ubuntu-latest env: RUSTFLAGS: -D warnings steps: - name: Checkout repository uses: actions/checkout@v3 - name: Install Rust toolchain id: install-rust uses: dtolnay/rust-toolchain@stable # Cache based on OS/compiler. - name: Extract cache uses: actions/cache@v3 with: path: | ~/.cargo !~/.cargo/registry/index !~/.cargo/git/checkouts target !target/tests !target/examples key: ${{ runner.os }}-${{ steps.install-rust.outputs.cachekey }} - name: Test all crates run: cargo test --all --verbose --features "use_serde" - name: Test si run: cargo test --verbose --no-default-features --features "f32 si" - name: Test all non-storage type features run: cargo test --verbose --no-default-features --features "autoconvert f32 si use_serde" - name: Test si with underlying storage types run: cargo test --verbose --no-run --no-default-features --features "autoconvert usize isize bigint bigrational complex32 si std use_serde" - name: Test all non-si features run: cargo test --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 complex32 complex64 f32 f64 std use_serde" uom-0.35.0/.github/workflows/ci-min-test-matrix.yml000064400000000000000000000014711046102023000202670ustar 00000000000000name: CI - min test matrix on: [pull_request, push] jobs: min_test_matrix: name: Run minimal test matrix (Rust ${{ matrix.rust }} on ${{ matrix.os }}) runs-on: ${{ matrix.os }} env: RUSTFLAGS: -D warnings strategy: fail-fast: false # If one job fails, run remaining jobs. matrix: os: - ubuntu-latest - macOS-latest - windows-latest toolchain: - stable - beta - nightly - 1.60.0 # MSRV steps: - name: Checkout repository uses: actions/checkout@v3 - name: Install Rust toolchain uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.toolchain }} - name: Test all crates run: cargo test --all --verbose --features "use_serde" uom-0.35.0/.github/workflows/ci-tool-checks.yml000064400000000000000000000037671046102023000174520ustar 00000000000000name: CI - Clippy, Rustfmt, Rustdoc, & Tarpaulin on: [pull_request, push] jobs: tools: name: Clippy, Rustfmt, & Tarpaulin (Rust ${{ matrix.toolchain }} on ubuntu-latest) runs-on: ubuntu-latest strategy: matrix: toolchain: - 1.70.0 steps: - name: Checkout repository uses: actions/checkout@v3 - name: Install Rust nightly toolchain uses: dtolnay/rust-toolchain@nightly - name: Install Rust toolchain uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.toolchain }} components: rustfmt, clippy # Tools-specific cache based on OS/compiler. - name: Extract tools cache uses: actions/cache@v3 with: path: | ~/.cargo !~/.cargo/registry/index !~/.cargo/git/checkouts target !target/tests !target/examples key: tools-${{ runner.os }}-${{ steps.install-rust.outputs.cachekey }} - name: Clippy run: cargo clippy --all --tests -- -D warnings - name: Rustfmt run: cargo fmt --all -- --check - name: Rustdoc run: cargo doc --all --no-deps env: RUSTDOCFLAGS: '-D warnings' - name: Install cargo-binstall if: ${{ success() && github.event_name == 'push' }} run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash - name: Install tarpaulin if: ${{ success() && github.event_name == 'push' }} run: cargo binstall --no-confirm cargo-tarpaulin - name: Run tarpaulin if: ${{ success() && github.event_name == 'push' }} run: cargo +nightly tarpaulin --verbose --timeout 120 --out Xml - name: Upload to codecov.io uses: codecov/codecov-action@v1.0.2 if: ${{ success() && github.event_name == 'push' }} with: token: ${{ secrets.CODECOV_TOKEN }} uom-0.35.0/.gitignore000064400000000000000000000000221046102023000124730ustar 00000000000000target Cargo.lock uom-0.35.0/.rustfmt.toml000064400000000000000000000005371046102023000131750ustar 00000000000000# Unstable and defective options commented out. Once stabilized or corrected these options will # likely be enabled. use_small_heuristics = "Max" #wrap_comments = true #comment_width = 100 #format_strings = true #match_block_trailing_comma = true edition = "2018" use_try_shorthand = true use_field_init_shorthand = true #error_on_unformatted = true uom-0.35.0/CHANGELOG.md000064400000000000000000001315531046102023000123320ustar 00000000000000# Change log ## [v0.35.0] — 2023-07-?? This release adds new quantities, bumps the MSRV (minimum supported Rust version) to 1.60.0, and fixes bitrot in Github actions. Many thanks to [calbaker](https://github.com/calbaker), [groscoe2](https://github.com/groscoe2), [professoralex13](https://github.com/professoralex13), [robinohs](https://github.com/robinohs), and [Uzaaft](https://github.com/Uzaaft) for pull requests included and issues resolved in this release. ### Added * [#406](https://github.com/iliekturtles/uom/pull/406) Add `cubic_meter_per_minute` and `cubic_meter_per_hour` units to `VolumeRate`. * [#409](https://github.com/iliekturtles/uom/pull/409) Add `AngularAbsement` quantity. * [#410](https://github.com/iliekturtles/uom/pull/410) Add `MassPerEnergy` quantity. * [#417](https://github.com/iliekturtles/uom/pull/417) [Breaking] Correct `ThermalConductance` `meter_per` units to be `meter_squared_per`. Descriptions and abbreviations were already correct. * [#419](https://github.com/iliekturtles/uom/pull/419) Add `PowerRate` quantity. * [#420](https://github.com/iliekturtles/uom/pull/420) Add `InverseVelocity` quantity. ### Changed * [#314](https://github.com/iliekturtles/uom/issues/314) Update Github actions to use `dtolnay/rust-toolchain`. `actions-rs` is no longer maintained. * [#387](https://github.com/iliekturtles/uom/issues/387) Increase MSRV (minimum supported Rust version) to `1.60.0`. No changes in this release require the new MSRV. ### Fixed * Fix unnecessary qualifications warnings in quantity tests. ## [v0.34.0] — 2022-10-26 This release adds a significant number of new quantities and units as well as a few minor fixes. Many thanks to [adamreichold](https://github.com/adamreichold), [calbaker](https://github.com/calbaker), [Eagle941](https://github.com/Eagle941), [jossriLDR](https://github.com/jossriLDR), [swaits](https://github.com/swaits), [Uzaaft](https://github.com/Uzaaft) [werdahias](https://github.com/werdahias), and [zdimension](https://github.com/zdimension) for pull requests included and issues resolved in this release. Special thanks to [crystal-growth](https://github.com/crystal-growth) for the *thirty nine* pull requests included in this release. ### Added * [#318](https://github.com/iliekturtles/uom/pull/318) Add `particle` units to `AmountOfSubstance`, `CatalyticActivity`, `CatalyticActivityConcentration`, `MolarConcentration`, `MolarEnergy`, and `MolarHeatCapacity` quantities. * [#319](https://github.com/iliekturtles/uom/pull/319) Add `MolarFlux` quantity. * [#322](https://github.com/iliekturtles/uom/pull/322) Add `DiffusionCoefficient` quantity. * [#323](https://github.com/iliekturtles/uom/pull/323) Add `DynamicViscosity` quantity. * [#324](https://github.com/iliekturtles/uom/pull/324) Add atomic units of energy, mass, length, electric charge, and current. * [#325](https://github.com/iliekturtles/uom/pull/325) Add `Action` quantity. * [#326](https://github.com/iliekturtles/uom/pull/326) Add `ElectricField` quantity. * [#327](https://github.com/iliekturtles/uom/pull/327) Add `ElectricDipoleMoment` and `ElectricQuadrupoleMoment` quantities. * [#329](https://github.com/iliekturtles/uom/pull/329) Add `ElectricalMobility` quantity. * [#330](https://github.com/iliekturtles/uom/pull/330) Add `ElectricalResistivity` quantity. * [#331](https://github.com/iliekturtles/uom/pull/331) Add `ElectricalConductivity` quantity. * [#332](https://github.com/iliekturtles/uom/pull/332) Add `ElectricPermittivity` quantity. * [#333](https://github.com/iliekturtles/uom/pull/333) Add `ElectricCurrentDensity` quantity. * [#334](https://github.com/iliekturtles/uom/pull/334) Add `ArealNumberDensity`, `LinearNumberDensity`, and `VolumetricNumberDensity` quantities. * [#335](https://github.com/iliekturtles/uom/pull/335) Add `ReciprocalLength` quantity. * [#336](https://github.com/iliekturtles/uom/pull/336) Add `MassFlux` quantity. * [#337](https://github.com/iliekturtles/uom/pull/337) Add `MagneticPermeability` quantity. * [#339](https://github.com/iliekturtles/uom/pull/339) Add `ArealNumberRate`, `LinearNumberRate`, and `VolumetricNumberRate` quantities. * [#341](https://github.com/iliekturtles/uom/pull/341) Add `ArealMassDensity`, `LinearMassDensity`, and `VolumetricMassDensity` quantities. * [#342](https://github.com/iliekturtles/uom/pull/342) Add `SurfaceElectricCurrentDensity` quantity. * [#343](https://github.com/iliekturtles/uom/pull/343) Add `MagneticMoment` quantity. * [#344](https://github.com/iliekturtles/uom/pull/344) Add `ElectricChargeArealDensity`, `ElectricChargeLinearDensity`, and `ElectricChargeVolumetricDensity` quantities. * [#345](https://github.com/iliekturtles/uom/pull/345) Add `ElectricDisplacementField` quantity. * [#346](https://github.com/iliekturtles/uom/pull/346) Add `MagneticFieldStrength` quantity. * [#347](https://github.com/iliekturtles/uom/pull/347) Add `MolarVolume` quantity. * [#348](https://github.com/iliekturtles/uom/pull/348) Add `ElectricFlux` quantity. * [#349](https://github.com/iliekturtles/uom/pull/349) Add `TemperatureGradient` quantity. * [#350](https://github.com/iliekturtles/uom/pull/350) Add `LinearPowerDensity` and `VolumetricPowerDensity` quantities as well as additional `HeatFluxDensity` units. * [#351](https://github.com/iliekturtles/uom/pull/351) Add `standard_gravity` unit to `Acceleration`. * [#352](https://github.com/iliekturtles/uom/pull/352) Add `SpecificArea` and `SpecificVolume` quantities. * [#353](https://github.com/iliekturtles/uom/pull/353) Add `boltzmann_constant` unit to `HeatCapacity` and `molar_gas_constant` unit to `MolarHeatCapacity`. * [#354](https://github.com/iliekturtles/uom/pull/354) Add `TemperatureCoefficient` quantity. * [#355](https://github.com/iliekturtles/uom/pull/355) Add `ArealDensityOfStates`, `LinearDensityOfStates`, and `VolumetricDensityOfStates` quantities. * [#356](https://github.com/iliekturtles/uom/pull/356) Add `MomentOfInertia` quantity. * [#358](https://github.com/iliekturtles/uom/pull/358) Add molar flow rate units to `AmountOfSubstance` and `CatalyticActivity`. * [#361](https://github.com/iliekturtles/uom/pull/361) Add `atomic_unit_of_velocity`, `natural_unit_of_velocity` and `speed_of_light_in_vacuum` units to `Velocity`. * [#368](https://github.com/iliekturtles/uom/pull/368) Add quantities for `Radioactivity`, `MolarRadioactivity`, and `SpecificRadioactivity` as well as additional `VolumetricNumberRate` units. * [#369](https://github.com/iliekturtles/uom/pull/369) Add `VolumetricHeatCapacity` quantity as well as additional `HeatCapacity` and `SpecificHeatCapacity` units. * [#370](https://github.com/iliekturtles/uom/pull/370) Add `Molality` quantity. * [#388](https://github.com/iliekturtles/uom/pull/388) Add `FrequencyDrift` quantity. * [#396](https://github.com/iliekturtles/uom/pull/396) Add `SpecificPower` quantity. * [#399](https://github.com/iliekturtles/uom/pull/399) Add `liter per minute` unit to `VolumeRate` and `newton per square millimeter` unit to `Pressure`. * [#405](https://github.com/iliekturtles/uom/pull/405) Add `ton_per_minute`, `ton_per_hour`, and `ton_per_day` units to `MassRate`. * [#408](https://github.com/iliekturtles/uom/pull/408) Add `ThermalConductance` quantity. ### Fixed * [#383](https://github.com/iliekturtles/uom/issues/383) Fix typos in past release notes. * [#392](https://github.com/iliekturtles/uom/issues/392) Disable certain `Area` and `Volume` tests on ARM CPUs until floating point behavior issues can be resolved. * [#393](https://github.com/iliekturtles/uom/pull/393) Fix typo in the spelling of `millijoule`. * Correct volume rate unit tests. ## [v0.33.0] — 2022-06-28 This release adds one new quantity, `Absement`. Two new underlying storage types, `Complex32` and `Complex64`. Eight new exponential and logarithmic functions on `Ratio` and changes to use `#[must_use]` and `#[non_exhaustive]`. Many thanks to [adamreichold](https://github.com/adamreichold), [gonzaponte](https://github.com/gonzaponte), [jacg](https://github.com/jacg), [nick-pascucci-spire](https://github.com/nick-pascucci-spire), and [TobTobXX](https://github.com/TobTobXX) for pull requests included and issues resolved in this release. ### Added * [#284](https://github.com/iliekturtles/uom/pull/284), [#285](https://github.com/iliekturtles/uom/pull/285) `Absement` quantity added. * [#287](https://github.com/iliekturtles/uom/pull/287) Add support for `Complex32` and `Complex64` as underlying storage types. * [#290](https://github.com/iliekturtles/uom/pull/290) Implement `exp2`, `exp_m1`, `exp`, `ln_1p`, `ln`, `log10`, `log2`, and `log` for `Ratio`. * [#306](https://github.com/iliekturtles/uom/pull/306) Add missing `#[must_use]` on all methods returning a value. `must_use_candidate` and `return_self_not_must_use` clippy lints are now enabled to ensure future methods include the attribute. ### Changed * [#272](https://github.com/iliekturtles/uom/pull/272) Improve documentation on how to enable `serde` for `big*` and `rational*` underlying storage types. * Enable `#[non_exhaustive]` on `Units` `enum`s. The `#[doc(hidden)] __nonexhaustive` trick is not longer used. ## [v0.32.0] — 2022-01-14 This release adds one new quantity, `MolarHeatCapacity`, a new trait, `ConstZero`, and many internal improvements. The `quickcheck` 1.0 update uncovered a number of issues with floating point precision that were able to be resolved while still maintaining zero-cost guarantees. Many thanks to [adamreichold](https://github.com/adamreichold), [B-Reif](https://github.com/B-Reif), [remilauzier](https://github.com/remilauzier), and [T-Bakker](https://github.com/T-Bakker) for pull requests included and issues resolved in this release. ### Added * [#250](https://github.com/iliekturtles/uom/pull/250) Add `ConstZero` trait which is implemented by `Quantity`. * [#263](https://github.com/iliekturtles/uom/pull/263) `MolarHeatCapacity` quantity added. ### Changed * [#258](https://github.com/iliekturtles/uom/pull/258) Use `RUSTFLAGS="-D warnings"` in CI to ensure that `rustc` warnings and caught and fail their respective workflows. * [Breaking] Rename `Conversion::into_conversion` to `Conversion::conversion`. Name change resolves `Clippy` `wrong_self_convention` warnings. * [#260](https://github.com/iliekturtles/uom/pull/260) Increase minimum supported `rustc` version to 1.43.0. Required to support `quickcheck` 1.0. * [#260](https://github.com/iliekturtles/uom/pull/260) Update to `quickcheck` 1.0. Change required the MSRV update as well as refactoring `from_base`, `to_base`, and multiple tests. The `from_base` and `to_base` changes provide better floating point precision while still maintaining zero-cost guarantees. The test changes better handle floating point precision issues as well as the wider range of values generated by `quickcheck` 1.0's `Arbitrary` implementation. * [#268](https://github.com/iliekturtles/uom/pull/268) Clarify `powi` documentation. ### Deprecated * [#260](https://github.com/iliekturtles/uom/pull/260) Deprecate `try-from` feature. The feature will be removed in a future release of `uom`. Functionality previously exposed by the feature is now enabled by default. ### Fixed * [#252](https://github.com/iliekturtles/uom/pull/252) Fix links within the documentation to use https. Many previously used http and were broken. * [#260](https://github.com/iliekturtles/uom/pull/260) Fix `TryFrom for Time`. Previously the conversion used the `Duration`'s subsecond microseconds as nanoseconds. The conversion now correct uses the subsecond nanoseconds. ## [v0.31.1] — 2021-03-01 This release corrects documentation issues and documents fewer underlying storage types on docs.rs so that container time and memory limits are not exceeded. ### Added * [#241](https://github.com/iliekturtles/uom/issues/241) Run `rustdoc` as part of tool checks and resolve previously ignored warnings. ### Changed * [#241](https://github.com/iliekturtles/uom/issues/241) Document fewer underlying storage types on docs.rs so that container time and memory limits are not exceeded. Previous releases documented all features and caused documentation to fail to build. ## [v0.31.0] — 2021-01-05 This release adds a new macro, `unit!`, to allow for units to be defined outside of the `quantity!` macro as well as a `Units` enum for each quantity. A number of standard library traits are implemented. Build regressions caused by issues with the CI system and changes in Rust are now fixed. Many thanks to [bheisler](https://github.com/bheisler), [CreepySkeleton](https://github.com/CreepySkeleton), [DusterTheFirst](https://github.com/DusterTheFirst), [Lucretiel](https://github.com/Lucretiel), and [neoeinstein](https://github.com/neoeinstein) for pull requests included and issues resolved in this release. ### Added * [#173](https://github.com/iliekturtles/uom/issues/173) Allow new units to be defined using `unit!` outside of `quantity!`. When using the pre-built SI system included with `uom` this macro allows for new units to quickly be defined without requiring a release. [Pull requests](https://github.com/iliekturtles/uom/pulls) to add new units upstream area always greatly appreciated. * [#215](https://github.com/iliekturtles/uom/pull/215) Add `Units` enum and `fn units() -> impl Iterator` function for each quantity. * [#227](https://github.com/iliekturtles/uom/issues/227) Ensure `UnwindSafe` and `RefUnwindSafe` are implemented. * [#217](https://github.com/iliekturtles/uom/pull/217) Add trait implementations for `Display` and `Error` to `ParseQuantityError`. ### Changed * [#214](https://github.com/iliekturtles/uom/pull/214) The `FromStr` implementation for quantities now supports the unit singular and plural descriptions in addition to the unit abbreviation. * [#225](https://github.com/iliekturtles/uom/pull/225) Convert CI to use Github Actions. This change fixes a number of problems with the old system and greatly improves build times. * [#223](https://github.com/iliekturtles/uom/issues/223) Correct build regressions introduced while no test job was run with the old CI system. ## [v0.30.0] — 2020-10-17 This release adds a new quantity, `RadiantExposure`, implements `Unpin` for `Quantity` and upgrades `uom` to the 2018 edition. These changes also include an increase of the minimum supported `rustc` to 1.37.0. Many thanks to [nicodemus26](https://github.com/nicodemus26) and (Michael-F-Bryan)[https://github.com/Michael-F-Bryan] for pull requests included and issues resolved in this release. ### Added * [#202](https://github.com/iliekturtles/uom/pull/202) `RadiantExposure` quantity added. * [#204](https://github.com/iliekturtles/uom/issues/204) Implement `Unpin` for `Quantity`. ### Changed * [#206](https://github.com/iliekturtles/uom/pull/206) Upgrade `uom` to compile using the 2018 edition. Generated code still supports both the 2015 and 2018 edition. * [#207](https://github.com/iliekturtles/uom/pull/207) Increase minimum supported `rustc` version to 1.37.0. Required to support upgrading to the latest dependencies and to allow for the Kleene `?` "at most one" repetition operator. ## [v0.29.0] — 2020-08-06 This release includes a number of changes for `Angle`, the addition of `SolidAngle`, and a new units for `Energy` and `Luminance`. Many thanks to [adamreichold](https://github.com/adamreichold), [AnickaBurova](https://github.com/AnickaBurova), and [Atmelfan](https://github.com/Atmelfan) for pull requests included and issues resolved in this release. ### Added * [#196](https://github.com/iliekturtles/uom/pull/196) `SolidAngle` quantity added. * [#191](https://github.com/iliekturtles/uom/pull/191) Add constants to `Angle` and `SolidAngle` representing half and full turns. * [#194](https://github.com/iliekturtles/uom/pull/194) Add `foot-candle` unit to `Luminance`. * [#200](https://github.com/iliekturtles/uom/pull/200) `electronvolt`-based `Energy` units added. ### Changed * [#192](https://github.com/iliekturtles/uom/issues/192) Use `f{32|64}::powi` instead of `Typenum::Pow::powi`. * [#123](https://github.com/iliekturtles/uom/issues/123) Change examples to use `Display` instead of `Debug`. ### Removed * [#188](https://github.com/iliekturtles/uom/issues/188) [Breaking] Remove `From`/`Into` impls for `Angle` and `SolidAngle`. ## [v0.28.0] — 2020-05-21 This release includes a number of trigonometric improvements as well as new units for `Time`. Many thanks to [adamreichold](https://github.com/adamreichold) and [Aehmlo](https://github.com/Aehmlo) for pull requests included and issues resolved in this release. ### Added * [#182](https://github.com/iliekturtles/uom/pull/182) Add inverse trigonometric functions to `Ratio` (`acos`, `acosh`, `asin`, `asinh`, `atan`, `atanh`) and `Angle` (`atan2`). * [#184](https://github.com/iliekturtles/uom/pull/184) Tropical and sidereal units added to `Time`. ### Changed * [#186](https://github.com/iliekturtles/uom/pull/186) Make `hypot` available for all quantities, not just `Length`. * [#187](https://github.com/iliekturtles/uom/pull/187) [Breaking] Change trigonometric functions to return `Ratio` instead of the underlying storage type so that identities like `x.sin().asin() == x` are well-typed. ## [v0.27.0] — 2020-02-14 This release adds a number of quantities. ### Added * [#167](https://github.com/iliekturtles/uom/pull/167) `CatalyticActivity`, `CatalyticActivityConcentration`, `MassConcentration`, and `MolarConcentration` quantities added. * [#175](https://github.com/iliekturtles/uom/pull/175) `Curvature` quantity added. ## [v0.26.0] — 2019-11-04 This release adds a number of thermodynamic quantities in addition to `TryFrom` implementations for `Time` and trigonometric functions on `Angle`. ### Added * [#164](https://github.com/iliekturtles/uom/pull/164) `HeatFluxDensity` quantity added. * [#155](https://github.com/iliekturtles/uom/pull/155) `HeatCapacity`, `HeatTransfer`, `MolarEnergy`, `MolarMass`, `SpecificHeatCapacity`, `ThermalConductivity` quantities added. * [#150](https://github.com/iliekturtles/uom/pull/150) `TryFrom` implemented between `std::time::Duration` and `uom::si::Time`. * [#151](https://github.com/iliekturtles/uom/pull/151) Trigonometric functions added to `Angle`. ### Changed * Increase minimum supported `rustc` version to 1.31.0. Required to because of backwards incompatibilities with `Cargo.toml` `edition` keyword. `cfg-if` introducted the keyword in a minor version update and other issues with the keyword prompted the update. ## [v0.25.0] — 2019-08-12 This release includes the long-requested `Information` and `InformationRate` quantities as well as support for `i128`/`u128` as underlying storage types. A number of documentation updates, including for the 9th edition of the SI, are also included. ### Added * [#31](https://github.com/iliekturtles/uom/issues/31) `Information` (`bit`, `byte`, ...) and `InformationRate` (`bit/s`, `byte/s`, ...) quantities added. Units for both SI (`kilo`, `mega`, ...) and binary (`kibi`, `mebi`, ...) prefixes are included. * [#85](https://github.com/iliekturtles/uom/issues/85) Add support for `i128` and `u128` as underlying storage types. * [#160](https://github.com/iliekturtles/uom/pull/160) `AngularJerk` quantity added. ### Changed * [#20](https://github.com/iliekturtles/uom/issues/20) Document generic parameters. * [#21](https://github.com/iliekturtles/uom/issues/21) Move links inline for trait methods to work around documentation generation bug. * [#111](https://github.com/iliekturtles/uom/issues/111) Update documentation for SI base units for the 9th edition of the SI. * [#127](https://github.com/iliekturtles/uom/issues/127) Remove superscripts for power 1 to keep all SI documentation consistent. ## [v0.24.0] — 2019-06-20 This release fixes two separate issues to ensure that zero-cost code is generated. Many thanks to [raimundomartins](https://github.com/raimundomartins), [apopiak](https://github.com/apopiak), and [gnzlbg](https://github.com/gnzlbg) for pull requests included and issues resolved in this release. ### Added * [#145](https://github.com/iliekturtles/uom/issues/145) Add `#[repr(transparent)]` to `Quantity` to ensure that the ABI of the underlying storage type is used instead of struct ABI in FFI contexts. ### Changed * [#148](https://github.com/iliekturtles/uom/pull/148) Increase minimum supported `rustc` version to 1.28.0. Required to support `#[repr(transparent)]`. ### Fixed * [#143](https://github.com/iliekturtles/uom/issues/143) Correct `to_base` and `from_base` to be zero-cost for float storage types. * [#147](https://github.com/iliekturtles/uom/pull/147) Correct typos in README and crate-level documentation. ## [v0.23.1] — 2019-05-29 This release fixes an issue with the `autoconvert` feature introduced in [v0.23.0]. Many thanks to [dmit](https://github.com/dmit) for pull requests included in this release. ### Fixed * [#141](https://github.com/iliekturtles/uom/issues/141) `From` implementations to convert between quantities of different kinds now correctly use the `autoconvert` feature and no longer cause a compile error when the feature is disabled. ## [v0.23.0] — 2019-05-13 This release adds three new quantities, `AngularAcceleration`, `AngularVelocity`, and `Torque`. Changes to make `Kind`s more ergonomic to use are also included along with documentation changes. Many thanks to [dunmatt](https://github.com/dunmatt/) and [Aehmlo](https://github.com/Aehmlo) for pull requests included in this release. ### Added * [#136](https://github.com/iliekturtles/uom/pull/136) `AngularAcceleration` quantity added. * [#135](https://github.com/iliekturtles/uom/pull/135) `AngularVelocity` quantity added. * [#117](https://github.com/iliekturtles/uom/issues/117) `Torque` quantity added. * Introduce `AngleKind` and `si::marker` to hold SI specific marker traits. `From` implementations for `AngleKind` added to more easily convert between `uom::Kind` and `si::marker::AngleKind`. * Allow documentation to be specified for base quantities in the `system!` macro. Documentation for the seven base SI quantities added. ### Changed * [#138](https://github.com/iliekturtles/uom/issues/138) Maintain kind when multiplying a number by a quantity. Multiplying a quantity by a number already maintains kind. * [#130](https://github.com/iliekturtles/uom/pull/130) Rename `Density` to `MassDensity`. A type alias for `Density` is available for backwards compatibility. * [#127](https://github.com/iliekturtles/uom/issues/127) Make all SI quantity documentation follow a single, consistent format. ### Deprecated * [#130](https://github.com/iliekturtles/uom/pull/130) `Density` has been renamed to `MassDensity` and is deprecated. `Density` will be removed in some future release. ## [v0.22.2] — 2019-04-28 This release adds `Angle` and `Jerk` quantities along with unit additions and conversion precision improvements to `Acceleration` and `Velocity`. Many thanks to [dunmatt](https://github.com/dunmatt/) and [nicodemus26](https://github.com/nicodemus26/) respectively. ### Added * [#89](https://github.com/iliekturtles/uom/issues/89) `Angle` quantity added. * [#128](https://github.com/iliekturtles/uom/issues/128) `Jerk` quantity added. `Acceleration` and `Velocity` units added and precision for some existing units improved. ### Changed * Continuous integration setup updated and improved. * Rust 1.34.0 is now used for `rustfmt`, `clippy`, and `tarpaulin` jobs. * `rustfmt` configuration updated. * `clippy` configuration corrected to run for all packages. ## [v0.22.1] — 2019-04-02 This release adds additional `liter`-based `VolumeRate` units. ### Added * [#121](https://github.com/iliekturtles/uom/pull/121) `Liter`-based `VolumeRate` units added. ## [v0.22.0] — 2019-03-30 This release adds the `Momentum` quantity and additional `liter`-based `volume` units. ### Added * [#114](https://github.com/iliekturtles/uom/issues/114) `Momentum` quantity added. * [#116](https://github.com/iliekturtles/uom/pull/116) `Liter`-based `volume` units added. ### Changed * Continuous integration setup updated and improved. * Rust 1.33.0 is now used for `rustfmt`, `clippy`, and `tarpaulin` jobs. * The deny warnings job is joined into the `clippy` job. * The stable + tests job has been updated to catch errors with non-default underlying storage types in SI quantity tests. ### Fixed * [#119](https://github.com/iliekturtles/uom/issues/119) Macros corrected to generate valid code for both 2015 and 2018 editions. Previously the doc test on the `$quantities!` macro would fail in a Rust 2018 crate. A new test crate, `edition_check`, was added to ensure `uom` remains usable in Rust 2018 code. ## [v0.21.1] — 2019-03-03 This release adds a few new units for `ElectricCharge` and `Energy`. ### Added * [#112](https://github.com/iliekturtles/uom/pull/112) Additional `ElectricCharge` and `Energy` units added. ## [v0.21.0] — 2019-01-13 This release adds display tools for quantities resolving another long-standing issue, [#13](https://github.com/iliekturtles/uom/issues/13). ### Added * [#13](https://github.com/iliekturtles/uom/issues/13) Add display tools for quantities. Allows `Quantity` to be formatted with the standard library formatting traits: `Binary`, `Debug`, `Display`, `LowerExp`, `LowerHex`, `Octal`, `UpperExp`, `UpperHex`. ### Changed * Improve continuous integration setup. * Update `clippy` and `rustfmt` jobs to use the now stable non `-preview` components. * Run OSX and Windows builds on TravisCI. * Improve individual job build time by reducing unnecessary cached data. ## [v0.20.1] — 2018-09-13 This release resolves nightly rustc error E0659 the base.rs example caused by [rust-lang/rust](https://github.com/rust-lang/rust) pull request [#52841](https://github.com/rust-lang/rust/pull/52841) "resolve: Implement prelude search for macro paths, implement tool attributes." ## [v0.20.0] — 2018-09-06 This release resolves long-standing issue [#3](https://github.com/iliekturtles/uom/issues/3) to implement thermodynamic temperature conversions (e.g. Celsius to Fahrenheit). Support is also added for multiple quantities of the same dimension (e.g. thermodynamic temperature and temperature interval, ratio and angle). The release also contains a number of internal changes including a reorganization of tests into multiple files and updated CI setup to provide faster builds and more feature test coverage. ### Added * [#3](https://github.com/iliekturtles/uom/issues/3) Implement thermodynamic temperature conversions (e.g. Celsius to Fahrenheit). Extend the `quantity!` macro to accept a coefficient and optional constant factor in the `$conversion` parameter to support these conversions. * [#14](https://github.com/iliekturtles/uom/issues/14) Implement `FromStr`. * [#78](https://github.com/iliekturtles/uom/issues/78) Add a `Kind` associated type to `Dimensions`.The new `Kind` associated type, defaulting to `uom::Kind`, allows for multiple quantities that have the same dimensions. Quantities of different kinds are not comparable. The marker traits implemented by a quantity's `Kind` control which operations are automatically implemented. * [#95](https://github.com/iliekturtles/uom/issues/95) `TemperatureInterval` quantity added. Includes `Add`, `AddAssign`, `Sub`, and `SubAssign` implementations between thermodynamic temperature and temperature interval. ### Changed * [Breaking] Remove unused `_unit: N` parameters and require turbofish syntax for `get`, `floor`, `ceil`, `round`, `trunc`, and `fract` methods of `Quantity`. This is a breaking change and can easily be resolved. e.g. `l.get(meter)` becomes `l.get::()`. * [#98](https://github.com/iliekturtles/uom/issues/98), [#100](https://github.com/iliekturtles/uom/issues/100) Correct `uom` feature hygiene in macro generated code. Previously the `system!` macro generated code that included `#[cfg(feature = "...")]` attributes on code in the crate executing the `system!` macro. With this fix these attributes will be eagerly evaluated and only generate code when the appropriate `uom` feature is enabled. * Spelling corrections for a number of documentation comments and unit abbreviations. ## [v0.19.0] — 2018-06-21 This release adds a number of additional quantities, configures `uom` to use `rustfmt`, and directly references `num` sub-crates to better control feature selection. ### Added * `Capacitance` quantity added. * `ElectricCharge` quantity added. * `ElectricalConductance` quantity added. * `ElectricalResistance` quantity added. * `Inductance` quantity added. * `Luminance` quantity added. * `MagneticFluxDensity` quantity added. * `MagneticFlux` quantity added. ### Changed * [#57](https://github.com/iliekturtles/uom/issues/57) `num` sub-crates `num-traits`, `num-rational`, and `num-bigint` are now directly referenced to control feature selection. `std`, `rational`, and `bigint` support are only included based on `uom` feature selection. * [#80](https://github.com/iliekturtles/uom/issues/80) Setup `rustfmt` so that `uom` code can be automatically formatted and builds are gated on changes not breaking formatting conventions. ## [v0.18.0] — 2018-05-10 This release contains a significant number of new quantities and units, compile time improvements, and a few bug fixes. See below for full details. Many thanks to [Aehmlo](https://github.com/Aehmlo/) for all of the new quantities and units. [radix](https://github.com/radix) for the `autoconvert` feature. [Nemo157](https://github.com/Nemo157) for hygiene fixes in the `storage_types!` macro. ### Added * [#54](https://github.com/iliekturtles/uom/issues/54) [Breaking] Add an `autoconvert` feature, enabled by default, which allows for operations between quantities with different base units. `autoconvert` enabled is the same functionality as prior versions of `uom`. Disabling the feature only allows for quantities with the same base units to directly interact. The feature has been added to account for current compiler limitations where zero-cost code is not generated for non-floating point underlying storage types. With the feature disabled more optimal code will be generated for integral types. This feature will likely have no effect and subsequently be deprecated and removed once `const fn` and specialization are stabilized. * [#61](https://github.com/iliekturtles/uom/issues/61) [Breaking] The `storage_types!` macro now always uses underlying storage type features from the `uom` crate instead of the crate where the macro is executed. * [#2](https://github.com/iliekturtles/uom/issues/2) Additional `Mass` units added. * [#5](https://github.com/iliekturtles/uom/issues/5) Additional `Velocity` units added. * [#6](https://github.com/iliekturtles/uom/issues/6) Additional `Area` units added. * [#7](https://github.com/iliekturtles/uom/issues/7) Additional `Volume` units added. * [#8](https://github.com/iliekturtles/uom/issues/8) Additional `Force` units added. * [#9](https://github.com/iliekturtles/uom/issues/9) Additional `Acceleration` units added. * [#30](https://github.com/iliekturtles/uom/issues/30) Additional `Frequency` units added. * [#64](https://github.com/iliekturtles/uom/issues/64) `Ratio` (dimensionless) quantity added. Includes `From for V` and `From for Ratio` implementations to allow for easy conversions between `Ratio` and the underlying storage type. * [#66](https://github.com/iliekturtles/uom/issues/66) `Energy` quantity added. * [#67](https://github.com/iliekturtles/uom/issues/67) `AvailableEnergy` quantity added. * [#68](https://github.com/iliekturtles/uom/issues/68) `Density` quantity added. * [#69](https://github.com/iliekturtles/uom/issues/69) `Power` quantity added. * [#70](https://github.com/iliekturtles/uom/issues/70) `Pressure` quantity added. * [#71](https://github.com/iliekturtles/uom/issues/71) `MassRate` quantity added. * [#72](https://github.com/iliekturtles/uom/issues/72) `VolumeRate` quantity added. * [#74](https://github.com/iliekturtles/uom/issues/74) `ElectricPotential` quantity added. * [#75](https://github.com/iliekturtles/uom/issues/75) Additional `ElectricCurrent` units added. ### Changed * [#52](https://github.com/iliekturtles/uom/issues/52) Type aliases generated by the `storage_type!` macro are now public. e.g. `pub type V = f32;`. This change drastically reduces compile times, especially when multiple underlying storage types are enabled. * Dimension documentation for `ElectricCurrent` corrected to no longer references `AmountOfSubstance` and units smaller than `milliampere` have corrected abbreviations and descriptions. ### Removed * [#15](https://github.com/iliekturtles/uom/issues/15) [Breaking] Remove `Product` implementation for `Quantity`. The product of a quantity is not that same quantity. e.g. `Length * Length = Area`. ## [v0.17.0] — 2018-03-14 This release implements a number of common traits from the standard library, the [`num`](https://crates.io/crates/num) crate, and the [`serde`](https://crates.io/crates/serde) crate. ### Added * [#16](https://github.com/iliekturtles/uom/issues/16) Implement `Default`. * [#17](https://github.com/iliekturtles/uom/issues/17) Implement `PartialEq`. * [#50](https://github.com/iliekturtles/uom/issues/50) Implement `Eq`. * [#18](https://github.com/iliekturtles/uom/issues/18) Implement `PartialOrd`. * [#51](https://github.com/iliekturtles/uom/issues/51) Implement `Ord`. * [#56](https://github.com/iliekturtles/uom/issues/56) Implement `Sum`. * [#15](https://github.com/iliekturtles/uom/issues/15) Implement `Product`. * [#26](https://github.com/iliekturtles/uom/issues/26) Implement `num::Zero`. * [#35](https://github.com/iliekturtles/uom/issues/35) Implement `num::Saturating`. * [#37](https://github.com/iliekturtles/uom/issues/37) Implement `serde::Serialize` and `serde::Deserialize`. Disabled by default. Enabled with the `use_serde` feature. ## [v0.16.0] — 2017-12-21 This release contains significant changes in order to support underlying storage types that implement the `Num` trait beyond `f32` and `f64`. Many changes are breaking: marker traits are simplified and fewer macros are exported. New storage types are not enabled by default and can be used by including the corresponding feature. See the changes below for full details. ### Added * Add missing `#[derive(Hash)]` attributes. * [#29](https://github.com/iliekturtles/uom/issues/29) A new macro, `storage_types!`, is now available to duplicate code on a per-storage type basis. See macro documentation for full details. The minimum supported `rustc` version is now 1.20.0. ### Changed * [#29](https://github.com/iliekturtles/uom/issues/29) Underlying storage type now uses the `Num` trait from the [`num`](https://crates.io/crates/num) crate instead of fixed implementations for `f32` and `f64`. Features for all types implementing `Num` have been added and control the availability of the type as an underlying storage type: `usize`, `u8`, `u16`, `u32`, `u64`, `isize`, `i8`, `i16`, `i32`, `i64`, `bigint`, `biguint`, `rational`, `rational32`, `rational64`, `bigrational`, `f32`, and `f64`. For compile time reasons only `f32` and `f64` are enabled by default. Tests are implemented for all underlying storage types but don't account for minimum or maximum values and will fail for non-float types where the conversion factor overflows the type's limits. A future release will correct this. * [#29](https://github.com/iliekturtles/uom/issues/29) [Breaking] Traits and structs generated by the `system!` macro have been significantly changed in order to support non-float underlying storage types. * `Dimension` changed to directly include associated types for quantity dimensions. * `Units` is now only parameterized on `V` and contains associated types for base units. * `Conversion` has been removed and replaced with `uom::Conversion`. * `$quantities<...>` has been removed. Quantity dimensions are now directly in the `Dimension` trait. * `BaseUnits<...>` has been removed. Base units are not directly in the `Units` trait. * `uom::Conversion` added to replace `Conversion` and gives access to a unit's conversion factor. * `uom::ConversionFactor` added to represent conversion factors for underlying storage types where the type can't be used (e.g. `i32`'s conversion factor is represented as `Rational32`.) * [Breaking] Macro usage and definitions have been simplified and consolidated. `quantities!`, `replace_ty!`, and `unit!` have been consolidated as "private" match arms of their calling macro. In order to reduce the chance of macro name collisions `$quantities!` is the only remaining generated exported macro (e.g. `ISQ!` for the `si` system). Generated macros for each quantity no longer exist. These changes make it easier to have multiple systems containing quantities with the same names. In order to support this change quantities in the `units` block of the `system!` macro must always be prefixed by the quantity's module (e.g. `length::Length`). Prefixing the module with the `mod` keyword instructs the `system!` macro not to generate a `#[macro_use] pub mod $module;` statement. ## [v0.15.0] — 2017-07-05 This release adds additional `Time` units; `Frequency`, `Force`, and `Volume` quantities; and numerous floating point methods such as `min`, `max`, and `powi`. ### Added * [#4](https://github.com/iliekturtles/uom/issues/4) Additional `Time` units added. * Add missing `giga` units. e.g. `gigameter`. * [#11](https://github.com/iliekturtles/uom/issues/11) Add floating point classification methods `classify`, `is_finite`, `is_infinte`, `is_nan`, and `is_normal` for `Quantity`. * [#11](https://github.com/iliekturtles/uom/issues/11) Add floating point fractional methods `floor`, `ceil`, `round`, `trunc`, and `fract` for `Quantity`. * [#11](https://github.com/iliekturtles/uom/issues/11) Add floating point comparison methods `max` and `min` for `Quantity`. * [#11](https://github.com/iliekturtles/uom/issues/11) Add floating point `mul_add` method for `Quantity`. * [#11](https://github.com/iliekturtles/uom/issues/11) Add floating point `powi` method for `Quantity`. * [#7](https://github.com/iliekturtles/uom/issues/7) `Volume` quantity added. Additional units still need to be added. * [#8](https://github.com/iliekturtles/uom/issues/8) `Force` quantity added. Additional units still need to be added. * [#30](https://github.com/iliekturtles/uom/issues/30) `Frequency` quantity added. Additional units still need to be added. ## [v0.14.0] — 2017-05-30 ### Added * [Breaking] A new feature, `std`, is now available and is enabled by default. `uom` can still be compiled with `no_std` by using `--no-default-features` when compiling the crate or `default-features = false` in the `dependencies` section of `Cargo.toml` * [#11](https://github.com/iliekturtles/uom/issues/11) `cbrt`, `recip`, and `sqrt` are implemented for `Quantity`. ### Changed * [#28](https://github.com/iliekturtles/uom/issues/28) `Quantity` fields made public in order to allow library users to create `const` values and instances of non-named quantities. e.g. `const TIME_STEP: Time = Quantity { dimension: PhantomData, units: PhantomData, value: 0.1 };` This functionality will be deprecated and subsequently removed once the [`const fn`](https://github.com/rust-lang/rust/issues/24111) feature is stabilized. * Tests now run for all enabled underlying storage types (`f32`, `f64`). ### Fixed * Fixed incorrect conversion factor when multiplying or dividing `Quantity`s with different base units. ## [v0.13.0] — 2017-04-20 This release adds numerous tests both for code generated by the `quantity!`, `system!`, and `$quantities!` macros as well as derived quantities. Fixes for issues found during testing noted below. Quantity implementations for `Area` and `Acceleration` also added. ### Added * [#6](https://github.com/iliekturtles/uom/issues/6) `Area` quantity added. Additional units still need to be added. * [#9](https://github.com/iliekturtles/uom/issues/9) `Acceleration` quantity added. Additional units still need to be added. ### Changed * [Breaking] Remove the unused `_unit` parameter from `Quantity::new` and so summon the turbofish. e.g. `Length::new(1.0, meter)` becomes `Length::new::(1.0)`. * [#22](https://github.com/iliekturtles/uom/issues/22) Change `impl Debug` for `Quantity` to use precision information. Previously the implementation checked the `alternate` flag which has no affect on printing raw floats. * [#27](https://github.com/iliekturtles/uom/issues/27) Change superscripts in documentation to the format supported by `pulldown` in anticipation of upcomming `rustdoc` changes. ### Fixed * [#22](https://github.com/iliekturtles/uom/issues/22) Fix `impl Sub` for `Quantity` to be implemented in terms of `-` instead of `+`. ## [v0.12.0] — 2017-04-01 Continuous integration was setup to ensure that `uom` builds on stable, beta, nightly, and 1.15.0 (the minimum `rustc` version). Quantity descriptions, unit abbreviations, and unit descriptions added. Additional length units [added](https://github.com/iliekturtles/uom/commit/d1b969b810a4b3298d4cf93d0a795d922261735b) to demonstrate the simplicity of the process. ### Added * [#1](https://github.com/iliekturtles/uom/issues/1) Additional `Length` units added. * [Breaking] The `quantity!` macro accepts comments on units. To resolve macro parsing ambiguities each unit must be prefixed with an `@`. * [#19](https://github.com/iliekturtles/uom/issues/19) [Breaking] The `quantity!` macro includes the quantity description. The description can be accessed using the `description()` method in quantity submodules. * [#19](https://github.com/iliekturtles/uom/issues/19) [Breaking] The `quantity!` macro includes unit abbreviations as well as singular and plural descriptions. These values can be accessed from new `abbreviation()`, `singular()`, and `plural()` methods on the `Unit` trait. The original `Unit` trait has been renamed `Conversion`. * [#12](https://github.com/iliekturtles/uom/issues/12) `Debug` manually implemented for `Quantity` to show the underlying value and associated units. * Test and compile-fail test modules setup. compile-fail tests for mismatched quantities and units added. ## v0.11.0 — 2017-02-26 Proof-of-concept functionality for type-safe zero-cost dimensional analysis. `uom` [0.11.0] allows for the creation of custom systems or the use of the pre-built SI. Basic mathematical operations are implemented and a minimal set of quantities (length, mass, time...) and units (meter, kilometer, foot, mile, ...) are included. [Unreleased]: https://github.com/iliekturtles/uom/compare/v0.35.0...master [v0.35.0]: https://github.com/iliekturtles/uom/compare/v0.34.0...v0.35.0 [v0.34.0]: https://github.com/iliekturtles/uom/compare/v0.33.0...v0.34.0 [v0.33.0]: https://github.com/iliekturtles/uom/compare/v0.32.0...v0.33.0 [v0.32.0]: https://github.com/iliekturtles/uom/compare/v0.31.1...v0.32.0 [v0.31.1]: https://github.com/iliekturtles/uom/compare/v0.31.0...v0.31.1 [v0.31.0]: https://github.com/iliekturtles/uom/compare/v0.30.0...v0.31.0 [v0.30.0]: https://github.com/iliekturtles/uom/compare/v0.29.0...v0.30.0 [v0.29.0]: https://github.com/iliekturtles/uom/compare/v0.28.0...v0.29.0 [v0.28.0]: https://github.com/iliekturtles/uom/compare/v0.27.0...v0.28.0 [v0.27.0]: https://github.com/iliekturtles/uom/compare/v0.26.0...v0.27.0 [v0.26.0]: https://github.com/iliekturtles/uom/compare/v0.25.0...v0.26.0 [v0.25.0]: https://github.com/iliekturtles/uom/compare/v0.24.0...v0.25.0 [v0.24.0]: https://github.com/iliekturtles/uom/compare/v0.23.1...v0.24.0 [v0.23.1]: https://github.com/iliekturtles/uom/compare/v0.23.0...v0.23.1 [v0.23.0]: https://github.com/iliekturtles/uom/compare/v0.22.2...v0.23.0 [v0.22.2]: https://github.com/iliekturtles/uom/compare/v0.22.1...v0.22.2 [v0.22.1]: https://github.com/iliekturtles/uom/compare/v0.22.0...v0.22.1 [v0.22.0]: https://github.com/iliekturtles/uom/compare/v0.21.1...v0.22.0 [v0.21.1]: https://github.com/iliekturtles/uom/compare/v0.21.0...v0.21.1 [v0.21.0]: https://github.com/iliekturtles/uom/compare/v0.20.1...v0.21.0 [v0.20.1]: https://github.com/iliekturtles/uom/compare/v0.20.0...v0.20.1 [v0.20.0]: https://github.com/iliekturtles/uom/compare/v0.19.0...v0.20.0 [v0.19.0]: https://github.com/iliekturtles/uom/compare/v0.18.0...v0.19.0 [v0.18.0]: https://github.com/iliekturtles/uom/compare/v0.17.0...v0.18.0 [v0.17.0]: https://github.com/iliekturtles/uom/compare/v0.16.0...v0.17.0 [v0.16.0]: https://github.com/iliekturtles/uom/compare/v0.15.0...v0.16.0 [v0.15.0]: https://github.com/iliekturtles/uom/compare/v0.14.0...v0.15.0 [v0.14.0]: https://github.com/iliekturtles/uom/compare/v0.13.0...v0.14.0 [v0.13.0]: https://github.com/iliekturtles/uom/compare/v0.12.0...v0.13.0 [v0.12.0]: https://github.com/iliekturtles/uom/compare/v0.11.0...v0.12.0 uom-0.35.0/CONTRIBUTING.md000064400000000000000000000023061046102023000127430ustar 00000000000000Contributing === Contributions are welcome from everyone. Submit a pull request, an issue, or just add comments to an existing item. The [International Bureau of Weights and Measures][BIPM] is an international standards organization that publishes the [SI Brochure][brochure]. This document defines the [SI] and can be used as a comprehensive reference for changes to `uom`. Conversion factors for non-SI units can be found in NIST [Special Publication 811][nist811]. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as below, without any additional terms or conditions. ### License Licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or ) * MIT license ([LICENSE-MIT](LICENSE-MIT) or ) at your option. [BIPM]: https://www.bipm.org/en/about-us/ [brochure]: https://www.bipm.org/en/publications/si-brochure/ [si]: https://jcgm.bipm.org/vim/en/1.16.html [nist811]: https://www.nist.gov/pml/nist-guide-si-appendix-b9-factors-units-listed-kind-quantity-or-field-science uom-0.35.0/Cargo.lock0000644000000135560000000000100077060ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "aho-corasick" version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ "memchr", ] [[package]] name = "approx" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" dependencies = [ "num-traits", ] [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "env_logger" version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ "log", "regex", ] [[package]] name = "getrandom" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", "wasi", ] [[package]] name = "itoa" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] name = "libc" version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "log" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "num-bigint" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" dependencies = [ "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-complex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" dependencies = [ "num-traits", ] [[package]] name = "num-integer" version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ "autocfg", "num-traits", ] [[package]] name = "num-rational" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" dependencies = [ "autocfg", "num-bigint", "num-integer", "num-traits", ] [[package]] name = "num-traits" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", ] [[package]] name = "quickcheck" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ "env_logger", "log", "rand", ] [[package]] name = "rand" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "rand_core", ] [[package]] name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] [[package]] name = "regex" version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "ryu" version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" [[package]] name = "serde" version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" [[package]] name = "serde_json" version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" dependencies = [ "itoa", "ryu", "serde", ] [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "typenum" version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "uom" version = "0.35.0" dependencies = [ "approx", "num-bigint", "num-complex", "num-rational", "num-traits", "quickcheck", "serde", "serde_json", "static_assertions", "typenum", ] [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" uom-0.35.0/Cargo.toml0000644000000061620000000000100077240ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "uom" version = "0.35.0" authors = ["Mike Boutin "] autobins = true autoexamples = true autotests = true autobenches = true description = "Units of measurement" documentation = "https://docs.rs/uom" readme = "README.md" keywords = [ "units", "measurement", "SI", "dimensional-analysis", "no_std", ] categories = [ "no-std", "science", "value-formatting", ] license = "Apache-2.0/MIT" repository = "https://github.com/iliekturtles/uom" [package.metadata] msrv = "1.60.0" [package.metadata.docs.rs] features = [ "usize", "u32", "u64", "isize", "i32", "i64", "bigint", "biguint", "rational", "rational32", "rational64", "bigrational", "use_serde", ] [[example]] name = "base" required-features = [ "autoconvert", "f32", "si", ] [[example]] name = "mks" required-features = ["f32"] [[example]] name = "si" required-features = [ "f32", "si", ] [[example]] name = "unit" required-features = [ "f32", "si", ] [dependencies.num-bigint] version = "0.4" features = ["std"] optional = true default-features = false [dependencies.num-complex] version = "0.4" features = ["std"] optional = true default-features = false [dependencies.num-rational] version = "0.4" optional = true default-features = false [dependencies.num-traits] version = "0.2" default-features = false [dependencies.serde] version = "1.0" optional = true default-features = false [dependencies.typenum] version = "1.13" [dev-dependencies.approx] version = "0.5" [dev-dependencies.quickcheck] version = "1.0" [dev-dependencies.serde_json] version = "1.0" [dev-dependencies.static_assertions] version = "1.1" [features] autoconvert = [] bigint = ["bigint-support"] bigint-support = [ "num-bigint", "num-rational/num-bigint-std", ] bigrational = ["bigint-support"] biguint = ["bigint-support"] complex-support = ["num-complex"] complex32 = ["complex-support"] complex64 = ["complex-support"] default = [ "autoconvert", "f32", "f64", "si", "std", ] f32 = [] f64 = [] i128 = ["rational-support"] i16 = ["rational-support"] i32 = ["rational-support"] i64 = ["rational-support"] i8 = ["rational-support"] isize = ["rational-support"] rational = ["rational-support"] rational-support = ["num-rational"] rational32 = ["rational-support"] rational64 = ["rational-support"] si = [] std = ["num-traits/std"] try-from = [] u128 = ["rational-support"] u16 = ["rational-support"] u32 = ["rational-support"] u64 = ["rational-support"] u8 = ["rational-support"] use_serde = ["serde"] usize = ["rational-support"] [badges.maintenance] status = "actively-developed" uom-0.35.0/Cargo.toml.orig000064400000000000000000000060411046102023000134010ustar 00000000000000[package] name = "uom" version = "0.35.0" edition = "2018" authors = ["Mike Boutin "] description = "Units of measurement" documentation = "https://docs.rs/uom" #homepage = "" repository = "https://github.com/iliekturtles/uom" readme = "README.md" keywords = ["units", "measurement", "SI", "dimensional-analysis", "no_std"] categories = ["no-std", "science", "value-formatting"] license = "Apache-2.0/MIT" autobins = true autoexamples = true autotests = true autobenches = true [package.metadata.docs.rs] features = ["usize", "u32", "u64", "isize", "i32", "i64", "bigint", "biguint", "rational", "rational32", "rational64", "bigrational", "use_serde"] [package.metadata] msrv = "1.60.0" [badges] maintenance = { status = "actively-developed" } [workspace] members = [ "tests/feature_check", "uom-macros", "tests/edition_check", ] [dependencies] num-traits = { version = "0.2", default-features = false } num-rational = { version = "0.4", optional = true, default-features = false } num-bigint = { version = "0.4", optional = true, default-features = false, features = ["std"] } num-complex = { version = "0.4", optional = true, default-features = false, features = ["std"] } serde = { version = "1.0", optional = true, default-features = false } typenum = "1.13" [dev-dependencies] approx = "0.5" quickcheck = "1.0" serde_json = "1.0" static_assertions = "1.1" [features] default = ["autoconvert", "f32", "f64", "si", "std"] autoconvert = [] usize = ["rational-support"] u8 = ["rational-support"] u16 = ["rational-support"] u32 = ["rational-support"] u64 = ["rational-support"] u128 = ["rational-support"] isize = ["rational-support"] i8 = ["rational-support"] i16 = ["rational-support"] i32 = ["rational-support"] i64 = ["rational-support"] i128 = ["rational-support"] bigint = ["bigint-support"] biguint = ["bigint-support"] rational = ["rational-support"] rational32 = ["rational-support"] rational64 = ["rational-support"] bigrational = ["bigint-support"] complex32 = ["complex-support"] complex64 = ["complex-support"] f32 = [] f64 = [] si = [] std = ["num-traits/std"] # The try-from feature is deprecated and will be removed in a future release of uom. Functionality # previously exposed by the feature is now enabled by default. try-from = [] # The `use_serde` feature exists so that, in the future, other dependency features like num/serde # can be added. However, num/serde is currently left out because it has not yet been updated to # Serde 1.0. It is also necessary to name the feature something other than `serde` because of a # cargo bug: https://github.com/rust-lang/cargo/issues/1286 use_serde = ["serde"] # Internal features to include appropriate num-* crates. rational-support = ["num-rational"] bigint-support = ["num-bigint", "num-rational/num-bigint-std"] complex-support = ["num-complex"] [[example]] name = "base" required-features = ["autoconvert", "f32", "si"] [[example]] name = "mks" required-features = ["f32"] [[example]] name = "si" required-features = ["f32", "si"] [[example]] name = "unit" required-features = ["f32", "si"] uom-0.35.0/LICENSE-APACHE000064400000000000000000000261361046102023000124450ustar 00000000000000 Apache License Version 2.0, January 2004 https://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.uom-0.35.0/LICENSE-MIT000064400000000000000000000020661046102023000121510ustar 00000000000000The MIT License (MIT) Copyright (c) 2019 Mike Boutin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. uom-0.35.0/README.md000064400000000000000000000205331046102023000117730ustar 00000000000000uom === [![Github Actions](https://img.shields.io/github/actions/workflow/status/iliekturtles/uom/ci-full-test-suite.yml?branch=master)](https://github.com/iliekturtles/uom/actions) [![Codecov.io](https://img.shields.io/codecov/c/github/iliekturtles/uom/master)](https://codecov.io/gh/iliekturtles/uom) [![Rustup.rs](https://img.shields.io/badge/rustc-1.60.0%2B-orange.svg)](https://rustup.rs/) [![Crates.io](https://img.shields.io/crates/v/uom.svg)](https://crates.io/crates/uom) [![Crates.io](https://img.shields.io/crates/l/uom.svg)](https://crates.io/crates/uom) [![Documentation](https://img.shields.io/badge/documentation-docs.rs-blue.svg)](https://docs.rs/uom) Units of measurement is a crate that does automatic type-safe zero-cost [dimensional analysis][analysis]. You can create your own systems or use the pre-built [International System of Units][si] (SI) which is based on the [International System of Quantities][isq] (ISQ) and includes numerous [quantities][quantity] (length, mass, time, ...) with conversion factors for even more numerous [measurement units][measurement] (meter, kilometer, foot, mile, ...). No more crashing your [climate orbiter][orbiter]! [analysis]: https://en.wikipedia.org/wiki/Dimensional_analysis [si]: https://jcgm.bipm.org/vim/en/1.16.html [isq]: https://jcgm.bipm.org/vim/en/1.6.html [quantity]: https://jcgm.bipm.org/vim/en/1.1.html [measurement]: https://jcgm.bipm.org/vim/en/1.9.html [orbiter]: https://en.wikipedia.org/wiki/Mars_Climate_Orbiter ## Usage `uom` requires `rustc` 1.60.0 or later. Add this to your `Cargo.toml`: ```toml [dependencies] uom = "0.35.0" ``` and this to your crate root: ```rust extern crate uom; ``` The simple example below shows how to use quantities and units as well as how `uom` stops invalid operations: ```rust extern crate uom; use uom::si::f32::*; use uom::si::length::kilometer; use uom::si::time::second; fn main() { let length = Length::new::(5.0); let time = Time::new::(15.0); let velocity/*: Velocity*/ = length / time; let _acceleration = calc_acceleration(velocity, time); //let error = length + time; // error[E0308]: mismatched types } fn calc_acceleration(velocity: Velocity, time: Time) -> Acceleration { velocity / time } ``` See the [examples](examples) directory for more advanced usage: * [si.rs](examples/si.rs) -- Shows how to use the pre-built SI system. * [base.rs](examples/base.rs) -- Shows how to create a set of `Quantity` type aliases for a different set of base units. See the [Design](#design) section for implications of choosing different base units. * [mks.rs](examples/mks.rs) -- Shows how to create a custom system of quantities. * [unit.rs](examples/unit.rs) -- Shows how to add new units to existing quantities in the pre-build SI system. ## Features `uom` has multiple `Cargo` features for controlling available underlying storage types, the inclusion of the pre-built [International System of Units][si] (SI), support for [Serde][serde], and `no_std` functionality. The features are described below. `f32`, `f64`, `std`, and `si` are enabled by default. Features can be cherry-picked by using the `--no-default-features` and `--features "..."` flags when compiling `uom` or specifying features in Cargo.toml: ```toml [dependencies] uom = { version = "0.35.0", default-features = false, features = [ "autoconvert", # automatic base unit conversion. "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. "complex32", "complex64", # Complex floating point storage types. "f32", "f64", # Floating point storage types. "si", "std", # Built-in SI system and std library support. "use_serde", # Serde support. ] } ``` * `autoconvert` -- Feature to enable automatic conversion between base units in binary operators. Disabling the feature only allows for quantities with the same base units to 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`, `complex32`, `complex64`, `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` with `no_std`. Enabled by default. * `use_serde` -- Feature to enable support for serialization and deserialization of quantities with the [Serde][serde] crate. Disabled by default. [Serde][serde] support for the `big*` and `rational*` underlying storage types requires manually enabling the `serde` feature for the `num-rational` and `num-bigint` crates. To do so, you can add one or both of the following lines to your `Cargo.toml`: ```toml num-rational = { version = "*", features = ["serde"] } num-bigint = { version = "*", features = ["serde"] } ``` [si]: https://jcgm.bipm.org/vim/en/1.16.html [serde]: https://serde.rs/ ## Design Rather than working with [measurement units](https://jcgm.bipm.org/vim/en/1.9.html) (meter, kilometer, foot, mile, ...) `uom` works with [quantities](https://jcgm.bipm.org/vim/en/1.1.html) (length, mass, time, ...). This simplifies usage because units are only involved at interface boundaries: the rest of your code only needs to be concerned about the quantities involved. This also makes operations on quantities (+, -, \*, /, ...) have zero runtime cost over using the raw storage type (e.g. `f32`). `uom` normalizes values to the [base unit](https://jcgm.bipm.org/vim/en/1.10.html) for the 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`, `complex32`, `complex64`, `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 types. For example if the base unit of `length` is `meter` and the underlying storage type is `i32` then values like `1 centimeter` or `1.1 meter` cannot be represented. `1 centimeter` is normalized to `0.01 meter` which can't be stored in an `i32`. `uom` only allows units to be used safely. Users of this library will still need to be aware of implementation details of the underlying storage type including limits and precision. ## Contributing Contributions are welcome from everyone. Submit a pull request, an issue, or just add comments to an existing item. The [International Bureau of Weights and Measures][BIPM] is an international standards organization that publishes the [SI Brochure][brochure]. This document defines the [SI] and can be used as a comprehensive reference for changes to `uom`. Conversion factors for non-SI units can be found in NIST [Special Publication 811][nist811]. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as below, without any additional terms or conditions. ### License Licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or ) * MIT license ([LICENSE-MIT](LICENSE-MIT) or ) at your option. [BIPM]: https://www.bipm.org/en/about-us/ [brochure]: https://www.bipm.org/en/publications/si-brochure/ [si]: https://jcgm.bipm.org/vim/en/1.16.html [nist811]: https://www.nist.gov/pml/nist-guide-si-appendix-b9-factors-units-listed-kind-quantity-or-field-science uom-0.35.0/examples/base.rs000064400000000000000000000013771046102023000136170ustar 00000000000000//! Example showing how to create a set of `Quantity` type aliases for a different set of base //! units. #[macro_use] extern crate uom; use uom::si::length::{centimeter, meter}; use uom::si::time::second; mod cgs { ISQ!(uom::si, f32, (centimeter, gram, second, ampere, kelvin, mole, candela)); } fn main() { let l1 = uom::si::f32::Length::new::(1.0); let l2 = cgs::Length::new::(1.0); let t1 = uom::si::f32::Time::new::(15.0); println!("{}: {:?}", uom::si::length::description(), l1); println!("{}: {:?}", uom::si::length::description(), l2); println!("{:?} + {:?} = {:?}", l1, l2, (l1 + l2)); println!("{:?} + {:?} = {:?}", l2, l1, (l2 + l1)); println!("{:?} / {:?} = {:?}", l2, t1, (l2 / t1)); } uom-0.35.0/examples/mks.rs000064400000000000000000000033121046102023000134660ustar 00000000000000//! Example showing how to create a custom system of quantities. #[macro_use] extern crate uom; use crate::length::{foot, meter}; use uom::fmt::DisplayStyle::Abbreviation; fn main() { let l1 = f32::Length::new::(100.0); println!( "{} = {}", l1.into_format_args(meter, Abbreviation), l1.into_format_args(foot, Abbreviation) ); } #[macro_use] mod length { quantity! { /// Length (base unit meter, m). quantity: Length; "length"; /// Length dimension, m. dimension: Q< P1, // length Z0, // mass Z0>; // time units { @meter: 1.0E0; "m", "meter", "meters"; @foot: 3.048E-1; "ft", "foot", "feet"; } } } #[macro_use] mod mass { quantity! { /// Mass (base unit kilogram, kg). quantity: Mass; "mass"; /// Mass dimension, kg. dimension: Q< Z0, // length P1, // mass Z0>; // time units { @kilogram: 1.0; "kg", "kilogram", "kilograms"; } } } #[macro_use] mod time { quantity! { /// Time (base unit second, s). quantity: Time; "time"; /// Time dimension, s. dimension: Q< Z0, // length Z0, // mass P1>; // time units { @second: 1.0; "s", "second", "seconds"; } } } system! { quantities: Q { length: meter, L; mass: kilogram, M; time: second, T; } units: U { mod length::Length, mod mass::Mass, mod time::Time, } } mod f32 { mod mks { pub use super::super::*; } Q!(self::mks, f32); } uom-0.35.0/examples/si.rs000064400000000000000000000025011046102023000133060ustar 00000000000000//! Example showing how to use the pre-built SI system. use uom::fmt::DisplayStyle::Abbreviation; use uom::si::f32::*; use uom::si::length::{centimeter, kilometer, meter}; use uom::si::time::second; use uom::si::velocity::{kilometer_per_second, meter_per_second}; fn main() { // Setup length and time quantities using different units. let l1 = Length::new::(15.0); let l2 = Length::new::(10.0); let t1 = Time::new::(50.0); let v1 = l1 / t1; //let error = l1 + t1; // error[E0308]: mismatched types // Setup re-usable format arguments. let m = Length::format_args(meter, Abbreviation); let cm = Length::format_args(centimeter, Abbreviation); let s = Time::format_args(second, Abbreviation); // Print results of simple formulas using different output units. println!("{} + {} = {}", m.with(l1), cm.with(l2), m.with(l1 + l2)); println!( "{} + {} = {}", m.with(l1), cm.with(l2), (l1 + l2).into_format_args(kilometer, Abbreviation) ); println!( "{} / {} = {}", m.with(l1), s.with(t1), v1.into_format_args(meter_per_second, Abbreviation) ); println!( "{} / {} = {}", m.with(l1), s.with(t1), v1.into_format_args(kilometer_per_second, Abbreviation) ); } uom-0.35.0/examples/unit.rs000064400000000000000000000014461046102023000136610ustar 00000000000000//! Example showing how to use the `unit!` macro to add new units to existing quantities. //! //! [Pull requests](https://github.com/iliekturtles/uom/pulls) for new units are always greatly //! appreciated. #[macro_use] extern crate uom; use uom::fmt::DisplayStyle::*; use uom::si::f32::*; use uom::si::length::meter; unit! { system: uom::si; quantity: uom::si::length; @smoot: 1.702; "smoot", "smoot", "smoots"; } fn main() { let l1 = Length::new::(15.0); let l2 = Length::new::(1.0); println!( "{} = {}", l1.into_format_args(meter, Abbreviation), l1.into_format_args(smoot, Abbreviation) ); println!( "{} = {}", l2.into_format_args(smoot, Abbreviation), l2.into_format_args(meter, Abbreviation) ); } uom-0.35.0/src/features.rs000064400000000000000000000056151046102023000134730ustar 00000000000000/// Expands the given block of code when `uom` is compiled with the `autoconvert` feature. #[doc(hidden)] #[macro_export] #[cfg(feature = "autoconvert")] macro_rules! autoconvert { ($($tt:tt)*) => { $($tt)* }; } /// Does not expand the given block of code when `uom` is compiled without the `autoconvert` /// feature. #[doc(hidden)] #[macro_export] #[cfg(not(feature = "autoconvert"))] macro_rules! autoconvert { ($($tt:tt)*) => {}; } /// Expands the given block of code when `uom` is compiled with the `autoconvert` and `test` /// features. #[doc(hidden)] #[macro_export] #[cfg(any(feature = "autoconvert", test))] macro_rules! autoconvert_test { ($($tt:tt)*) => { $($tt)* }; } /// Does not expand the given block of code when `uom` is compiled without the `autoconvert` or /// `test` features. #[doc(hidden)] #[macro_export] #[cfg(not(any(feature = "autoconvert", test)))] macro_rules! autoconvert_test { ($($tt:tt)*) => {}; } /// Expands the given block of code when `uom` is compiled without the `autoconvert` feature. #[doc(hidden)] #[macro_export] #[cfg(feature = "autoconvert")] macro_rules! not_autoconvert { ($($tt:tt)*) => {}; } /// Does not expand the given block of code when `uom` is compiled with the `autoconvert` feature. #[doc(hidden)] #[macro_export] #[cfg(not(feature = "autoconvert"))] macro_rules! not_autoconvert { ($($tt:tt)*) => { $($tt)* }; } /// Expands the given block of code when `uom` is compiled with the `serde` feature. #[doc(hidden)] #[macro_export] #[cfg(feature = "serde")] macro_rules! serde { ($($tt:tt)*) => { $($tt)* }; } /// Does not expand the given block of code when `uom` is compiled without the `serde` feature. #[doc(hidden)] #[macro_export] #[cfg(not(feature = "serde"))] macro_rules! serde { ($($tt:tt)*) => {}; } /// Expands the given block of code when `uom` is compiled with the `si` feature. #[doc(hidden)] #[macro_export] #[cfg(feature = "si")] macro_rules! si { ($($tt:tt)*) => { $($tt)* }; } /// Does not expand the given block of code when `uom` is compiled without the `si` feature. #[doc(hidden)] #[macro_export] #[cfg(not(feature = "si"))] macro_rules! si { ($($tt:tt)*) => {}; } /// Expands the given block of code when `uom` is compiled with the `std` feature. #[doc(hidden)] #[macro_export] #[cfg(feature = "std")] macro_rules! std { ($($tt:tt)*) => { $($tt)* }; } /// Does not expand the given block of code when `uom` is compiled without the `std` feature. #[doc(hidden)] #[macro_export] #[cfg(not(feature = "std"))] macro_rules! std { ($($tt:tt)*) => {}; } /// Expands the given block of code when `uom` is compiled with the `test` feature. #[doc(hidden)] #[macro_export] #[cfg(test)] macro_rules! test { ($($tt:tt)*) => { $($tt)* }; } /// Does not expand the given block of code when `uom` is compiled without the `test` feature. #[doc(hidden)] #[macro_export] #[cfg(not(test))] macro_rules! test { ($($tt:tt)*) => {}; } uom-0.35.0/src/lib.rs000064400000000000000000000645201046102023000124230ustar 00000000000000//! Units of measurement is a crate that does automatic type-safe zero-cost //! [dimensional analysis][analysis]. You can create your own systems or use the pre-built //! [International System of Units][si] (SI) which is based on the //! [International System of Quantities][isq] (ISQ) and includes numerous [quantities][quantity] //! (length, mass, time, ...) with conversion factors for even more numerous //! [measurement units][measurement] (meter, kilometer, foot, mile, ...). No more crashing your //! [climate orbiter][orbiter]! //! //! [analysis]: https://en.wikipedia.org/wiki/Dimensional_analysis //! [si]: https://jcgm.bipm.org/vim/en/1.16.html //! [isq]: https://jcgm.bipm.org/vim/en/1.6.html //! [quantity]: https://jcgm.bipm.org/vim/en/1.1.html //! [measurement]: https://jcgm.bipm.org/vim/en/1.9.html //! [orbiter]: https://en.wikipedia.org/wiki/Mars_Climate_Orbiter //! //! ## Usage //! `uom` requires `rustc` 1.60.0 or later. Add this to your `Cargo.toml`: //! //! ```toml //! [dependencies] //! uom = "0.35.0" //! ``` //! //! and this to your crate root: //! //! ```rust //! extern crate uom; //! ``` //! //! The simple example below shows how to use quantities and units as well as how `uom` stops //! invalid operations: //! #![cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #![cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] //! extern crate uom; //! //! use uom::si::f32::*; //! use uom::si::length::kilometer; //! use uom::si::time::second; //! //! fn main() { //! let length = Length::new::(5.0); //! let time = Time::new::(15.0); //! let velocity/*: Velocity*/ = length / time; //! let _acceleration = calc_acceleration(velocity, time); //! //let error = length + time; // error[E0308]: mismatched types //! } //! //! fn calc_acceleration(velocity: Velocity, time: Time) -> Acceleration { //! velocity / time //! } //! ``` //! //! See examples provided with the source for more advanced usage including how to create `Quantity` //! type aliases for a different set of base units and how to create an entirely new system of //! quantities. //! //! ## Features //! `uom` has multiple `Cargo` features for controlling available underlying storage types, the //! inclusion of the pre-built [International System of Units][si] (SI), support for //! [Serde][serde], and `no_std` functionality. The features are described below. `f32`, `f64`, //! `std`, and `si` are enabled by default. Features can be cherry-picked by using the //! `--no-default-features` and `--features "..."` flags when compiling `uom` or specifying //! features in Cargo.toml: //! //! ```toml //! [dependencies] //! uom = { //! version = "0.35.0", //! default-features = false, //! features = [ //! "autoconvert", # automatic base unit conversion. //! "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. //! "complex32", "complex64", # Complex floating point storage types. //! "f32", "f64", # Floating point storage types. //! "si", "std", # Built-in SI system and std library support. //! "use_serde", # Serde support. //! ] //! } //! ``` //! //! * `autoconvert` -- Feature to enable automatic conversion between base units in binary //! operators. Disabling the feature only allows for quantities with the same base units to //! 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`, `complex32`, //! `complex64`, `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` with `no_std`. Enabled by default. //! * `use_serde` -- Feature to enable support for serialization and deserialization of quantities //! with the [Serde][serde] crate. Disabled by default. //! //! [Serde][serde] support for the `big*` and `rational*` underlying storage types requires //! manually enabling the `serde` feature for the `num-rational` and `num-bigint` crates. To do //! so, you can add one or both of the following lines to your `Cargo.toml`: //! //! ```toml //! num-rational = { version = "*", features = ["serde"] } //! num-bigint = { version = "*", features = ["serde"] } //! ``` //! //! [si]: https://jcgm.bipm.org/vim/en/1.16.html //! [serde]: https://serde.rs/ //! //! ## Design //! Rather than working with [measurement units](https://jcgm.bipm.org/vim/en/1.9.html) (meter, //! kilometer, foot, mile, ...) `uom` works with [quantities](https://jcgm.bipm.org/vim/en/1.1.html) //! (length, mass, time, ...). This simplifies usage because units are only involved at interface //! boundaries: the rest of your code only needs to be concerned about the quantities involved. //! This also makes operations on quantities (+, -, \*, /, ...) have zero runtime cost over using //! the raw storage type (e.g. `f32`). //! //! `uom` normalizes values to the [base unit](https://jcgm.bipm.org/vim/en/1.10.html) for the //! 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`, `complex32`, `complex64`, `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 types. For example if the base unit of `length` is `meter` and the underlying storage //! type is `i32` then values like `1 centimeter` or `1.1 meter` cannot be represented. `1 //! centimeter` is normalized to `0.01 meter` which can't be stored in an `i32`. `uom` only allows //! units to be used safely. Users of this library will still need to be aware of implementation //! details of the underlying storage type including limits and precision. //! //! ## Contributing //! Contributions are welcome from everyone. Submit a pull request, an issue, or just add comments //! to an existing item. The [International Bureau of Weights and Measures][BIPM] is an //! international standards organization that publishes the [SI Brochure][brochure]. This document //! defines the [SI] and can be used as a comprehensive reference for changes to `uom`. Conversion //! factors for non-SI units can be found in NIST [Special Publication 811][nist811]. //! //! Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in //! the work by you, as defined in the Apache-2.0 license, shall be dual licensed as below, without //! any additional terms or conditions. //! //! ### License //! Licensed under either of //! //! * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or //! ) //! * MIT license ([LICENSE-MIT](LICENSE-MIT) or ) //! //! at your option. //! //! [BIPM]: https://www.bipm.org/en/about-us/ //! [brochure]: https://www.bipm.org/en/publications/si-brochure/ //! [si]: https://jcgm.bipm.org/vim/en/1.16.html //! [nist811]: https://www.nist.gov/pml/nist-guide-si-appendix-b9-factors-units-listed-kind-quantity-or-field-science // Compile with `no_std` when the `std` feature is not specified. #![cfg_attr(not(feature = "std"), no_std)] // Rustc lints. #![forbid(unsafe_code)] #![warn( bare_trait_objects, missing_copy_implementations, missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts, unused_extern_crates, unused_import_braces, unused_qualifications, unused_results )] // Clippy lints. #![cfg_attr( feature = "cargo-clippy", warn( clippy::must_use_candidate, clippy::return_self_not_must_use, ), allow( clippy::deprecated_cfg_attr, clippy::excessive_precision, clippy::inconsistent_digit_grouping, // https://github.com/rust-lang/rust-clippy/issues/6096 clippy::inline_always, ) )] // Lints allowed in tests because they are unavoidable in the generic code when a type may or may // not need to be dereferenced or cloned. #![cfg_attr( all(feature = "cargo-clippy", test), allow(clippy::op_ref, clippy::clone_on_copy, clippy::float_cmp) )] // Fail to compile if no underlying storage type features are specified. #[rustfmt::skip] #[cfg(not(any( feature = "usize", feature = "u8", feature = "u16", feature = "u32", feature = "u64", feature = "u128", 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 = "complex32", feature = "complex64", 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."); #[doc(hidden)] pub extern crate num_traits; #[doc(hidden)] #[cfg(feature = "bigint-support")] pub extern crate num_bigint; #[doc(hidden)] #[cfg(any(feature = "rational-support", feature = "bigint-support"))] pub extern crate num_rational; #[doc(hidden)] #[cfg(feature = "complex-support")] pub extern crate num_complex; #[doc(hidden)] #[cfg(feature = "serde")] pub extern crate serde; #[doc(hidden)] pub extern crate typenum; #[cfg(all( test, any(feature = "f32", feature = "f64", feature = "complex32", feature = "complex64") ))] #[macro_use] extern crate approx; #[cfg(test)] #[macro_use] extern crate quickcheck; #[cfg(test)] #[macro_use] extern crate static_assertions; // Conditionally import `core` or `std` based on feature selection. #[doc(hidden)] pub mod lib { #[cfg(not(feature = "std"))] pub use core::*; #[cfg(feature = "std")] pub use std::*; // Re-export `ops` module along with `typenum::ops` to provide all types in a single mod. This // allows the `system!` macro to reference all operations by the absolute path. Macro paths and // idents can't easily be combined without a `use` statement that pollutes the macro execution // location's namespace. pub mod ops { #[cfg(not(feature = "std"))] pub use core::ops::*; #[cfg(feature = "std")] pub use std::ops::*; pub use typenum::type_operators::*; } // Export `panic` module when the `std` feature is not enabled. `RefUnwindSafe` and `UnwindSafe` // traits do not exist in `core` but are conditionally needed in traits defined by `uom` when // `std` is enabled. These definitions work around conditional requirements. #[cfg(not(feature = "std"))] pub mod panic { pub trait RefUnwindSafe {} pub trait UnwindSafe {} } } // Conditionally import num sub-crate types based on feature selection. #[doc(hidden)] pub mod num { #[cfg(feature = "std")] pub use num_traits::float::Float; #[cfg(not(feature = "std"))] pub use num_traits::float::FloatCore as Float; pub use num_traits::{pow, FromPrimitive, Num, One, Saturating, Signed, ToPrimitive, Zero}; #[cfg(feature = "bigint-support")] pub use num_bigint::{BigInt, BigUint}; #[cfg(feature = "rational-support")] pub type Rational = num_rational::Ratio; #[cfg(feature = "bigint-support")] pub use num_rational::BigRational; #[cfg(any(feature = "rational-support", feature = "bigint-support"))] pub mod rational { pub use num_rational::*; } #[cfg(feature = "complex-support")] pub mod complex { pub use num_complex::*; } } /// Primitive traits and types representing basic properties of types. pub mod marker { /// Trait to denote that a quantity is able to be added with a quantity of the same dimensions. /// When a specific quantity's kind inherits this trait `ops::Add` is implemented /// automatically. pub trait Add {} /// Trait to denote that a quantity is able to be added with a quantity of the same dimensions. /// When a specific quantity's kind inherits this trait `ops::AddAssign` is implemented /// automatically. pub trait AddAssign {} /// Trait to denote that a quantity is able to be subtracted with a quantity of the same /// dimensions. When a specific quantity's kind inherits this trait `ops::Sub` is implemented /// automatically. pub trait Sub {} /// Trait to denote that a quantity is able to be subtracted with a quantity of the same /// dimensions. When a specific quantity's kind inherits this trait `ops::SubAssign` is /// implemented automatically. pub trait SubAssign {} /// Trait to denote that a quantity is able to be multiplied with a quantity of the same /// dimensions. When a specific quantity's kind inherits this trait `ops::Mul` is implemented /// automatically. pub trait Mul {} /// Trait to denote that a quantity is able to be multiplied with a quantity of the same /// dimensions. When a specific quantity's kind inherits this trait `ops::MulAssign` is /// implemented automatically. pub trait MulAssign {} /// Trait to denote that a quantity is able to be divided with a quantity of the same /// dimensions. When a specific quantity's kind inherits this trait `ops::Div` is implemented /// automatically. pub trait Div {} /// Trait to denote that a quantity is able to be divided with a quantity of the same /// dimensions. When a specific quantity's kind inherits this trait `ops::DivAssign` is /// implemented automatically. pub trait DivAssign {} /// Trait to denote that a quantity is able to be negated. When a specific quantity's kind /// inherits this trait `ops::Neg` is implemented automatically. pub trait Neg {} /// Trait to denote that a quantity is able to calculate a remainder with a quantity of the /// same dimensions. When a specific quantity's kind inherits this trait `ops::Rem` is /// implemented automatically. pub trait Rem {} /// Trait to denote that a quantity is able to calculate a remainder with a quantity of the /// same dimensions. When a specific quantity's kind inherits this trait `ops::RemAssign` is /// implemented automatically. pub trait RemAssign {} /// Trait to denote that a quantity is able to perform saturating additions and subtractions /// with a quantity of the same dimensions. When a specific quantity's kind inherits this trait /// `ops::Saturating` is implemented automatically. pub trait Saturating {} } #[macro_use] mod features; #[macro_use] mod storage_types; #[macro_use] mod system; #[macro_use] mod quantity; #[macro_use] mod unit; #[cfg(feature = "si")] #[macro_use] pub mod si; #[cfg(test)] mod tests; /// Operations performed on the constant portion of the [conversion factor][factor]. Used to help /// guide optimizations when floating point underlying storage types are used. /// /// For a value, `v: Float`, adding `-0.0` is a no-op while adding `0.0` will change the sign if /// `v` is `-0.0`. The opposite is true for subtraction. /// /// ```ignore /// v /// 0.0 + -0.0 = 0.0 /// -0.0 + 0.0 = 0.0 // v + 0.0 != v /// -0.0 + -0.0 = -0.0 /// 0.0 - -0.0 = 0.0 /// -0.0 - 0.0 = 0.0 /// -0.0 - -0.0 = 0.0 // v - -0.0 != v /// ``` /// /// [factor]: https://jcgm.bipm.org/vim/en/1.24.html #[derive(Clone, Copy, Debug)] pub enum ConstantOp { /// Hint that the constant is being added to a value. Add, /// Hint that the constant is being subtracted from a value. Sub, } /// Trait to identify [units][units] which have a [conversion factor][factor]. /// /// ## Generic Parameters /// * `V`: Underlying storage type trait is implemented for. /// /// [units]: https://jcgm.bipm.org/vim/en/1.13.html /// [factor]: https://jcgm.bipm.org/vim/en/1.24.html pub trait Conversion { /// Conversion factor type specific to the underlying storage type. type T: ConversionFactor; /// Coefficient portion of [conversion factor](https://jcgm.bipm.org/vim/en/1.24.html) for /// converting the given unit to the base unit for the quantity: `(value * coefficient()) + /// constant()`. Implementation should return the multiplicative identity (`Self::T::one()`) if /// no coefficient exists. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] fn coefficient() -> Self::T { ::one() } /// Constant portion of [conversion factor](https://jcgm.bipm.org/vim/en/1.24.html) for /// converting the given unit to the base unit for the quantity: `(value * coefficient()) + /// constant()`. Implementation should return the additive identity (`Self::T::zero()`) if no /// constant exists. See [ConstantOp](enum.ConstantOp.html) documentation for details about /// parameter use to ensure the method optimizes correctly. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] #[allow(unused_variables)] fn constant(op: ConstantOp) -> Self::T { ::zero() } /// Instance [conversion factor](https://jcgm.bipm.org/vim/en/1.24.html). /// /// Default implementation returns the coefficient: `Self::coefficient()`. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] fn conversion(&self) -> Self::T where Self: Sized, { Self::coefficient() } } /// Trait representing a [conversion factor][factor]. /// /// ## Generic Parameters /// * `V`: Underlying storage type trait is implemented for. /// /// [factor]: https://jcgm.bipm.org/vim/en/1.24.html #[allow(unused_qualifications)] // lib:cmp::PartialOrder false positive. pub trait ConversionFactor: lib::cmp::PartialOrd + lib::ops::Add + lib::ops::Sub + lib::ops::Mul + lib::ops::Div + crate::num::Zero + crate::num::One { /// Raises a `ConversionFactor` to an integer power. #[must_use = "method returns a new number and does not mutate the original value"] fn powi(self, e: i32) -> Self; /// Converts a `ConversionFactor` into its underlying storage type. #[must_use = "method returns a new number and does not mutate the original value"] fn value(self) -> V; } /// Helper trait to identify the zero value of a type at compile time. /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::Length; /// use uom::ConstZero; /// /// const ORIGIN: (Length, Length, Length) = (Length::ZERO, Length::ZERO, Length::ZERO); /// ``` pub trait ConstZero { /// Constant representing the zero value. const ZERO: Self; } /// Default [kind][kind] of quantities to allow addition, subtraction, multiplication, division, /// remainder, negation, and saturating addition/subtraction. /// /// [kind]: https://jcgm.bipm.org/vim/en/1.2.html pub trait Kind: marker::Add + marker::AddAssign + marker::Sub + marker::SubAssign + marker::Mul + marker::MulAssign + marker::Div + marker::DivAssign + marker::Rem + marker::RemAssign + marker::Neg + marker::Saturating { } storage_types! { types: Float; impl crate::Conversion for V { type T = V; #[inline(always)] fn constant(op: crate::ConstantOp) -> Self::T { match op { crate::ConstantOp::Add => -::zero(), crate::ConstantOp::Sub => ::zero(), } } #[inline(always)] fn conversion(&self) -> Self::T { *self } } impl crate::ConversionFactor for V { #[inline(always)] fn powi(self, e: i32) -> Self { ::powi(self, e) } #[inline(always)] fn value(self) -> V { self } } impl crate::ConstZero for V { const ZERO: Self = 0.0; } } storage_types! { types: PrimInt; impl crate::Conversion for V { type T = crate::num::rational::Ratio; #[inline(always)] fn conversion(&self) -> Self::T { (*self).into() } } impl crate::ConversionFactor for crate::num::rational::Ratio { #[inline(always)] fn powi(self, e: i32) -> Self { self.pow(e) } #[inline(always)] fn value(self) -> V { self.to_integer() } } impl crate::ConstZero for V { const ZERO: Self = 0; } } storage_types! { types: BigInt, BigUint; impl crate::Conversion for V { type T = crate::num::rational::Ratio; #[inline(always)] fn conversion(&self) -> Self::T { self.clone().into() } } impl crate::ConversionFactor for crate::num::rational::Ratio { #[inline(always)] fn powi(self, e: i32) -> Self { match e.cmp(&0) { crate::lib::cmp::Ordering::Equal => ::one(), crate::lib::cmp::Ordering::Less => crate::num::pow::pow(self.recip(), (-e) as usize), crate::lib::cmp::Ordering::Greater => crate::num::pow::pow(self, e as usize), } } #[inline(always)] fn value(self) -> V { self.to_integer() } } } storage_types! { types: Rational, Rational32, Rational64; impl crate::Conversion for V { type T = V; #[inline(always)] fn conversion(&self) -> Self::T { *self } } impl crate::ConversionFactor for V { #[inline(always)] fn powi(self, e: i32) -> Self { self.pow(e) } #[inline(always)] fn value(self) -> V { self } } } storage_types! { types: BigRational; impl crate::Conversion for V { type T = V; #[inline(always)] fn conversion(&self) -> Self::T { self.clone() } } impl crate::ConversionFactor for V { #[inline(always)] fn powi(self, e: i32) -> Self { match e.cmp(&0) { crate::lib::cmp::Ordering::Equal => ::one(), crate::lib::cmp::Ordering::Less => crate::num::pow::pow(self.recip(), (-e) as usize), crate::lib::cmp::Ordering::Greater => crate::num::pow::pow(self, e as usize), } } #[inline(always)] fn value(self) -> V { self } } } storage_types! { types: Complex; impl crate::Conversion for V { type T = VV; #[inline(always)] fn constant(op: crate::ConstantOp) -> Self::T { match op { crate::ConstantOp::Add => -::zero(), crate::ConstantOp::Sub => ::zero(), } } #[inline(always)] fn conversion(&self) -> Self::T { // Conversion factor is the norm of the number. Scaling with length again yields the // same number. self.norm() } } impl crate::ConversionFactor for VV { #[inline(always)] fn powi(self, e: i32) -> Self { self.powi(e) } #[inline(always)] fn value(self) -> V { // Conversion by scaling (multiplication with only real number). Scaling a normalized // number yields the original number again. V::new(self, 0.0) } } } /// Utilities for formatting and printing quantities. pub mod fmt { /// An enum to specify the display style to use. #[derive(Clone, Copy, Debug)] pub enum DisplayStyle { /// Display the value and a unit abbreviation, e.g. "1.0 m", "327 s". Abbreviation, /// Display the value and full unit name (pluralized as appropriate), /// e.g. "1 kilogram", "756 feet". Description, } } /// Unicode string slice manipulation for quantities. pub mod str { use crate::lib::fmt::{self, Display, Formatter}; /// Represents an error encountered while parsing a string into a `Quantity`. #[allow(missing_copy_implementations)] #[derive(Clone, Debug, Eq, PartialEq)] pub enum ParseQuantityError { /// No separators (spaces) were encountered. NoSeparator, /// An error occurred while parsing the value (first) portion of the string. /// /// Due to exhaustiveness and type system limitations, this variant does not encode /// the underlying parse error. ValueParseError, /// The unit used wasn't found for this quantity. /// /// ### Notes /// For now, only abbreviations are supported, so this error may be encountered even if the /// unit name (description) is correct. UnknownUnit, } impl Display for ParseQuantityError { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { use ParseQuantityError::*; match *self { NoSeparator => write!(f, "no space between quantity and units"), ValueParseError => write!(f, "error parsing unit quantity"), UnknownUnit => write!(f, "unrecognized unit of measure"), } } } #[cfg(feature = "std")] impl crate::lib::error::Error for ParseQuantityError {} } uom-0.35.0/src/quantity.rs000064400000000000000000000422721046102023000135330ustar 00000000000000/// Macro to implement a [quantity][quantity] and associated [measurement units][measurement]. Note /// that this macro must be executed in direct submodules of the module where the /// [`system!`](macro.system.html) macro was executed. `@...` match arms are considered private. /// /// * `$quantity_attr`: Quantity attributes. Generally used to set documentation comments for the /// quantity. /// * `$quantity`: Quantity name (e.g. `Length`). /// * `$description`: Quantity description (e.g. `"length"`). /// * `$dim_attr`: Dimension attributes. Generally used to set documentation comments for the /// quantity's dimension type alias. /// * `$system`: System of quantities type (e.g. `ISQ`). /// * `$dimension`: Power of a factor for each base quantity in the system. Power should be /// represented as a `typenum` type-level integer (e.g. `N1`, `Z0`, `P1`, `P2`, ...). /// * `$kind`: [Kind][kind] of the quantity. Optional. This variable should only be specified when /// defining a quantity that has the same dimensions as another quantity but isn't comparable. /// When not specified [`uom::Kind`](trait.Kind.html) is used. /// * `$unit`: Unit name (e.g. `meter`, `foot`). /// * `$conversion`: Conversion (coefficient and constant factor) from the unit to the base unit of /// the quantity (e.g. `3.048_E-1` to convert `foot` to `meter`. `1.0_E0, 273.15_E0` to convert /// `celsius` to `kelvin`.). The coefficient is required and the constant factor is optional. /// Note that using a unit with a non-zero constant factor is not currently supported as a base /// unit. /// * `$abbreviation`: Unit abbreviation (e.g. `"m"`). /// * `$singular`: Singular unit description (e.g. `"meter"`). /// * `$plural`: Plural unit description (e.g. `"meters"`). /// /// An example invocation is given below for the quantity of length in a meter-kilogram-second /// system. The `#[macro_use]` attribute must be used when including the `uom` crate to make the /// `quantity!` macro available. /// /// ``` /// #[macro_use] /// extern crate uom; /// /// # fn main() { } /// # mod mks { /// #[macro_use] /// mod length { /// quantity! { /// /// Length (base unit meter, m). /// quantity: Length; "length"; /// /// Length dimension, m. /// dimension: Q; /// units { /// @meter: 1.0E0; "m", "meter", "meters"; /// @foot: 3.048E-1; "ft", "foot", "feet"; /// } /// } /// } /// # #[macro_use] /// # mod mass { /// # quantity! { /// # /// Mass (base unit kilogram, kg). /// # quantity: Mass; "mass"; /// # /// Mass dimension, kg. /// # dimension: Q; /// # units { /// # @kilogram: 1.0; "kg", "kilogram", "kilograms"; /// # } /// # } /// # } /// # #[macro_use] /// # mod time { /// # quantity! { /// # /// Time (base unit second, s). /// # quantity: Time; "time"; /// # /// Time dimension, s. /// # dimension: Q; /// # units { /// # @second: 1.0; "s", "second", "seconds"; /// # } /// # } /// # } /// # system! { /// # /// System of quantities, Q. /// # quantities: Q { /// # length: meter, L; /// # mass: kilogram, M; /// # time: second, T; /// # } /// # /// System of units, U. /// # units: U { /// # mod length::Length, /// # mod mass::Mass, /// # mod time::Time, /// # } /// # } /// # mod f32 { /// # Q!(crate::mks, f32/*, (centimeter, gram, second)*/); /// # } /// # } /// ``` /// /// [quantity]: https://jcgm.bipm.org/vim/en/1.1.html /// [measurement]: https://jcgm.bipm.org/vim/en/1.9.html /// [kind]: https://jcgm.bipm.org/vim/en/1.2.html #[macro_export] macro_rules! quantity { ( $(#[$quantity_attr:meta])* quantity: $quantity:ident; $description:expr; $(#[$dim_attr:meta])* dimension: $system:ident<$($dimension:ident),+>; $(kind: $kind:ty;)? units { $($(#[$unit_attr:meta])* @$unit:ident: $($conversion:expr),+; $abbreviation:expr, $singular:expr, $plural:expr;)+ } ) => { mod __system { pub use super::super::*; } $(#[$dim_attr])* pub type Dimension = __system::$system<$($crate::typenum::$dimension),+, quantity!(@kind $($kind)?)>; $(#[$quantity_attr])* /// /// ## Generic Parameters /// * `U`: Base units. /// * `V`: Underlying storage type. pub type $quantity = __system::Quantity; /// Marker trait to identify measurement units for the quantity. See /// [`Unit`](../trait.Unit.html). pub trait Unit: __system::Unit {} /// Trait to identify [units][units] which have a [conversion factor][factor] for the /// `Quantity`. See [`Conversion`](../../trait.Conversion.html). /// /// ## Generic Parameters /// * `V`: Underlying storage type trait is implemented for. /// /// [units]: https://jcgm.bipm.org/vim/en/1.13.html /// [factor]: https://jcgm.bipm.org/vim/en/1.24.html pub trait Conversion: Unit + $crate::Conversion>::T> where V: $crate::Conversion, { } unit! { @units $($(#[$unit_attr])* @$unit: $($conversion),+; $abbreviation, $singular, $plural;)+ } /// Quantity description. #[must_use = "method returns a static value"] #[allow(dead_code)] #[inline(always)] pub fn description() -> &'static str { $description } /// Unit enum. #[allow(non_camel_case_types)] #[non_exhaustive] #[allow(clippy::manual_non_exhaustive)] #[derive(Debug, Clone, Copy)] pub enum Units { $(#[doc=$plural] $unit($unit),)+ } impl Units { /// Unit abbreviation. #[must_use = "method returns a static value"] #[allow(dead_code)] pub fn abbreviation(&self) -> &'static str { match self { $(Units::$unit(_) => <$unit as __system::Unit>::abbreviation(),)+ } } /// Unit singular description. #[must_use = "method returns a static value"] #[allow(dead_code)] pub fn singular(&self) -> &'static str { match self { $(Units::$unit(_) => <$unit as __system::Unit>::singular(),)+ } } /// Unit plural description. #[must_use = "method returns a static value"] #[allow(dead_code)] pub fn plural(&self) -> &'static str { match self { $(Units::$unit(_) => <$unit as __system::Unit>::plural(),)+ } } } static ALL_UNITS: &[Units] = &[ $(Units::$unit($unit),)+ ]; /// Iterate over all defined units for this quantity. #[allow(dead_code)] pub fn units() -> impl Iterator { ALL_UNITS.iter().copied() } impl $quantity where U: __system::Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { /// Create a new quantity from the given value and measurement unit. /// /// ## Generic Parameters /// * `N`: Unit. #[must_use = "method produces a new value"] #[inline(always)] pub fn new(v: V) -> Self where N: Unit + $crate::Conversion, { $quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: __system::to_base::(&v), } } /// Retrieve the value of the quantity in the given measurement unit. /// /// ## Generic Parameters /// * `N`: Unit. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn get(&self) -> V where N: Unit + $crate::Conversion, { __system::from_base::(&self.value) } /// Returns the largest integer less than or equal to a number in the given /// measurement unit. /// /// ## Generic Parameters /// * `N`: Unit. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn floor(self) -> Self where V: $crate::num::Float, N: Unit + $crate::Conversion, { Self::new::(self.get::().floor()) } /// Returns the smallest integer less than or equal to a number in the given /// measurement unit. /// /// ## Generic Parameters /// * `N`: Unit. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn ceil(self) -> Self where V: $crate::num::Float, N: Unit + $crate::Conversion, { Self::new::(self.get::().ceil()) } /// Returns the nearest integer to a number in the in given measurement unit. /// Round half-way cases away from 0.0. /// /// ## Generic Parameters /// * `N`: Unit. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn round(self) -> Self where V: $crate::num::Float, N: Unit + $crate::Conversion, { Self::new::(self.get::().round()) } /// Returns the integer part of a number in the given measurement unit. /// /// ## Generic Parameters /// * `N`: Unit. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn trunc(self) -> Self where V: $crate::num::Float, N: Unit + $crate::Conversion, { Self::new::(self.get::().trunc()) } /// Returns the fractional part of a number in the given measurement unit. /// /// ## Generic Parameters /// * `N`: Unit. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn fract(self) -> Self where V: $crate::num::Float, N: Unit + $crate::Conversion, { Self::new::(self.get::().fract()) } /// Creates a struct that can be used to format a compatible quantity for display. /// /// # Notes /// The return value of this method cannot be used to print directly, but is instead /// used to format quantities and can be reused; see /// [Arguments::with](../fmt/struct.Arguments.html#method.with) and the examples below. /// /// If you do not need to format multiple quantities, consider using /// [`into_format_args`](#method.into_format_args) instead. /// /// # Examples #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::time::{femtosecond, picosecond}; /// # use uom::si::fmt::Arguments; /// # use uom::fmt::DisplayStyle::*; /// let t1 = Time::new::(1.0_E-1); /// let t2 = Time::new::(1.0_E-1); /// let a = Time::format_args(femtosecond, Description); /// /// assert_eq!("0.1 femtoseconds", format!("{}", a.with(t1))); /// assert_eq!("100 femtoseconds", format!("{}", a.with(t2))); /// ``` /// /// ## Generic Parameters /// * `N`: Unit. #[must_use = "method returns a new object"] pub fn format_args( unit: N, style: $crate::fmt::DisplayStyle ) -> __system::fmt::Arguments where N: Unit { __system::fmt::Arguments { dimension: $crate::lib::marker::PhantomData, unit, style, } } /// Creates a struct that formats `self` for display. /// /// # Notes /// Unlike [`format_args`](#method.format_args), the return value of this method can be /// used directly for display. It will format the value of `self` for the quantity on /// which it is called and nothing else. /// /// If you wish to reuse the return value to format multiple quantities, use /// [`format_args`](#method.format_args) instead. /// /// # Examples #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::time::{femtosecond, picosecond}; /// # use uom::si::fmt::Arguments; /// # use uom::fmt::DisplayStyle::*; /// let t = Time::new::(1.0_E-1); /// let a = t.into_format_args(femtosecond, Description); /// /// assert_eq!("100 femtoseconds", format!("{}", a)); /// ``` /// /// ## Generic Parameters /// * `N`: Unit. #[must_use = "method returns a new object and does not mutate the original one"] pub fn into_format_args( self, unit: N, style: $crate::fmt::DisplayStyle ) -> __system::fmt::QuantityArguments where N: Unit { __system::fmt::QuantityArguments { arguments: __system::fmt::Arguments { dimension: $crate::lib::marker::PhantomData, unit, style, }, quantity: self, } } } impl __system::fmt::Arguments where N: __system::Unit + Unit, { /// Specifies a quantity to display. /// /// ## Generic Parameters /// * `U`: Base units. /// * `V`: Underlying storage type trait is implemented for. #[must_use = "method returns a new object and does not mutate the original one"] pub fn with( self, quantity: $quantity ) -> __system::fmt::QuantityArguments where U: __system::Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { __system::fmt::QuantityArguments { arguments: self, quantity, } } } mod str { storage_types! { use $crate::lib::str::FromStr; use $crate::str::ParseQuantityError::*; impl FromStr for super::super::$quantity where U: super::super::__system::Units + ?Sized, { type Err = $crate::str::ParseQuantityError; fn from_str(s: &str) -> Result { let mut parts = s.splitn(2, ' '); let value = parts.next().unwrap(); let unit = parts.next().ok_or(NoSeparator)?; let value = value.parse::().map_err(|_| ValueParseError)?; #[allow(unreachable_patterns)] match unit.trim() { $($abbreviation | $singular | $plural => Ok(Self::new::(value)),)+ _ => Err(UnknownUnit), } } } } } }; (@kind $kind:ty) => { $kind }; (@kind) => { dyn $crate::Kind }; } uom-0.35.0/src/si/absement.rs000064400000000000000000000123071046102023000140620ustar 00000000000000//! Absement (base unit meter second, m · s). quantity! { /// Absement (base unit meter second, m · s). quantity: Absement; "absement"; /// Dimension of absement, LT (base unit meter second, m · s). dimension: ISQ< P1, // length Z0, // mass P1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottameter_second: prefix!(yotta); "Ym · s", "yottameter second", "yottameter seconds"; @zettameter_second: prefix!(zetta); "Zm · s", "zettameter second", "zettameter seconds"; @exameter_second: prefix!(exa); "Em · s", "exameter second", "exameter seconds"; @petameter_second: prefix!(peta); "Pm · s", "petameter second", "petameter seconds"; @terameter_second: prefix!(tera); "Tm · s", "terameter second", "terameter seconds"; @gigameter_second: prefix!(giga); "Gm · s", "gigameter second", "gigameter seconds"; @megameter_second: prefix!(mega); "Mm · s", "megameter second", "megameter seconds"; @kilometer_second: prefix!(kilo); "km · s", "kilometer second", "kilometer seconds"; @hectometer_second: prefix!(hecto); "hm · s", "hectometer second", "hectometer seconds"; @decameter_second: prefix!(deca); "dam · s", "decameter second", "decameter seconds"; @meter_second: prefix!(none); "m · s", "meter second", "meter seconds"; @decimeter_second: prefix!(deci); "dm · s", "decimeter second", "decimeter seconds"; @centimeter_second: prefix!(centi); "cm · s", "centimeter second", "centimeter seconds"; @millimeter_second: prefix!(milli); "mm · s", "millimeter second", "millimeter seconds"; @micrometer_second: prefix!(micro); "µm · s", "micrometer second", "micrometer seconds"; @nanometer_second: prefix!(nano); "nm · s", "nanometer second", "nanometer seconds"; @picometer_second: prefix!(pico); "pm · s", "picometer second", "picometer seconds"; @femtometer_second: prefix!(femto); "fm · s", "femtometer second", "femtometer seconds"; @attometer_second: prefix!(atto); "am · s", "attometer second", "attometer seconds"; @zeptometer_second: prefix!(zepto); "zm · s", "zeptometer second", "zeptometer seconds"; @yoctometer_second: prefix!(yocto); "ym · s", "yoctometer second", "yoctometer seconds"; @foot_second: 3.048_E-1; "ft · s", "foot second", "foot seconds"; @inch_second: 2.54_E-2; "in · s", "inch second", "inch seconds"; @kilometer_hour: 3.6_E6; "km · h", "kilometer hour", "kilometer hours"; } } #[cfg(test)] mod tests { storage_types! { use crate::si::absement as a; use crate::si::length as l; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; use crate::num::One; #[test] fn check_dimension() { let _: Absement = Length::new::(V::one()) * Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, A: a::Conversion>() { Test::assert_eq(&Absement::new::(V::one()), &(Length::new::(V::one()) * Time::new::(V::one()))); } } } } uom-0.35.0/src/si/acceleration.rs000064400000000000000000000154451046102023000147230ustar 00000000000000//! Acceleration (base unit meter per second squared, m · s⁻²). quantity! { /// Acceleration (base unit meter per second squared, m · s⁻²). quantity: Acceleration; "acceleration"; /// Dimension of acceleration, LT⁻² (base unit meter per second squared, m · s⁻²). dimension: ISQ< P1, // length Z0, // mass N2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottameter_per_second_squared: prefix!(yotta); "Ym/s²", "yottameter per second squared", "yottameters per second squared"; @zettameter_per_second_squared: prefix!(zetta); "Zm/s²", "zettameter per second squared", "zettameters per second squared"; @exameter_per_second_squared: prefix!(exa); "Em/s²", "exameter per second squared", "exameters per second squared"; @petameter_per_second_squared: prefix!(peta); "Pm/s²", "petameter per second squared", "petameters per second squared"; @terameter_per_second_squared: prefix!(tera); "Tm/s²", "terameter per second squared", "terameters per second squared"; @gigameter_per_second_squared: prefix!(giga); "Gm/s²", "gigameter per second squared", "gigameters per second squared"; @megameter_per_second_squared: prefix!(mega); "Mm/s²", "megameter per second squared", "megameters per second squared"; @kilometer_per_second_squared: prefix!(kilo); "km/s²", "kilometer per second squared", "kilometers per second squared"; @hectometer_per_second_squared: prefix!(hecto); "hm/s²", "hectometer per second squared", "hectometers per second squared"; @decameter_per_second_squared: prefix!(deca); "dam/s²", "decameter per second squared", "decameters per second squared"; @meter_per_second_squared: prefix!(none); "m/s²", "meter per second squared", "meters per second squared"; @decimeter_per_second_squared: prefix!(deci); "dm/s²", "decimeter per second squared", "decimeters per second squared"; @centimeter_per_second_squared: prefix!(centi); "cm/s²", "centimeter per second squared", "centimeters per second squared"; @millimeter_per_second_squared: prefix!(milli); "mm/s²", "millimeter per second squared", "millimeters per second squared"; @micrometer_per_second_squared: prefix!(micro); "µm/s²", "micrometer per second squared", "micrometers per second squared"; @nanometer_per_second_squared: prefix!(nano); "nm/s²", "nanometer per second squared", "nanometers per second squared"; @picometer_per_second_squared: prefix!(pico); "pm/s²", "picometer per second squared", "picometers per second squared"; @femtometer_per_second_squared: prefix!(femto); "fm/s²", "femtometer per second squared", "femtometers per second squared"; @attometer_per_second_squared: prefix!(atto); "am/s²", "attometer per second squared", "attometers per second squared"; @zeptometer_per_second_squared: prefix!(zepto); "zm/s²", "zeptometer per second squared", "zeptometers per second squared"; @yoctometer_per_second_squared: prefix!(yocto); "ym/s²", "yoctometer per second squared", "yoctometers per second squared"; @foot_per_second_squared: 3.048_E-1; "ft/s²", "foot per second squared", "feet per second squared"; @galileo: 1.0_E-2; "Gal", "galileo", "galileos"; @inch_per_second_squared: 2.54_E-2; "in/s²", "inch per second squared", "inches per second squared"; @millimeter_per_minute_squared: 2.777_777_777_777_777_8_E-7; "mm/min²", "millimeter per minute squared", "millimeters per minute squared"; @standard_gravity: 9.806_65_E0; "g₀", "standard acceleration of gravity", "standard accelerations of gravity"; } } #[cfg(test)] mod tests { storage_types! { use crate::si::acceleration as a; use crate::si::length as l; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; use crate::num::One; #[test] fn check_dimension() { let _: Acceleration = Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one())); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, A: a::Conversion>() { Test::assert_eq(&Acceleration::new::(V::one()), &(Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one())))); } } } } uom-0.35.0/src/si/action.rs000064400000000000000000000041111046102023000135330ustar 00000000000000//! Action (base unit joule second, kg ⋅ m² ⋅ s⁻¹). quantity! { /// Action (base unit joule second, kg ⋅ m² ⋅ s⁻¹). quantity: Action; "action"; /// Dimension of action, L²MT⁻¹ (base unit joule second, kg ⋅ m² ⋅ s⁻¹). dimension: ISQ< P2, // length P1, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @joule_second: prefix!(none); "J · s", "joule second", "joule seconds"; /// Reduced Planck constant ħ. @atomic_unit_of_action: 1.054_571_817_E-34; "ħ", "atomic unit of action", "atomic units of action"; @reduced_planck_constant: 1.054_571_817_E-34; "ħ", "reduced planck constant", "reduced planck constants"; @planck_constant: 6.626_070_15_E-34; "h", "planck constant", "planck constants"; @erg_second: 1.0_E-7; "erg · s", "erg second", "erg seconds"; @electronvolt_second: 1.602_176_634_E-19; "eV · s", "electronvolt second", "electronvolt seconds"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::quantities::*; use crate::si::time as t; use crate::si::energy as e; use crate::si::action as act; use crate::tests::Test; #[test] fn check_dimension() { let _: Action = Energy::new::(V::one()) * Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); fn test, T: t::Conversion, ACT: act::Conversion>() { Test::assert_approx_eq(&Action::new::(V::one()), &(Energy::new::(V::one()) * Time::new::(V::one()))); } } } } uom-0.35.0/src/si/amount_of_substance.rs000064400000000000000000000074041046102023000163240ustar 00000000000000//! Amount of substance (base unit mole, mol). quantity! { /// Amount of substance (base unit mole, mol). quantity: AmountOfSubstance; "amount of substance"; /// Dimension of amount of substance, N (base unit mole, mol). dimension: ISQ< Z0, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature P1, // amount of substance Z0>; // luminous intensity units { @yottamole: prefix!(yotta); "Ymol", "yottamole", "yottamoles"; @zettamole: prefix!(zetta); "Zmol", "zettamole", "zettamoles"; @examole: prefix!(exa); "Emol", "examole", "examoles"; @petamole: prefix!(peta); "Pmol", "petamole", "petamoles"; @teramole: prefix!(tera); "Tmol", "teramole", "teramoles"; @gigamole: prefix!(giga); "Gmol", "gigamole", "gigamoles"; @megamole: prefix!(mega); "Mmol", "megamole", "megamoles"; @kilomole: prefix!(kilo); "kmol", "kilomole", "kilomoles"; @hectomole: prefix!(hecto); "hmol", "hectomole", "hectomoles"; @decamole: prefix!(deca); "damol", "decamole", "decamoles"; /// 1. The mole is the SI unit of amount of substance. One mole contains exactly /// 6.022 140 76 × 10²³ elementary entities. This number is the fixed numerical value of /// the Avogadro constant, *N*A, when expressed in the unit mol⁻¹ and is /// called the Avogadro number. /// 2. The amount of substance, symbol *n*, of a system is a measure of the number of /// specified elementary entities. An elementary entity may be an atom, a molecule, an /// ion, an electron, any other particle or specified group of particles. @mole: prefix!(none); "mol", "mole", "moles"; @decimole: prefix!(deci); "dmol", "decimole", "decimoles"; @centimole: prefix!(centi); "cmol", "centimole", "centimoles"; @millimole: prefix!(milli); "mmol", "millimole", "millimoles"; @micromole: prefix!(micro); "µmol", "micromole", "micromoles"; @nanomole: prefix!(nano); "nmol", "nanomole", "nanomoles"; @picomole: prefix!(pico); "pmol", "picomole", "picomoles"; @femtomole: prefix!(femto); "fmol", "femtomole", "femtomoles"; @attomole: prefix!(atto); "amol", "attomole", "attomoles"; @zeptomole: prefix!(zepto); "zmol", "zeptomole", "zeptomoles"; @yoctomole: prefix!(yocto); "ymol", "yoctomole", "yoctomoles"; /// One elementary entity may be an atom, a molecule, an ion, an electron, any other /// particle or specified group of particles. @particle: 1.0_E0 / 6.022_140_76_E23; "particle", "particle", "particles"; /// Amount of ideal gas contained in a volume of cubic meter at standard temperature (O°C) and pressure (1 bar) @standard_cubic_meter: 1_E5 * prefix!(none) / 8.314_462_618 / 273.15; "m³(STP)", "standard cubic meter", "standard cubic meters"; /// Amount of ideal gas contained in a volume of liter at standard temperature (O°C) and pressure (1 bar) @standard_liter: 1_E5 * prefix!(milli) / 8.314_462_618 / 273.15; "L(STP)", "standard liter", "standard liters"; /// Amount of ideal gas contained in a volume of cubic centimeter at standard temperature (O°C) and pressure (1 bar) @standard_centimeter: 1_E5 * prefix!(micro) / 8.314_462_618 / 273.15; "cm³(STP)", "standard cubic centimeter", "standard cubic centimeters"; /// Amount of ideal gas contained in a volume of cubic foot at standard temperature (O°C) and pressure (1 bar) @standard_cubic_foot: 1_E5 * 2.831_685_E-2 / 8.314_462_618 / 273.15; "scf", "standard cubic foot", "standard cubic feet"; } } uom-0.35.0/src/si/angle.rs000064400000000000000000000210471046102023000133530ustar 00000000000000//! Angle (dimensionless quantity). #[cfg(feature = "std")] use super::ratio::Ratio; quantity! { /// Angle (dimensionless quantity). quantity: Angle; "angle"; /// Dimension of angle, 1 (dimensionless). dimension: ISQ< Z0, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::AngleKind); units { /// SI derived unit of angle. It is the angle subtended at the center of a circle by an /// arc that is equal in length to the radius of the circle. @radian: 1.0_E0; "rad", "radian", "radians"; @revolution: 6.283_185_307_179_586_E0; "r", "revolution", "revolutions"; @degree: 1.745_329_251_994_329_5_E-2; "°", "degree", "degrees"; @gon: 1.570_796_326_794_896_7_E-2; "gon", "gon", "gons"; @mil: 9.817_477_E-4; "mil", "mil", "mils"; @minute: 2.908_882_086_657_216_E-4; "′", "minute", "minutes"; @second: 4.848_136_811_095_36_E-6; "″", "second", "seconds"; } } #[cfg(feature = "f32")] impl Angle, f32> { /// A half turn, i.e. an angle with a value of π as measured in radians pub const HALF_TURN: Self = Self { dimension: crate::lib::marker::PhantomData, units: crate::lib::marker::PhantomData, value: crate::lib::f32::consts::PI, }; /// A full turn, i.e. an angle with a value of 2π as measured in radians pub const FULL_TURN: Self = Self { dimension: crate::lib::marker::PhantomData, units: crate::lib::marker::PhantomData, value: 2. * crate::lib::f32::consts::PI, }; } #[cfg(feature = "f64")] impl Angle, f64> { /// A half turn, i.e. an angle with a value of π as measured in radians pub const HALF_TURN: Self = Self { dimension: crate::lib::marker::PhantomData, units: crate::lib::marker::PhantomData, value: crate::lib::f64::consts::PI, }; /// A full turn, i.e. an angle with a value of 2π as measured in radians pub const FULL_TURN: Self = Self { dimension: crate::lib::marker::PhantomData, units: crate::lib::marker::PhantomData, value: 2. * crate::lib::f64::consts::PI, }; } /// Implementation of various stdlib trigonometric functions #[cfg(feature = "std")] impl Angle where U: crate::si::Units + ?Sized, V: crate::num::Float + crate::Conversion, { /// Computes the value of the cosine of the angle. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn cos(self) -> Ratio { self.value.cos().into() } /// Computes the value of the hyperbolic cosine of the angle. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn cosh(self) -> Ratio { self.value.cosh().into() } /// Computes the value of the sine of the angle. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn sin(self) -> Ratio { self.value.sin().into() } /// Computes the value of the hyperbolic sine of the angle. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn sinh(self) -> Ratio { self.value.sinh().into() } /// Computes the value of both the sine and cosine of the angle. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn sin_cos(self) -> (Ratio, Ratio) { let (sin, cos) = self.value.sin_cos(); (sin.into(), cos.into()) } /// Computes the value of the tangent of the angle. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn tan(self) -> Ratio { self.value.tan().into() } /// Computes the value of the hyperbolic tangent of the angle. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn tanh(self) -> Ratio { self.value.tanh().into() } } #[cfg(feature = "std")] impl crate::si::Quantity where D: crate::si::Dimension + ?Sized, U: crate::si::Units + ?Sized, V: crate::num::Float + crate::Conversion, radian: crate::Conversion, { /// Computes the four quadrant arctangent of self (y) and other (x). #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn atan2(self, other: Self) -> Angle { Angle::new::(self.value.atan2(other.value)) } } #[cfg(test)] mod tests { storage_types! { use crate::lib::f64::consts::PI; use crate::num::{FromPrimitive, One}; use crate::si::angle as a; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_units() { Test::assert_eq(&Angle::new::(V::from_f64(2.0 * PI).unwrap()), &Angle::new::(V::one())); Test::assert_eq(&Angle::new::(V::from_f64(360.0).unwrap()), &Angle::new::(V::one())); Test::assert_approx_eq(&Angle::new::(V::from_f64(400.0).unwrap()), &Angle::new::(V::one())); Test::assert_eq(&Angle::new::(V::from_f64(60.0).unwrap()), &Angle::new::(V::one())); Test::assert_eq(&Angle::new::(V::from_f64(60.0 * 60.0).unwrap()), &Angle::new::(V::one())); } } #[cfg(feature = "std")] mod trig { storage_types! { types: Float; use crate::lib::f64::consts::PI; use crate::num::{FromPrimitive, Zero}; use crate::si::angle as a; use crate::si::length as l; use crate::si::quantities::*; use crate::tests::Test; #[test] fn sanity() { let zero: Angle = Angle::zero(); let nzero: Angle = -Angle::zero(); let pi: Angle = Angle::new::(V::from_f64(PI).unwrap()); let half: Angle = Angle::new::(V::from_f64(PI / 2.0).unwrap()); Test::assert_approx_eq(&zero.cos().into(), &1.0); Test::assert_approx_eq(&nzero.cos().into(), &1.0); Test::assert_approx_eq(&pi.cos().into(), &-1.0); Test::assert_approx_eq(&half.cos().into(), &0.0); Test::assert_approx_eq(&zero.sin().into(), &0.0); Test::assert_approx_eq(&nzero.sin().into(), &0.0); // Float inaccuracy does not guarantee approximate values // In these tests, it diverges slightly over the epsilon value //Test::assert_approx_eq(&pi.sin().into(), &0.0); //Test::assert_approx_eq(&half.sin().into(), &1.0); Test::assert_approx_eq(&zero.tan().into(), &0.0); Test::assert_approx_eq(&nzero.tan().into(), &0.0); //Test::assert_approx_eq(&pi.tan(), &0.0); // Cannot test for PI / 2 equality as it diverges to infinity // Float inaccuracy does not guarantee a NAN or INFINITY result //let result = half.tan().into(); //assert!(result == V::nan() || result == V::infinity()); Test::assert_approx_eq(&zero.cosh().into(), &1.0); Test::assert_approx_eq(&nzero.cosh().into(), &1.0); Test::assert_approx_eq(&zero.sinh().into(), &0.0); Test::assert_approx_eq(&nzero.sinh().into(), &0.0); Test::assert_approx_eq(&zero.tanh().into(), &0.0); Test::assert_approx_eq(&nzero.tanh().into(), &0.0); } quickcheck! { #[allow(trivial_casts)] fn atan2(y: V, x: V) -> bool { Test::eq(&y.atan2(x), &Length::new::(y).atan2(Length::new::(x)).get::()) } } #[test] fn turns() { Test::assert_approx_eq(&Angle::::HALF_TURN.cos().into(), &-1.0); Test::assert_approx_eq(&Angle::::FULL_TURN.cos().into(), &1.0); } } } } uom-0.35.0/src/si/angular_absement.rs000064400000000000000000000031511046102023000155700ustar 00000000000000//! Angular Absement (base unit radian second, s). quantity! { /// Angular Absement (base unit radian second, s). quantity: AngularAbsement; "angular absement"; /// Dimension of angular absement, T (base unit radian second, s). dimension: ISQ< Z0, // length Z0, // mass P1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::AngleKind); units { @radian_second: prefix!(none); "rad · s", "radian second", "radian seconds"; @degree_second: 1.745_329_251_994_329_5_E-2; "° · s", "degree second", "degree seconds"; } } #[cfg(test)] mod tests { storage_types! { use crate::si::angular_absement as a; use crate::si::angle as l; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; use crate::num::One; #[test] fn check_dimension() { let _: AngularAbsement = (Angle::new::(V::one()) * Time::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); fn test, T: t::Conversion, A: a::Conversion>() { Test::assert_eq(&AngularAbsement::new::(V::one()), &(Angle::new::(V::one()) * Time::new::(V::one())).into()); } } } } uom-0.35.0/src/si/angular_acceleration.rs000064400000000000000000000033641046102023000164310ustar 00000000000000//! Angular acceleration (base unit radian per second squared, s⁻²). quantity! { /// Angular acceleration (base unit radian per second squared, s⁻²). quantity: AngularAcceleration; "angular acceleration"; /// Dimension of angular acceleration, T⁻² (base unit radian per second squared, s⁻²). dimension: ISQ< Z0, // length Z0, // mass N2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::AngleKind); units { /// Derived unit of angular acceleration. @radian_per_second_squared: 1.0; "rad/s²", "radian per second squared", "radians per second squared"; @degree_per_second_squared: 1.745_329_251_994_329_5_E-2; "°/s²", "degree per second squared", "degrees per second squared"; } } #[cfg(test)] mod tests { storage_types! { use crate::si::angle as a; use crate::si::angular_acceleration as aa; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; use crate::num::One; #[test] fn check_units() { test::(); test::(); fn test, T: t::Conversion, R: aa::Conversion>() { let square_second = Time::new::(V::one()) * Time::new::(V::one()); Test::assert_approx_eq(&AngularAcceleration::new::(V::one()), &(Angle::new::(V::one()) / square_second).into()); } } } } uom-0.35.0/src/si/angular_jerk.rs000064400000000000000000000033751046102023000147350ustar 00000000000000//! Angular jerk (base unit radian per second cubed, s⁻³). quantity! { /// Angular jerk (base unit radian per second cubed, s⁻³). quantity: AngularJerk; "angular jerk"; /// Dimension of angular jerk, T⁻³ (base unit radian per second cubed, s⁻³). dimension: ISQ< Z0, // length Z0, // mass N3, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::AngleKind); units { /// Derived unit of angular jerk. @radian_per_second_cubed: 1.0; "rad/s³", "radian per second cubed", "radians per second cubed"; @degree_per_second_cubed: 1.745_329_251_994_329_5_E-2; "°/s³", "degree per second cubed", "degrees per second cubed"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::angle as a; use crate::si::angular_jerk as aj; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_units() { test::(); test::(); fn test, T: t::Conversion, R: aj::Conversion>() { let cubic_second = Time::new::(V::one()) * Time::new::(V::one()) * Time::new::(V::one()); Test::assert_approx_eq(&AngularJerk::new::(V::one()), &(Angle::new::(V::one()) / cubic_second).into()); } } } } uom-0.35.0/src/si/angular_velocity.rs000064400000000000000000000041661046102023000156370ustar 00000000000000//! Angular velocity (base unit radian per second, s⁻¹). quantity! { /// Angular velocity (base unit radian per second, s⁻¹). quantity: AngularVelocity; "angular velocity"; /// Dimension of angular velocity, T⁻¹ (base unit radian per second, s⁻¹). dimension: ISQ< Z0, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::AngleKind); units { /// Derived unit of angular velocity. @radian_per_second: 1.0_E0; "rad/s", "radian per second", "radians per second"; @degree_per_second: 1.745_329_251_994_329_5_E-2; "°/s", "degree per second", "degrees per second"; @revolution_per_second: 6.283_185_307_179_586_E0; "rps", "revolution per second", "revolutions per second"; @revolution_per_minute: 1.047_197_551_196_597_7_E-1; "rpm", "revolution per minute", "revolutions per minute"; @revolution_per_hour: 1.745_329_251_994_329_6_E-3; "rph", "revolution per hour", "revolutions per hour"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::angle as a; use crate::si::angular_velocity as v; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, R: v::Conversion>() { Test::assert_approx_eq(&AngularVelocity::new::(V::one()), &(Angle::new::(V::one()) / Time::new::(V::one())).into()); } } } } uom-0.35.0/src/si/area.rs000064400000000000000000000133021046102023000131700ustar 00000000000000//! Area (base unit square meter, m²). quantity! { /// Area (base unit square meter, m²). quantity: Area; "area"; /// Dimension of area, L² (base unit square meter, m²). dimension: ISQ< P2, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @square_yottameter: prefix!(yotta) * prefix!(yotta); "Ym²", "square yottameter", "square yottameters"; @square_zettameter: prefix!(zetta) * prefix!(zetta); "Zm²", "square zettameter", "square zettameters"; @square_exameter: prefix!(exa) * prefix!(exa); "Em²", "square exameter", "square exameters"; @square_petameter: prefix!(peta) * prefix!(peta); "Pm²", "square petameter", "square petameters"; @square_terameter: prefix!(tera) * prefix!(tera); "Tm²", "square terameter", "square terameters"; @square_gigameter: prefix!(giga) * prefix!(giga); "Gm²", "square gigameter", "square gigameters"; @square_megameter: prefix!(mega) * prefix!(mega); "Mm²", "square megameter", "square megameters"; @square_kilometer: prefix!(kilo) * prefix!(kilo); "km²", "square kilometer", "square kilometers"; @square_hectometer: prefix!(hecto) * prefix!(hecto); "hm²", "square hectometer", "square hectometers"; @square_decameter: prefix!(deca) * prefix!(deca); "dam²", "square decameter", "square decameters"; @square_meter: prefix!(none); "m²", "square meter", "square meters"; @square_decimeter: prefix!(deci) * prefix!(deci); "dm²", "square decimeter", "square decimeters"; @square_centimeter: prefix!(centi) * prefix!(centi); "cm²", "square centimeter", "square centimeters"; @square_millimeter: prefix!(milli) * prefix!(milli); "mm²", "square millimeter", "square millimeters"; @square_micrometer: prefix!(micro) * prefix!(micro); "µm²", "square micrometer", "square micrometers"; @square_nanometer: prefix!(nano) * prefix!(nano); "nm²", "square nanometer", "square nanometers"; @square_picometer: prefix!(pico) * prefix!(pico); "pm²", "square picometer", "square picometers"; @square_femtometer: prefix!(femto) * prefix!(femto); "fm²", "square femtometer", "square femtometers"; @square_attometer: prefix!(atto) * prefix!(atto); "am²", "square attometer", "square attometers"; @square_zeptometer: prefix!(zepto) * prefix!(zepto); "zm²", "square zeptometer", "square zeptometers"; @square_yoctometer: prefix!(yocto) * prefix!(yocto); "ym²", "square yoctometer", "square yoctometers"; @acre: 4.046_873_E3; "ac", "acre", "acres"; @are: 1.0_E2; "a", "are", "ares"; @barn: 1.0_E-28; "b", "barn", "barns"; @circular_mil: 5.067_075_E-10; "cmil", "circular mil", "circular mils"; @hectare: 1.0_E4; "ha", "hectare", "hectares"; @square_foot: 9.290_304_E-2; "ft²", "square foot", "square feet"; @square_inch: 6.451_6_E-4; "in²", "square inch", "square inches"; @square_mile: 2.589_988_E6; "mi²", "square mile", "square miles"; @square_yard: 8.361_274_E-1; "yd²", "square yard", "square yards"; } } #[cfg(test)] mod tests { storage_types! { use crate::lib::any::TypeId; use crate::num::One; use crate::si::area as a; use crate::si::length as l; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: Area = Length::new::(V::one()) * Length::new::(V::one()); } #[test] // #392: Disable tests on ARM until issues with floating point behavior can be resolved. #[cfg(not(target_arch = "arm"))] fn check_units() { // Values too large for f32. if TypeId::of::() == TypeId::of::() { test::(); test::(); } test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); // Values too small for f32. if TypeId::of::() == TypeId::of::() { test::(); } fn test, A: a::Conversion>() { Test::assert_eq(&Area::new::(V::one()), &(Length::new::(V::one()) * Length::new::(V::one()))); } } } } uom-0.35.0/src/si/areal_density_of_states.rs000064400000000000000000000047341046102023000171630ustar 00000000000000//! Areal density of states (base unit 1 / square meter joule, kg⁻¹ · m⁻⁴ · s²). quantity! { /// Areal density of states (base unit 1 / square meter joule, kg⁻¹ · m⁻⁴ · s²). quantity: ArealDensityOfStates; "areal density of states"; /// Dimension of areal density of states, L⁻⁴M⁻¹T² (base unit 1 / square meter joule, kg⁻¹ · m⁻⁴ · s²). dimension: ISQ< N4, // length N1, // mass P2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @state_per_square_meter_joule: prefix!(none); "1/(m² · J)", "state per square meter joule", "states per square meter joule"; @state_per_square_centimeter_joule: prefix!(none) / prefix!(centi) / prefix!(centi); "1/(cm² · J)", "state per square centimeter joule", "states per square centimeter joule"; @state_per_square_centimeter_electronvolt: prefix!(none) / prefix!(centi) / prefix!(centi) / 1.602_176_634_E-19; "1/(cm² · eV)", "state per square centimeter electronvolt", "states per square centimeter electronvolt"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::areal_density_of_states as ados; use crate::si::energy as e; use crate::si::quantities::*; use crate::si::area as a; use crate::tests::Test; #[test] fn check_dimension() { let _: ArealDensityOfStates = (V::one() / Energy::new::(V::one()) / Area::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); fn test, E: e::Conversion, ADOS: ados::Conversion>() { Test::assert_approx_eq(&ArealDensityOfStates::new::(V::one()), &(V::one() / Energy::new::(V::one()) / Area::new::(V::one())).into()); } } } } uom-0.35.0/src/si/areal_mass_density.rs000064400000000000000000000043041046102023000161300ustar 00000000000000//! Areal mass density (base unit kilogram per square meter, m⁻² · kg). quantity! { /// Areal mass density (base unit kilogram per square meter, m⁻² · kg). quantity: ArealMassDensity; "areal mass density"; /// Dimension of areal mass density, L⁻²M (base unit kilogram per square meter, m⁻² · kg). dimension: ISQ< N2, // length P1, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @kilogram_per_square_meter: prefix!(none); "kg/m²", "kilogram per square meter", "kilograms per square meter"; @gram_per_square_meter: prefix!(milli); "g/m²", "gram per square meter", "grams per square meter"; @gram_per_square_centimeter: prefix!(milli) / prefix!(centi) / prefix!(centi); "g/cm²", "gram per square centimeter", "grams per square centimeter"; @ounce_per_square_foot: 2.834_952_E-2 / 9.290_304_E-2; "oz/ft²", "ounce per square foot", "ounces per square foot"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::mass as m; use crate::si::areal_mass_density as d; use crate::si::quantities::*; use crate::si::area as a; use crate::tests::Test; #[test] fn check_dimension() { let _: ArealMassDensity = Mass::new::(V::one()) / Area::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); fn test, A: a::Conversion, D: d::Conversion>() { Test::assert_approx_eq(&ArealMassDensity::new::(V::one()), &(Mass::new::(V::one()) / Area::new::(V::one()))); } } } } uom-0.35.0/src/si/areal_number_density.rs000064400000000000000000000075771046102023000164740ustar 00000000000000//! Areal number density (base unit 1 per square meter, m⁻²). quantity! { /// Areal number density (base unit 1 per square meter, m⁻²). quantity: ArealNumberDensity; "areal number density"; /// Dimension of areal number density, L⁻² (base unit 1 per square meter, m⁻²). dimension: ISQ< N2, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @per_square_kilometer: prefix!(none) / prefix!(kilo) / prefix!(kilo); "km⁻²", "per square kilometer", "per square kilometer"; @per_square_meter: prefix!(none); "m⁻²", "per square meter", "per square meter"; @per_square_decimeter: prefix!(none) / prefix!(deci) / prefix!(deci); "dm⁻²", "per square decimeter", "per square decimeter"; @per_square_centimeter: prefix!(none) / prefix!(centi) / prefix!(centi); "cm⁻²", "per square centimeter", "per square centimeter"; @per_square_millimeter: prefix!(none) / prefix!(milli) / prefix!(milli); "mm⁻²", "per square millimeter", "per square millimeter"; @per_square_micrometer: prefix!(none) / prefix!(micro) / prefix!(micro); "µm⁻²", "per square micrometer", "per square micrometer"; @per_acre: prefix!(none) / 4.046_873_E3; "ac⁻²", "per acre", "per acre"; @per_are: prefix!(none) / 1.0_E2; "a⁻²", "per are", "per are"; @per_barn: prefix!(none) / 1.0_E-28; "b⁻²", "per barn", "per barn"; @per_circular_mil: prefix!(none) / 5.067_075_E-10; "cmil⁻²", "per circular mil", "per circular mil"; @per_hectare: prefix!(none) / 1.0_E4; "ha⁻²", "per hectare", "per hectare"; @per_square_foot: prefix!(none) / 9.290_304_E-2; "ft⁻²", "per square foot", "per square foot"; @per_square_inch: prefix!(none) / 6.451_6_E-4; "in⁻²", "per square inch", "per square inch"; @per_square_mile: prefix!(none) / 2.589_988_E6; "mi⁻²", "per square mile", "per square mile"; @per_square_yard: prefix!(none) / 8.361_274_E-1; "yd⁻²", "per square yard", "per square yard"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::area as a; use crate::si::areal_number_density as n; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: ArealNumberDensity = (V::one() / Area::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, A: a::Conversion>() { Test::assert_approx_eq(&ArealNumberDensity::new::(V::one()), &(V::one() / Area::new::(V::one())).into()); } } } } uom-0.35.0/src/si/areal_number_rate.rs000064400000000000000000000075271046102023000157430ustar 00000000000000//! Areal number rate (base unit 1 per square meter second, m⁻² · s⁻¹). quantity! { /// Areal number rate (base unit 1 per square meter second, m⁻² · s⁻¹). quantity: ArealNumberRate; "areal number rate"; /// Dimension of areal number rate, L⁻²T⁻¹ (base unit 1 per square meter second, m⁻² · s⁻¹). dimension: ISQ< N2, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @per_square_meter_second: prefix!(none); "m⁻² · s⁻¹", "per square meter second", "per square meter second"; @per_square_centimeter_second: prefix!(none) / prefix!(centi) / prefix!(centi); "cm⁻² · s⁻¹", "per square centimeter second", "per square centimeter second"; @per_acre_second: prefix!(none) / 4.046_873_E3; "ac⁻¹ · s⁻¹", "per acre second", "per acre second"; @per_are_second: prefix!(none) / 1.0_E2; "a⁻¹ · s⁻¹", "per are second", "per are second"; @per_barn_second: prefix!(none) / 1.0_E-28; "b⁻¹ · s⁻¹", "per barn second", "per barn second"; @per_circular_mil_second: prefix!(none) / 5.067_075_E-10; "cmil⁻¹ · s⁻¹", "per circular mil second", "per circular mil second"; @per_hectare_second: prefix!(none) / 1.0_E4; "ha⁻¹ · s⁻¹", "per hectare second", "per hectare second"; @per_square_foot_second: prefix!(none) / 9.290_304_E-2; "ft⁻² · s⁻¹", "per square foot second", "per square foot second"; @per_square_inch_second: prefix!(none) / 6.451_6_E-4; "in⁻² · s⁻¹", "per square inch second", "per square inch second"; @per_square_mile_second: prefix!(none) / 2.589_988_E6; "mi⁻² · s⁻¹", "per square mile second", "per square mile second"; @per_square_yard_second: prefix!(none) / 8.361_274_E-1; "yd⁻² · s⁻¹", "per square yard second", "per square yard second"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::areal_number_rate as anr; use crate::si::quantities::*; use crate::si::time as t; use crate::si::area as a; use crate::tests::Test; #[test] fn check_dimension() { let _: ArealNumberRate = (V::one() / Time::new::(V::one()) / Area::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, A: a::Conversion, T: t::Conversion>() { Test::assert_approx_eq(&ArealNumberRate::new::(V::one()), &(V::one() / Time::new::(V::one()) / Area::new::(V::one())).into()); } } } } uom-0.35.0/src/si/available_energy.rs000064400000000000000000000163201046102023000155540ustar 00000000000000//! Available energy (base unit joule per kilogram, m² · s⁻²). quantity! { /// Available energy (base unit joule per kilogram, m² · s⁻²). quantity: AvailableEnergy; "available energy"; /// Dimension of available energy, L²T⁻² (base unit joule per kilogram, m² · s⁻²). dimension: ISQ< P2, // length Z0, // mass N2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottajoule_per_kilogram: prefix!(yotta); "YJ/kg", "yottajoule per kilogram", "yottajoules per kilogram"; @zettajoule_per_kilogram: prefix!(zetta); "ZJ/kg", "zettajoule per kilogram", "zettajoules per kilogram"; @exajoule_per_kilogram: prefix!(exa); "EJ/kg", "exajoule per kilogram", "exajoules per kilogram"; @petajoule_per_kilogram: prefix!(peta); "PJ/kg", "petajoule per kilogram", "petajoules per kilogram"; @terajoule_per_kilogram: prefix!(tera); "TJ/kg", "terajoule per kilogram", "terajoules per kilogram"; @gigajoule_per_kilogram: prefix!(giga); "GJ/kg", "gigajoule per kilogram", "gigajoules per kilogram"; @megajoule_per_kilogram: prefix!(mega); "MJ/kg", "megajoule per kilogram", "megajoules per kilogram"; @kilojoule_per_kilogram: prefix!(kilo); "kJ/kg", "kilojoule per kilogram", "kilojoules per kilogram"; @hectojoule_per_kilogram: prefix!(hecto); "hJ/kg", "hectojoule per kilogram", "hectojoules per kilogram"; @decajoule_per_kilogram: prefix!(deca); "daJ/kg", "decajoule per kilogram", "decajoules per kilogram"; /// Derived unit of available energy. @joule_per_kilogram: prefix!(none); "J/kg", "joule per kilogram", "joules per kilogram"; @decijoule_per_kilogram: prefix!(deci); "dJ/kg", "decijoule per kilogram", "decijoules per kilogram"; @centijoule_per_kilogram: prefix!(centi); "cJ/kg", "centijoule per kilogram", "centijoules per kilogram"; @millijoule_per_kilogram: prefix!(milli); "mJ/kg", "millijoule per kilogram", "millijoules per kilogram"; @microjoule_per_kilogram: prefix!(micro); "µJ/kg", "microjoule per kilogram", "microjoules per kilogram"; @nanojoule_per_kilogram: prefix!(nano); "nJ/kg", "nanojoule per kilogram", "nanojoules per kilogram"; @picojoule_per_kilogram: prefix!(pico); "pJ/kg", "picojoule per kilogram", "picojoules per kilogram"; @femtojoule_per_kilogram: prefix!(femto); "fJ/kg", "femtojoule per kilogram", "femtojoules per kilogram"; @attojoule_per_kilogram: prefix!(atto); "aJ/kg", "attojoule per kilogram", "attojoules per kilogram"; @zeptojoule_per_kilogram: prefix!(zepto); "zJ/kg", "zeptojoule per kilogram", "zeptojoules per kilogram"; @yoctojoule_per_kilogram: prefix!(yocto); "yJ/kg", "yoctojoule per kilogram", "yoctojoules per kilogram"; @joule_per_zeptogram: prefix!(yotta); "J/zg", "joule per zeptogram", "joules per zeptogram"; @joule_per_attogram: prefix!(zetta); "J/ag", "joule per attogram", "joules per attogram"; @joule_per_femtogram: prefix!(exa); "J/fg", "joule per femtogram", "joules per femtogram"; @joule_per_picogram: prefix!(peta); "J/pg", "joule per picogram", "joules per picogram"; @joule_per_nanogram: prefix!(tera); "J/ng", "joule per nanogram", "joules per nanogram"; @joule_per_microgram: prefix!(giga); "J/µg", "joule per microgram", "joules per microgram"; @joule_per_milligram: prefix!(mega); "J/mg", "joule per milligram", "joules per milligram"; @joule_per_gram: prefix!(kilo); "J/g", "joule per gram", "joules per gram"; @joule_per_megagram: prefix!(milli); "J/Mg", "joule per megagram", "joules per megagram"; @joule_per_gigagram: prefix!(micro); "J/Gg", "joule per gigagram", "joules per gigagram"; @joule_per_teragram: prefix!(nano); "J/Tg", "joule per teragram", "joules per teragram"; @joule_per_petagram: prefix!(pico); "J/Pg", "joule per petagram", "joules per petagram"; @joule_per_exagram: prefix!(femto); "J/Eg", "joule per exagram", "joules per exagram"; @joule_per_zettagram: prefix!(atto); "J/Zg", "joule per zettagram", "joules per zettagram"; @joule_per_yottagram: prefix!(zepto); "J/Yg", "joule per yottagram", "joules per yottagram"; @btu_it_per_pound: 2.326_000_171_078_704_E3; "Btu (IT)/lb", "British thermal unit (IT) per pound", "British thermal units (IT) per pound"; @btu_per_pound: 2.324_443_707_610_621_E3; "Btu/lb", "British thermal unit per pound", "British thermal units per pound"; @calorie_it_per_gram: 4.186_8_E3; "cal (IT)/lb", "calorie (IT) per gram", "calories (IT) per gram"; @calorie_per_gram: 4.184_E3; "cal/lb", "calorie per gram", "calories per gram"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::available_energy as v; use crate::si::energy as e; use crate::si::mass as m; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: AvailableEnergy = Energy::new::(V::one()) / Mass::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, M: m::Conversion, A: v::Conversion>() { Test::assert_approx_eq(&AvailableEnergy::new::(V::one()), &(Energy::new::(V::one()) / Mass::new::(V::one()))); } } } } uom-0.35.0/src/si/capacitance.rs000064400000000000000000000107361046102023000145230ustar 00000000000000//! Capacitance (base unit farad, m⁻² · kg⁻¹ · s⁴ · A²). quantity! { /// Capacitance (base unit farad, m⁻² · kg⁻¹ · s⁴ · A²). quantity: Capacitance; "capacitance"; /// Dimension of capacitance, L⁻²M⁻¹T⁴I² (base unit farad, m⁻² · kg⁻¹ · s⁴ · A²). dimension: ISQ< N2, // length N1, // mass P4, // time P2, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottafarad: prefix!(yotta); "YF", "yottafarad", "yottafarads"; @zettafarad: prefix!(zetta); "ZF", "zettafarad", "zettafarads"; @exafarad: prefix!(exa); "EF", "exafarad", "exafarads"; @petafarad: prefix!(peta); "PF", "petafarad", "petafarads"; @terafarad: prefix!(tera); "TF", "terafarad", "terafarads"; @gigafarad: prefix!(giga); "GF", "gigafarad", "gigafarads"; @megafarad: prefix!(mega); "MF", "megafarad", "megafarads"; @kilofarad: prefix!(kilo); "kF", "kilofarad", "kilofarads"; @hectofarad: prefix!(hecto); "hF", "hectofarad", "hectofarads"; @decafarad: prefix!(deca); "daF", "decafarad", "decafarads"; /// Derived unit of capacitance. @farad: prefix!(none); "F", "farad", "farads"; @decifarad: prefix!(deci); "dF", "decifarad", "decifarads"; @centifarad: prefix!(centi); "cF", "centifarad", "centifarads"; @millifarad: prefix!(milli); "mF", "millifarad", "millifarads"; @microfarad: prefix!(micro); "µF", "microfarad", "microfarads"; @nanofarad: prefix!(nano); "nF", "nanofarad", "nanofarads"; @picofarad: prefix!(pico); "pF", "picofarad", "picofarads"; @femtofarad: prefix!(femto); "fF", "femtofarad", "femtofarads"; @attofarad: prefix!(atto); "aF", "attofarad", "attofarads"; @zeptofarad: prefix!(zepto); "zF", "zeptofarad", "zeptofarads"; @yoctofarad: prefix!(yocto); "yF", "yoctofarad", "yoctofarads"; @abfarad: 1.0_E9; "abF", "abfarad", "abfarads"; @statfarad: 1.112_650_E-12; "statF", "statfarad", "statfarads"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::capacitance as c; use crate::si::electric_current as i; use crate::si::electric_potential as v; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: Capacitance = ElectricCurrent::new::(V::one()) * Time::new::(V::one()) / ElectricPotential::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, U: v::Conversion, C: c::Conversion>() { Test::assert_approx_eq(&Capacitance::new::(V::one()), &(ElectricCurrent::new::(V::one()) * Time::new::(V::one()) / ElectricPotential::new::(V::one()))); } } } } uom-0.35.0/src/si/catalytic_activity.rs000064400000000000000000000230211046102023000161500ustar 00000000000000//! Catalytic activity (base unit katal, mol · s⁻¹). quantity! { /// Catalytic activity (base unit katal, mol · s⁻¹). quantity: CatalyticActivity; "catalytic activity"; /// Dimension of catalytic activity, T⁻¹N (base unit katal, mol · s⁻¹). dimension: ISQ< Z0, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature P1, // amount of substance Z0>; // luminous intensity units { @yottakatal: prefix!(yotta); "Ykat", "yottakatal", "yottakatals"; @zettakatal: prefix!(zetta); "Zkat", "zettakatal", "zettakatals"; @exakatal: prefix!(exa); "Ekat", "exakatal", "exakatals"; @petakatal: prefix!(peta); "Pkat", "petakatal", "petakatals"; @terakatal: prefix!(tera); "Tkat", "terakatal", "terakatals"; @gigakatal: prefix!(giga); "Gkat", "gigakatal", "gigakatals"; @megakatal: prefix!(mega); "Mkat", "megakatal", "megakatals"; @kilokatal: prefix!(kilo); "kkat", "kilokatal", "kilokatals"; @hectokatal: prefix!(hecto); "hkat", "hectokatal", "hectokatals"; @decakatal: prefix!(deca); "dakat", "decakatal", "decakatals"; @katal: prefix!(none); "kat", "katal", "katals"; @decikatal: prefix!(deci); "dkat", "decikatal", "decikatals"; @centikatal: prefix!(centi); "ckat", "centikatal", "centikatals"; @millikatal: prefix!(milli); "mkat", "millikatal", "millikatals"; @microkatal: prefix!(micro); "µkat", "microkatal", "microkatals"; @nanokatal: prefix!(nano); "nkat", "nanokatal", "nanokatals"; @picokatal: prefix!(pico); "pkat", "picokatal", "picokatals"; @femtokatal: prefix!(femto); "fkat", "femtokatal", "femtokatals"; @attokatal: prefix!(atto); "akat", "attokatal", "attokatals"; @zeptokatal: prefix!(zepto); "zkat", "zeptokatal", "zeptokatals"; @yoctokatal: prefix!(yocto); "ykat", "yoctokatal", "yoctokatals"; @yotta_enzyme_unit: prefix!(yotta) * prefix!(micro) / 6.0_E1; "YU", "yotta enzyme unit", "yotta enzyme units"; @zetta_enzyme_unit: prefix!(zetta) * prefix!(micro) / 6.0_E1; "ZU", "zetta enzyme unit", "zetta enzyme units"; @exa_enzyme_unit: prefix!(exa) * prefix!(micro) / 6.0_E1; "EU", "exa enzyme unit", "exa enzyme units"; @peta_enzyme_unit: prefix!(peta) * prefix!(micro) / 6.0_E1; "PU", "peta enzyme unit", "peta enzyme units"; @tera_enzyme_unit: prefix!(tera) * prefix!(micro) / 6.0_E1; "TU", "tera enzyme unit", "tera enzyme units"; @giga_enzyme_unit: prefix!(giga) * prefix!(micro) / 6.0_E1; "GU", "giga enzyme unit", "giga enzyme units"; @mega_enzyme_unit: prefix!(mega) * prefix!(micro) / 6.0_E1; "MU", "mega enzyme unit", "mega enzyme units"; @kilo_enzyme_unit: prefix!(kilo) * prefix!(micro) / 6.0_E1; "kU", "kilo enzyme unit", "kilo enzyme units"; @hecto_enzyme_unit: prefix!(hecto) * prefix!(micro) / 6.0_E1; "hU", "hecto enzyme unit", "hecto enzyme units"; @deca_enzyme_unit: prefix!(deca) * prefix!(micro) / 6.0_E1; "daU", "deca enzyme unit", "deca enzyme units"; @enzyme_unit: prefix!(none) * prefix!(micro) / 6.0_E1; "U", "enzyme unit", "enzyme units"; @deci_enzyme_unit: prefix!(deci) * prefix!(micro) / 6.0_E1; "dU", "deci enzyme unit", "deci enzyme units"; @centi_enzyme_unit: prefix!(centi) * prefix!(micro) / 6.0_E1; "cU", "centi enzyme unit", "centi enzyme units"; @milli_enzyme_unit: prefix!(milli) * prefix!(micro) / 6.0_E1; "mU", "milli enzyme unit", "milli enzyme units"; @micro_enzyme_unit: prefix!(micro) * prefix!(micro) / 6.0_E1; "μU", "micro enzyme unit", "micro enzyme units"; @nano_enzyme_unit: prefix!(nano) * prefix!(micro) / 6.0_E1; "nU", "nano enzyme unit", "nano enzyme units"; @pico_enzyme_unit: prefix!(pico) * prefix!(micro) / 6.0_E1; "pU", "pico enzyme unit", "pico enzyme units"; @femto_enzyme_unit: prefix!(femto) * prefix!(micro) / 6.0_E1; "fU", "femto enzyme unit", "femto enzyme units"; @atto_enzyme_unit: prefix!(atto) * prefix!(micro) / 6.0_E1; "aU", "atto enzyme unit", "atto enzyme units"; @zepto_enzyme_unit: prefix!(zepto) * prefix!(micro) / 6.0_E1; "zU", "zepto enzyme unit", "zepto enzyme units"; @yocto_enzyme_unit: prefix!(yocto) * prefix!(micro) / 6.0_E1; "yU", "yocto enzyme unit", "yocto enzyme units"; @particle_per_second: 1.0_E0 / 6.022_140_76_E23; "particle/s", "particle per second", "particles per second"; @mole_per_second: prefix!(none); "mol/s", "mole per second", "moles per second"; @standard_centimeter_per_minute: 1_E5 * prefix!(micro) / 8.314_462_618 / 273.15 / 60.0; "sccm", "standard centimeter per minute", "standard centimeters per minute"; @standard_liter_per_minute: 1_E5 * prefix!(milli) / 8.314_462_618 / 273.15 / 60.0; "slm", "standard liter per minute", "standard liters per minute"; @standard_cubic_meter_per_minute: 1_E5 * prefix!(none) / 8.314_462_618 / 273.15 / 60.0; "m³(STP)/min", "standard cubic meter per minute", "standard cubic meters per minute"; @standard_cubic_foot_per_minute: 1_E5 * 2.831_685_E-2 / 8.314_462_618 / 273.15 / 60.0; "scfm", "standard cubic foot per hour", "standard cubic feet per hour"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::amount_of_substance as aos; use crate::si::catalytic_activity as ca; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: Time = AmountOfSubstance::new::(V::one()) / CatalyticActivity::new::(V::one()); let _: CatalyticActivity = AmountOfSubstance::new::(V::one()) / Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, CA: ca::Conversion>() { Test::assert_approx_eq( &(AmountOfSubstance::new::(V::one()) / Time::new::(V::one())), &CatalyticActivity::new::(V::one())); Test::assert_approx_eq( &Time::new::(V::one()), &(AmountOfSubstance::new::(V::one()) / CatalyticActivity::new::(V::one()))); } } } } uom-0.35.0/src/si/catalytic_activity_concentration.rs000064400000000000000000000670001046102023000211030ustar 00000000000000//! Catalytic activity concentration (base unit katal per cubic meter, mol · s⁻¹ · m⁻³). quantity! { /// Catalytic activity concentration (base unit katal per cubic meter, mol · s⁻¹ · m⁻³). quantity: CatalyticActivityConcentration; "catalytic activity concentration"; /// Dimension of catalytic activity concentration, L⁻³T⁻¹N /// (base unit katal per cubic meter, mol · s⁻¹ · m⁻³). dimension: ISQ< N3, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature P1, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @yottakatal_per_cubic_meter: prefix!(yotta); "Ykat/m³", "yottakatal per cubic meter", "yottakatals per cubic meter"; @zettakatal_per_cubic_meter: prefix!(zetta); "Zkat/m³", "zettakatal per cubic meter", "zettakatals per cubic meter"; @exakatal_per_cubic_meter: prefix!(exa); "Ekat/m³", "exakatal per cubic meter", "exakatals per cubic meter"; @petakatal_per_cubic_meter: prefix!(peta); "Pkat/m³", "petakatal per cubic meter", "petakatals per cubic meter"; @terakatal_per_cubic_meter: prefix!(tera); "Tkat/m³", "terakatal per cubic meter", "terakatals per cubic meter"; @gigakatal_per_cubic_meter: prefix!(giga); "Gkat/m³", "gigakatal per cubic meter", "gigakatals per cubic meter"; @megakatal_per_cubic_meter: prefix!(mega); "Mkat/m³", "megakatal per cubic meter", "megakatals per cubic meter"; @kilokatal_per_cubic_meter: prefix!(kilo); "kkat/m³", "kilokatal per cubic meter", "kilokatals per cubic meter"; @hectokatal_per_cubic_meter: prefix!(hecto); "hkat/m³", "hectokatal per cubic meter", "hectokatals per cubic meter"; @decakatal_per_cubic_meter: prefix!(deca); "dakat/m³", "decakatal per cubic meter", "decakatals per cubic meter"; @katal_per_cubic_meter: prefix!(none); "kat/m³", "katal per cubic meter", "katals per cubic meter"; @decikatal_per_cubic_meter: prefix!(deci); "dkat/m³", "decikatal per cubic meter", "decikatals per cubic meter"; @centikatal_per_cubic_meter: prefix!(centi); "ckat/m³", "centikatal per cubic meter", "centikatals per cubic meter"; @millikatal_per_cubic_meter: prefix!(milli); "mkat/m³", "millikatal per cubic meter", "millikatals per cubic meter"; @microkatal_per_cubic_meter: prefix!(micro); "µkat/m³", "microkatal per cubic meter", "microkatals per cubic meter"; @nanokatal_per_cubic_meter: prefix!(nano); "nkat/m³", "nanokatal per cubic meter", "nanokatals per cubic meter"; @picokatal_per_cubic_meter: prefix!(pico); "pkat/m³", "picokatal per cubic meter", "picokatals per cubic meter"; @femtokatal_per_cubic_meter: prefix!(femto); "fkat/m³", "femtokatal per cubic meter", "femtokatals per cubic meter"; @attokatal_per_cubic_meter: prefix!(atto); "akat/m³", "attokatal per cubic meter", "attokatals per cubic meter"; @zeptokatal_per_cubic_meter: prefix!(zepto); "zkat/m³", "zeptokatal per cubic meter", "zeptokatals per cubic meter"; @yoctokatal_per_cubic_meter: prefix!(yocto); "ykat/m³", "yoctokatal per cubic meter", "yoctokatals per cubic meter"; @kilokatal_per_cubic_decimeter: prefix!(kilo) / prefix!(deci) / prefix!(deci) / prefix!(deci); "kkat/dm³", "kilokatal per cubic decimeter", "kilokatals per cubic decimeter"; @kilokatal_per_liter: prefix!(kilo) / prefix!(milli); "kkat/L", "kilokatal per liter", "kilokatals per liter"; @katal_per_cubic_decimeter: prefix!(none) / prefix!(deci) / prefix!(deci) / prefix!(deci); "kat/dm³", "katal per cubic decimeter", "katals per cubic decimeter"; @katal_per_liter: prefix!(none) / prefix!(milli); "kat/L", "katal per liter", "katals per liter"; @millikatal_per_cubic_decimeter: prefix!(milli) / prefix!(deci) / prefix!(deci) / prefix!(deci); "mkat/dm³", "millikatal per cubic decimeter", "millikatals per cubic decimeter"; @millikatal_per_liter: prefix!(milli) / prefix!(milli); "mkat/L", "millikatal per liter", "millikatals per liter"; @microkatal_per_cubic_decimeter: prefix!(micro) / prefix!(deci) / prefix!(deci) / prefix!(deci); "μkat/dm³", "microkatal per cubic decimeter", "microkatals per cubic decimeter"; @microkatal_per_liter: prefix!(micro) / prefix!(milli); "μkat/L", "microkatal per liter", "microkatals per liter"; @nanokatal_per_cubic_decimeter: prefix!(nano) / prefix!(deci) / prefix!(deci) / prefix!(deci); "nkat/dm³", "nanokatal per cubic decimeter", "nanokatals per cubic decimeter"; @nanokatal_per_liter: prefix!(nano) / prefix!(milli); "nkat/L", "nanokatal per liter", "nanokatals per liter"; @picokatal_per_cubic_decimeter: prefix!(pico) / prefix!(deci) / prefix!(deci) / prefix!(deci); "pkat/dm³", "picokatal per cubic decimeter", "picokatals per cubic decimeter"; @picokatal_per_liter: prefix!(pico) / prefix!(milli); "pkat/L", "picokatal per liter", "picokatals per liter"; @femtokatal_per_cubic_decimeter: prefix!(femto) / prefix!(deci) / prefix!(deci) / prefix!(deci); "fkat/dm³", "femtokatal per cubic decimeter", "femtokatals per cubic decimeter"; @femtokatal_per_liter: prefix!(femto) / prefix!(milli); "fkat/L", "femtokatal per liter", "femtokatals per liter"; @kilokatal_per_deciliter: prefix!(kilo) / prefix!(deci) / prefix!(milli); "kkat/dL", "kilokatal per deciliter", "kilokatals per deciliter"; @katal_per_deciliter: prefix!(none) / prefix!(deci) / prefix!(milli); "kat/dL", "katal per deciliter", "katals per deciliter"; @millikatal_per_deciliter: prefix!(milli) / prefix!(deci) / prefix!(milli); "mkat/dL", "millikatal per deciliter", "millikatals per deciliter"; @microkatal_per_deciliter: prefix!(micro) / prefix!(deci) / prefix!(milli); "μkat/dL", "microkatal per deciliter", "microkatals per deciliter"; @nanokatal_per_deciliter: prefix!(nano) / prefix!(deci) / prefix!(milli); "nkat/dL", "nanokatal per deciliter", "nanokatals per deciliter"; @picokatal_per_deciliter: prefix!(pico) / prefix!(deci) / prefix!(milli); "pkat/dL", "picokatal per deciliter", "picokatals per deciliter"; @femtokatal_per_deciliter: prefix!(femto) / prefix!(deci) / prefix!(milli); "fkat/dL", "femtokatal per deciliter", "femtokatals per deciliter"; @kilokatal_per_milliliter: prefix!(kilo) / prefix!(milli) / prefix!(milli); "kkat/mL", "kilokatal per milliliter", "kilokatals per milliliter"; @katal_per_milliliter: prefix!(none) / prefix!(milli) / prefix!(milli); "kat/mL", "katal per milliliter", "katals per milliliter"; @millikatal_per_milliliter: prefix!(milli) / prefix!(milli) / prefix!(milli); "mkat/mL", "millikatal per milliliter", "millikatals per milliliter"; @microkatal_per_milliliter: prefix!(micro) / prefix!(milli) / prefix!(milli); "μkat/mL", "microkatal per milliliter", "microkatals per milliliter"; @nanokatal_per_milliliter: prefix!(nano) / prefix!(milli) / prefix!(milli); "nkat/mL", "nanokatal per milliliter", "nanokatals per milliliter"; @picokatal_per_milliliter: prefix!(pico) / prefix!(milli) / prefix!(milli); "pkat/mL", "picokatal per milliliter", "picokatals per milliliter"; @femtokatal_per_milliliter: prefix!(femto) / prefix!(milli) / prefix!(milli); "fkat/mL", "femtokatal per milliliter", "femtokatals per milliliter"; @yotta_enzyme_unit_per_cubic_meter: prefix!(yotta) * prefix!(micro) / 6.0_E1; "YU/m³", "yotta enzyme unit per cubic meter", "yotta enzyme units per cubic meter"; @zetta_enzyme_unit_per_cubic_meter: prefix!(zetta) * prefix!(micro) / 6.0_E1; "ZU/m³", "zetta enzyme unit per cubic meter", "zetta enzyme units per cubic meter"; @exa_enzyme_unit_per_cubic_meter: prefix!(exa) * prefix!(micro) / 6.0_E1; "EU/m³", "exa enzyme unit per cubic meter", "exa enzyme units per cubic meter"; @peta_enzyme_unit_per_cubic_meter: prefix!(peta) * prefix!(micro) / 6.0_E1; "PU/m³", "peta enzyme unit per cubic meter", "peta enzyme units per cubic meter"; @tera_enzyme_unit_per_cubic_meter: prefix!(tera) * prefix!(micro) / 6.0_E1; "TU/m³", "tera enzyme unit per cubic meter", "tera enzyme units per cubic meter"; @giga_enzyme_unit_per_cubic_meter: prefix!(giga) * prefix!(micro) / 6.0_E1; "GU/m³", "giga enzyme unit per cubic meter", "giga enzyme units per cubic meter"; @mega_enzyme_unit_per_cubic_meter: prefix!(mega) * prefix!(micro) / 6.0_E1; "MU/m³", "mega enzyme unit per cubic meter", "mega enzyme units per cubic meter"; @kilo_enzyme_unit_per_cubic_meter: prefix!(kilo) * prefix!(micro) / 6.0_E1; "kU/m³", "kilo enzyme unit per cubic meter", "kilo enzyme units per cubic meter"; @hecto_enzyme_unit_per_cubic_meter: prefix!(hecto) * prefix!(micro) / 6.0_E1; "hU/m³", "hecto enzyme unit per cubic meter", "hecto enzyme units per cubic meter"; @deca_enzyme_unit_per_cubic_meter: prefix!(deca) * prefix!(micro) / 6.0_E1; "daU/m³", "deca enzyme unit per cubic meter", "deca enzyme units per cubic meter"; @enzyme_unit_per_cubic_meter: prefix!(none) * prefix!(micro) / 6.0_E1; "U/m³", "enzyme unit per cubic meter", "enzyme units per cubic meter"; @deci_enzyme_unit_per_cubic_meter: prefix!(deci) * prefix!(micro) / 6.0_E1; "dU/m³", "deci enzyme unit per cubic meter", "deci enzyme units per cubic meter"; @centi_enzyme_unit_per_cubic_meter: prefix!(centi) * prefix!(micro) / 6.0_E1; "cU/m³", "centi enzyme unit per cubic meter", "centi enzyme units per cubic meter"; @milli_enzyme_unit_per_cubic_meter: prefix!(milli) * prefix!(micro) / 6.0_E1; "mU/m³", "milli enzyme unit per cubic meter", "milli enzyme units per cubic meter"; @micro_enzyme_unit_per_cubic_meter: prefix!(micro) * prefix!(micro) / 6.0_E1; "µU/m³", "micro enzyme unit per cubic meter", "micro enzyme units per cubic meter"; @nano_enzyme_unit_per_cubic_meter: prefix!(nano) * prefix!(micro) / 6.0_E1; "nU/m³", "nano enzyme unit per cubic meter", "nano enzyme units per cubic meter"; @pico_enzyme_unit_per_cubic_meter: prefix!(pico) * prefix!(micro) / 6.0_E1; "pU/m³", "pico enzyme unit per cubic meter", "pico enzyme units per cubic meter"; @femto_enzyme_unit_per_cubic_meter: prefix!(femto) * prefix!(micro) / 6.0_E1; "fU/m³", "femto enzyme unit per cubic meter", "femto enzyme units per cubic meter"; @atto_enzyme_unit_per_cubic_meter: prefix!(atto) * prefix!(micro) / 6.0_E1; "aU/m³", "atto enzyme unit per cubic meter", "atto enzyme units per cubic meter"; @zepto_enzyme_unit_per_cubic_meter: prefix!(zepto) * prefix!(micro) / 6.0_E1; "zU/m³", "zepto enzyme unit per cubic meter", "zepto enzyme units per cubic meter"; @yocto_enzyme_unit_per_cubic_meter: prefix!(yocto) * prefix!(micro) / 6.0_E1; "yU/m³", "yocto enzyme unit per cubic meter", "yocto enzyme units per cubic meter"; @kilo_enzyme_unit_per_cubic_decimeter: prefix!(kilo) * prefix!(micro) / 6.0_E1 / prefix!(milli); "kU/dm³", "kilo enzyme unit per cubic decimeter", "kilo enzyme units per cubic decimeter"; @kilo_enzyme_unit_per_liter: prefix!(kilo) * prefix!(micro) / 6.0_E1 / prefix!(milli); "kU/L", "kilo enzyme unit per liter", "kilo enzyme units per liter"; @enzyme_unit_per_cubic_decimeter: prefix!(none) * prefix!(micro) / 6.0_E1 / prefix!(milli); "U/dm³", "enzyme unit per cubic decimeter", "enzyme units per cubic decimeter"; @enzyme_unit_per_liter: prefix!(none) * prefix!(micro) / 6.0_E1 / prefix!(milli); "U/L", "enzyme unit per liter", "enzyme units per liter"; @milli_enzyme_unit_per_cubic_decimeter: prefix!(milli) * prefix!(micro) / 6.0_E1 / prefix!(milli); "mU/dm³", "milli enzyme unit per cubic decimeter", "milli enzyme units per cubic decimeter"; @milli_enzyme_unit_per_liter: prefix!(milli) * prefix!(micro) / 6.0_E1 / prefix!(milli); "mU/L", "milli enzyme unit per liter", "milli enzyme units per liter"; @micro_enzyme_unit_per_cubic_decimeter: prefix!(micro) * prefix!(micro) / 6.0_E1 / prefix!(milli); "μU/dm³", "micro enzyme unit per cubic decimeter", "micro enzyme units per cubic decimeter"; @micro_enzyme_unit_per_liter: prefix!(micro) * prefix!(micro) / 6.0_E1 / prefix!(milli); "μU/L", "micro enzyme unit per liter", "micro enzyme units per liter"; @nano_enzyme_unit_per_cubic_decimeter: prefix!(nano) * prefix!(micro) / 6.0_E1 / prefix!(milli); "nU/dm³", "nano enzyme unit per cubic decimeter", "nano enzyme units per cubic decimeter"; @nano_enzyme_unit_per_liter: prefix!(nano) * prefix!(micro) / 6.0_E1 / prefix!(milli); "nU/L", "nano enzyme unit per liter", "nano enzyme units per liter"; @pico_enzyme_unit_per_cubic_decimeter: prefix!(pico) * prefix!(micro) / 6.0_E1 / prefix!(milli); "pU/dm³", "pico enzyme unit per cubic decimeter", "pico enzyme units per cubic decimeter"; @pico_enzyme_unit_per_liter: prefix!(pico) * prefix!(micro) / 6.0_E1 / prefix!(milli); "pU/L", "pico enzyme unit per liter", "pico enzyme units per liter"; @femto_enzyme_unit_per_cubic_decimeter: prefix!(femto) * prefix!(micro) / 6.0_E1 / prefix!(milli); "fU/dm³", "femto enzyme unit per cubic decimeter", "femto enzyme units per cubic decimeter"; @femto_enzyme_unit_per_liter: prefix!(femto) * prefix!(micro) / 6.0_E1 / prefix!(milli); "fU/L", "femto enzyme unit per liter", "femto enzyme units per liter"; @kilo_enzyme_unit_per_deciliter: prefix!(kilo) * prefix!(micro) / 6.0_E1 / prefix!(deci) / prefix!(milli); "kU/dL", "kilo enzyme unit per deciliter", "kilo enzyme units per deciliter"; @enzyme_unit_per_deciliter: prefix!(none) * prefix!(micro) / 6.0_E1 / prefix!(deci) / prefix!(milli); "U/dL", "enzyme unit per deciliter", "enzyme units per deciliter"; @milli_enzyme_unit_per_deciliter: prefix!(milli) * prefix!(micro) / 6.0_E1 / prefix!(deci) / prefix!(milli); "mU/dL", "milli enzyme unit per deciliter", "milli enzyme units per deciliter"; @micro_enzyme_unit_per_deciliter: prefix!(micro) * prefix!(micro) / 6.0_E1 / prefix!(deci) / prefix!(milli); "μU/dL", "micro enzyme unit per deciliter", "micro enzyme units per deciliter"; @nano_enzyme_unit_per_deciliter: prefix!(nano) * prefix!(micro) / 6.0_E1 / prefix!(deci) / prefix!(milli); "nU/dL", "nano enzyme unit per deciliter", "nano enzyme units per deciliter"; @pico_enzyme_unit_per_deciliter: prefix!(pico) * prefix!(micro) / 6.0_E1 / prefix!(deci) / prefix!(milli); "pU/dL", "pico enzyme unit per deciliter", "pico enzyme units per deciliter"; @femto_enzyme_unit_per_deciliter: prefix!(femto) * prefix!(micro) / 6.0_E1 / prefix!(deci) / prefix!(milli); "fU/dL", "femto enzyme unit per deciliter", "femto enzyme units per deciliter"; @kilo_enzyme_unit_per_milliliter: prefix!(kilo) * prefix!(micro) / 6.0_E1 / prefix!(milli) / prefix!(milli); "kU/mL", "kilo enzyme unit per milliliter", "kilo enzyme units per milliliter"; @enzyme_unit_per_milliliter: prefix!(none) * prefix!(micro) / 6.0_E1 / prefix!(milli) / prefix!(milli); "U/mL", "enzyme unit per milliliter", "enzyme units per milliliter"; @milli_enzyme_unit_per_milliliter: prefix!(milli) * prefix!(micro) / 6.0_E1 / prefix!(milli) / prefix!(milli); "mU/mL", "milli enzyme unit per milliliter", "milli enzyme units per milliliter"; @micro_enzyme_unit_per_milliliter: prefix!(micro) * prefix!(micro) / 6.0_E1 / prefix!(milli) / prefix!(milli); "μU/mL", "micro enzyme unit per milliliter", "micro enzyme units per milliliter"; @nano_enzyme_unit_per_milliliter: prefix!(nano) * prefix!(micro) / 6.0_E1 / prefix!(milli) / prefix!(milli); "nU/mL", "nano enzyme unit per milliliter", "nano enzyme units per milliliter"; @pico_enzyme_unit_per_milliliter: prefix!(pico) * prefix!(micro) / 6.0_E1 / prefix!(milli) / prefix!(milli); "pU/mL", "pico enzyme unit per milliliter", "pico enzyme units per milliliter"; @femto_enzyme_unit_per_milliliter: prefix!(femto) * prefix!(micro) / 6.0_E1 / prefix!(milli) / prefix!(milli); "fU/mL", "femto enzyme unit per milliliter", "femto enzyme units per milliliter"; @particle_per_second_cubic_meter: 1.0_E0 / 6.022_140_76_E23; "particle · s⁻¹ · m⁻³", "particle per second cubic meter", "particles per second cubic meter"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::catalytic_activity as ca; use crate::si::catalytic_activity_concentration as c; use crate::si::quantities::*; use crate::si::volume as v; use crate::tests::Test; #[test] fn check_dimension() { let _: CatalyticActivityConcentration = (CatalyticActivity::new::(V::one()) / Volume::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, U: v::Conversion, C: c::Conversion>() { Test::assert_approx_eq(&CatalyticActivityConcentration::new::(V::one()), &(CatalyticActivity::new::(V::one()) / Volume::new::(V::one())).into()); } } } } uom-0.35.0/src/si/curvature.rs000064400000000000000000000040571046102023000143070ustar 00000000000000//! [Curvature](https://en.wikipedia.org/wiki/Curvature) (base unit radian per meter, m⁻¹). quantity! { /// Curvature (base unit radian per meter, m⁻¹). quantity: Curvature; "curvature"; /// Dimension of curvature, L⁻¹ (base unit radian per meter, m⁻¹). dimension: ISQ< N1, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::AngleKind); units { @radian_per_meter: 1.0_E0; "rad/m", "radian per meter", "radians per meter"; @degree_per_meter: 1.745_329_251_994_329_5_E-2; "°/m", "degree per meter", "degrees per meter"; @radian_per_millimeter: 1000.0; "rad/mm", "radian per millimeter", "radians per millimeter"; @degree_per_millimeter: 1.745_329_251_994_329_5_E1; "°/mm", "degree per millimeter", "degrees per millimeter"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::angle as a; use crate::si::curvature as c; use crate::si::length as l; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: Curvature = (Angle::new::(V::one()) / Length::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); fn test, L: l::Conversion, C: c::Conversion>() { Test::assert_approx_eq(&Curvature::new::(V::one()), &(Angle::new::(V::one()) / Length::new::(V::one())).into()); } } } } uom-0.35.0/src/si/diffusion_coefficient.rs000064400000000000000000000056461046102023000166200ustar 00000000000000//! Diffusion coefficient (base unit square meter per second, m² · s⁻¹). quantity! { /// Diffusion coefficient (base unit square meter per second, m² · s⁻¹). quantity: DiffusionCoefficient; "diffusion coefficient"; /// Dimension of diffusion coefficient, L²T⁻¹ (base unit square meter per second, m² · s⁻¹). dimension: ISQ< P2, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @square_meter_per_second: prefix!(none); "m²/s", "square meter per second", "square meters per second"; @square_centimeter_per_second: prefix!(centi) * prefix!(centi); "cm²/s", "square centimeter per second", "square centimeters per second"; @square_millimeter_per_second: prefix!(milli) * prefix!(milli); "mm²/s", "square millimeter per second", "square millimeters per second"; @square_micrometer_per_second: prefix!(micro) * prefix!(micro); "µm²/s", "square micrometer per second", "square micrometers per second"; @square_nanometer_per_second: prefix!(nano) * prefix!(nano); "nm²/s", "square nanometer per second", "square nanometers per second"; @stokes: prefix!(centi) * prefix!(centi); "St", "Stokes", "Stokes"; @centistokes: prefix!(centi) * prefix!(centi) * prefix!(centi); "cSt", "centistokes", "centistokes"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::quantities::*; use crate::si::time as t; use crate::si::area as area; use crate::si::diffusion_coefficient as dc; use crate::tests::Test; #[test] fn check_dimension() { let _: DiffusionCoefficient = Area::new::(V::one()) / Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, DC: dc::Conversion>() { Test::assert_approx_eq(&DiffusionCoefficient::new::(V::one()), &(Area::new::(V::one()) / Time::new::(V::one()))); } } } } uom-0.35.0/src/si/dynamic_viscosity.rs000064400000000000000000000105311046102023000160210ustar 00000000000000//! Dynamic viscosity (base unit pascal second, kg · m⁻¹ · s⁻¹). quantity! { /// Dynamic viscosity (base unit pascal second, kg · m⁻¹ · s⁻¹). quantity: DynamicViscosity; "dynamic viscosity"; /// Dimension of dynamic viscosity, L⁻¹MT⁻¹ (base unit pascal second, kg · m⁻¹ · s⁻¹). dimension: ISQ< N1, // length P1, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @pascal_second: prefix!(none); "Pa · s", "pascal second", "pascal seconds"; @millipascal_second: prefix!(milli); "mPa · s", "millipascal second", "millipascal seconds"; @micropascal_second: prefix!(micro); "µPa · s", "micropascal second", "micropascal seconds"; // poise = 0.1 Pa · s @poise: 1.0_E-1; "P", "poise", "poises"; // centipoise = 1 mPa · s @centipoise: prefix!(centi) * 1.0_E-1; "cP", "centipoise", "centipoises"; @pound_force_second_per_square_foot: 4.448_222_E0 / 3.048_E-1 / 3.048_E-1; "lbf · s/ft²", "pound-force second per square foot", "pound-force seconds per square foot"; @pound_force_second_per_square_inch: 4.448_222_E0 / 2.54_E-2 / 2.54_E-2; "lbf · s/in²", "pound-force second per square inch", "pound-force seconds per square inch"; // Reyn = 1 lbf · s/in² @reyn: 4.448_222_E0 / 2.54_E-2 / 2.54_E-2; "reyn", "reyn", "reyns"; @pound_per_foot_second: 4.535_924_E-1 / 3.048_E-1; "lb/(ft · s)", "pound per foot second", "pounds per foot second"; @pound_per_foot_hour: 4.535_924_E-1 / 3.048_E-1 / 3.6_E3; "lb/(ft · h)", "pound per foot hour", "pounds per foot hour"; @slug_per_foot_second: 1.459_390_E1 / 3.048_E-1; "slug/(ft · s)", "slug per foot second", "slugs per foot second"; @gram_per_centimeter_second: prefix!(milli) / prefix!(centi); "g/(cm · s)", "gram per centimeter second", "grams per centimeter second"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::quantities::*; use crate::si::dynamic_viscosity as dv; use crate::si::time as t; use crate::si::mass as m; use crate::si::length as l; use crate::si::pressure as p; use crate::tests::Test; #[test] fn check_dimension() { let _: DynamicViscosity = Pressure::new::(V::one()) * Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, DV: dv::Conversion>() { Test::assert_approx_eq(&DynamicViscosity::new::(V::one()), &(Pressure::new::

(V::one()) * Time::new::(V::one()))); } } #[test] fn check_units_mlt() { test::(); test::(); test::(); test::(); fn test, L: l::Conversion, T: t::Conversion, DV: dv::Conversion>() { Test::assert_approx_eq(&DynamicViscosity::new::(V::one()), &(Mass::new::(V::one()) / Length::new::(V::one()) / Time::new::(V::one()))); } } } } uom-0.35.0/src/si/electric_charge.rs000064400000000000000000000137461046102023000153770ustar 00000000000000//! Electric charge (base unit coulomb, A · s). quantity! { /// Electric charge (base unit coulomb, A · s). quantity: ElectricCharge; "electric charge"; /// Dimension of electric charge, TI (base unit coulomb, A · s). dimension: ISQ< Z0, // length Z0, // mass P1, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottacoulomb: prefix!(yotta); "YC", "yottacoulomb", "yottacoulombs"; @zettacoulomb: prefix!(zetta); "ZC", "zettacoulomb", "zettacoulombs"; @exacoulomb: prefix!(exa); "EC", "exacoulomb", "exacoulombs"; @petacoulomb: prefix!(peta); "PC", "petacoulomb", "petacoulombs"; @teracoulomb: prefix!(tera); "TC", "teracoulomb", "teracoulombs"; @gigacoulomb: prefix!(giga); "GC", "gigacoulomb", "gigacoulombs"; @megacoulomb: prefix!(mega); "MC", "megacoulomb", "megacoulombs"; @kilocoulomb: prefix!(kilo); "kC", "kilocoulomb", "kilocoulombs"; @hectocoulomb: prefix!(hecto); "hC", "hectocoulomb", "hectocoulombs"; @decacoulomb: prefix!(deca); "daC", "decacoulomb", "decacoulombs"; /// Derived unit of electric charge. @coulomb: prefix!(none); "C", "coulomb", "coulombs"; @decicoulomb: prefix!(deci); "dC", "decicoulomb", "decicoulombs"; @centicoulomb: prefix!(centi); "cC", "centicoulomb", "centicoulombs"; @millicoulomb: prefix!(milli); "mC", "millcoulomb", "millcoulombs"; @microcoulomb: prefix!(micro); "µC", "microcoulomb", "microcoulombs"; @nanocoulomb: prefix!(nano); "nC", "nanocoulomb", "nanocoulombs"; @picocoulomb: prefix!(pico); "pC", "picocoulomb", "picocoulombs"; @femtocoulomb: prefix!(femto); "fC", "femtocoulomb", "femtocoulombs"; @attocoulomb: prefix!(atto); "aC", "attocoulomb", "attocoulombs"; @zeptocoulomb: prefix!(zepto); "zC", "zeptocoulomb", "zeptocoulombs"; @yoctocoulomb: prefix!(yocto); "yC", "yoctocoulomb", "yoctocoulombs"; @petaampere_hour: 3.6_E18; "PA · h", "petaampere hour", "petaampere hours"; @teraampere_hour: 3.6_E15; "TA · h", "teraampere hour", "teraampere hours"; @gigaampere_hour: 3.6_E12; "GA · h", "gigaampere hour", "gigaampere hours"; @megaampere_hour: 3.6_E9; "MA · h", "megaampere hour", "megaampere hours"; @kiloampere_hour: 3.6_E6; "kA · h", "kiloampere hour", "kiloampere hours"; @hectoampere_hour: 3.6_E5; "hA · h", "hectoampere hour", "hectoampere hours"; @decaampere_hour: 3.6_E4; "daA · h", "decaampere hour", "decaampere hours"; @ampere_hour: 3.6_E3; "A · h", "ampere hour", "ampere hours"; @milliampere_hour: 3.6_E0; "mA · h", "milliampere hour", "milliampere hours"; @microampere_hour: 3.6_E-3; "µA · h", "microampere hour", "microampere hours"; /// Electric charge carried by a single proton. @elementary_charge: 1.602_176_634_E-19; "e", "elementary charge", "elementary charges"; @atomic_unit_of_charge: 1.602_176_634_E-19; "a.u. of charge", "atomic unit of charge", "atomic units of charge"; @abcoulomb: 1.0_E1; "abC", "abcoulomb", "abcoulombs"; @faraday: 9.648_531_E4; "F", "faraday", "faradays"; @franklin: 3.335_641_E-10; "Fr", "franklin", "franklins"; @statcoulomb: 3.335_641_E-10; "statC", "statcoulomb", "statcoulombs"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::electric_charge as q; use crate::si::electric_current as i; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricCharge = ElectricCurrent::new::(V::one()) * Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, Q: q::Conversion>() { Test::assert_approx_eq(&ElectricCharge::new::(V::one()), &(ElectricCurrent::new::(V::one()) * Time::new::(V::one()))); } } } } uom-0.35.0/src/si/electric_charge_areal_density.rs000064400000000000000000000040411046102023000202660ustar 00000000000000//! Electric charge areal density (base unit coulomb per square meter, m⁻² · A · s). quantity! { ///Electric charge areal density (base unit coulomb per square meter, m⁻² · A · s). quantity: ElectricChargeArealDensity; "electric charge areal density"; /// Dimension of electric charge areal density, L⁻²TI (base unit coulomb per square meter, /// m⁻² · A · s). dimension: ISQ< N2, // length Z0, // mass P1, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @coulomb_per_square_meter: prefix!(none); "C/m²", "coulomb per square meter", "coulombs per square meter"; @coulomb_per_square_centimeter: prefix!(none) / prefix!(centi) / prefix!(centi); "C/cm²", "coulomb per square centimeter", "coulombs per square centimeter"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::electric_charge as q; use crate::si::electric_charge_areal_density as ecad; use crate::si::quantities::*; use crate::si::area as a; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricChargeArealDensity = (ElectricCharge::new::(V::one()) / Area::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); fn test, A: a::Conversion, ECAD: ecad::Conversion>() { Test::assert_approx_eq(&ElectricChargeArealDensity::new::(V::one()), &(ElectricCharge::new::(V::one()) / Area::new::(V::one())).into()); } } } } uom-0.35.0/src/si/electric_charge_linear_density.rs000064400000000000000000000036541046102023000204650ustar 00000000000000//! Electric charge linear density (base unit coulomb per meter, m⁻¹ · A · s). quantity! { ///Electric charge linear density (base unit coulomb per meter, m⁻¹ · A · s). quantity: ElectricChargeLinearDensity; "electric charge linear density"; /// Dimension of electric charge linear density, L⁻¹TI (base unit coulomb per meter, /// m⁻¹ · A · s). dimension: ISQ< N1, // length Z0, // mass P1, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @coulomb_per_meter: prefix!(none); "C/m", "coulomb per meter", "coulombs per meter"; @coulomb_per_centimeter: prefix!(none) / prefix!(centi); "C/cm", "coulomb per centimeter", "coulombs per centimeter"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::electric_charge as q; use crate::si::electric_charge_linear_density as ecld; use crate::si::quantities::*; use crate::si::length as l; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricChargeLinearDensity = (ElectricCharge::new::(V::one()) / Length::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); fn test, L: l::Conversion, ECLD: ecld::Conversion>() { Test::assert_approx_eq(&ElectricChargeLinearDensity::new::(V::one()), &(ElectricCharge::new::(V::one()) / Length::new::(V::one())).into()); } } } } uom-0.35.0/src/si/electric_charge_volumetric_density.rs000064400000000000000000000041421046102023000213750ustar 00000000000000//! Electric charge volumetric density (base unit coulomb per cubic meter, m⁻³ · A · s). quantity! { ///Electric charge volumetric density (base unit coulomb per cubic meter, m⁻³ · A · s). quantity: ElectricChargeVolumetricDensity; "electric charge volumetric density"; /// Dimension of electric charge volumetric density, TIL⁻³ (base unit coulomb per cubic meter, /// m⁻³ · A · s). dimension: ISQ< N3, // length Z0, // mass P1, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @coulomb_per_cubic_meter: prefix!(none); "C/m³", "coulomb per cubic meter", "coulombs per cubic meter"; @coulomb_per_cubic_centimeter: prefix!(none) / prefix!(centi) / prefix!(centi) / prefix!(centi); "C/cm³", "coulomb per cubic centimeter", "coulombs per cubic centimeter"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::electric_charge as q; use crate::si::electric_charge_volumetric_density as ecvd; use crate::si::quantities::*; use crate::si::volume as v; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricChargeVolumetricDensity = (ElectricCharge::new::(V::one()) / Volume::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); fn test, VOL: v::Conversion, ECVD: ecvd::Conversion>() { Test::assert_approx_eq(&ElectricChargeVolumetricDensity::new::(V::one()), &(ElectricCharge::new::(V::one()) / Volume::new::(V::one())).into()); } } } } uom-0.35.0/src/si/electric_current.rs000064400000000000000000000055541046102023000156260ustar 00000000000000//! Electric current (base unit ampere, A). quantity! { /// Electric current (base unit ampere, A). quantity: ElectricCurrent; "electric current"; /// Dimension of electric current, I (base unit ampere, A). dimension: ISQ< Z0, // length Z0, // mass Z0, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottaampere: prefix!(yotta); "YA", "yottaampere", "yottaamperes"; @zettaampere: prefix!(zetta); "ZA", "zettaampere", "zettaamperes"; @exaampere: prefix!(exa); "EA", "exaampere", "exaamperes"; @petaampere: prefix!(peta); "PA", "petaampere", "petaamperes"; @teraampere: prefix!(tera); "TA", "teraampere", "teraamperes"; @gigaampere: prefix!(giga); "GA", "gigaampere", "gigaamperes"; @megaampere: prefix!(mega); "MA", "megaampere", "megaamperes"; @kiloampere: prefix!(kilo); "kA", "kiloampere", "kiloamperes"; @hectoampere: prefix!(hecto); "hA", "hectoampere", "hectoamperes"; @decaampere: prefix!(deca); "daA", "decaampere", "decaamperes"; /// The ampere is the SI unit of electric current. It is defined by taking the fixed /// numerical value of the elementary charge *e* to be 1.602 176 634 × 10⁻¹⁹ when expressed /// in the unit C, which is equal to A s, where the second is defined in terms of /// ∆*ν*Cs. @ampere: prefix!(none); "A", "ampere", "amperes"; @deciampere: prefix!(deci); "dA", "deciampere", "deciamperes"; @centiampere: prefix!(centi); "cA", "centiampere", "centiamperes"; @milliampere: prefix!(milli); "mA", "millampere", "millamperes"; @microampere: prefix!(micro); "µA", "microampere", "microamperes"; @nanoampere: prefix!(nano); "nA", "nanoampere", "nanoamperes"; @picoampere: prefix!(pico); "pA", "picoampere", "picoamperes"; @femtoampere: prefix!(femto); "fA", "femtoampere", "femtoamperes"; @attoampere: prefix!(atto); "aA", "attoampere", "attoamperes"; @zeptoampere: prefix!(zepto); "zA", "zeptoampere", "zeptoamperes"; @yoctoampere: prefix!(yocto); "yA", "yoctoampere", "yoctoamperes"; /// Atomic unit of charge (electric charge carried by a single proton) per second. @elementary_charge_per_second: 1.602_176_634_E-19; "e/s", "elementary charge per second", "elementary charges per second"; @atomic_unit_of_charge_per_second: 1.602_176_634_E-19; "a.u. of charge/s", "atomic unit of charge per second", "atomic units of charge per second"; @abampere: 1.0_E1; "abA", "abampere", "abamperes"; @gilbert: 7.957_747_E-1; "Gi", "gilbert", "gilberts"; @statampere: 3.335_641_E-10; "statA", "statampere", "statamperes"; } } uom-0.35.0/src/si/electric_current_density.rs000064400000000000000000000043351046102023000173610ustar 00000000000000//! Electric current density (base unit ampere per square meter, m⁻² · A). quantity! { /// Electric current density (base unit ampere per square meter, m⁻² · A). quantity: ElectricCurrentDensity; "electric current density"; /// Dimension of electric current density, L⁻²I (base unit ampere per square meter, A · m⁻²). dimension: ISQ< N2, // length Z0, // mass Z0, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @ampere_per_square_meter: prefix!(none); "A/m²", "ampere per square meter", "amperes per square meter"; @ampere_per_square_centimeter: prefix!(none) / prefix!(centi) / prefix!(centi); "A/cm²", "ampere per square centimeter", "amperes per square centimeter"; @ampere_per_square_millimeter: prefix!(none) / prefix!(milli) / prefix!(milli); "A/mm²", "ampere per square millimeter", "amperes per square millimeter"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::area as a; use crate::si::electric_current as i; use crate::si::electric_current_density as ecd; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricCurrentDensity = (ElectricCurrent::new::(V::one()) / Area::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); fn test, I: i::Conversion, A: a::Conversion>() { Test::assert_approx_eq(&ElectricCurrentDensity::new::(V::one()), &(ElectricCurrent::new::(V::one()) / Area::new::(V::one())).into()); } } } } uom-0.35.0/src/si/electric_dipole_moment.rs000064400000000000000000000051641046102023000167740ustar 00000000000000//! Electric dipole moment (base unit coulomb meter, m · s · A). quantity! { /// Electric dipole moment (base unit coulomb meter, m · s · A). quantity: ElectricDipoleMoment; "electric dipole moment"; /// Dimension of electric dipole moment, LTI (base unit coulomb meter, m · s · A). dimension: ISQ< P1, // length Z0, // mass P1, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @coulomb_meter: prefix!(none); "C · m", "coulomb meter", "coulomb meters"; @atomic_unit_of_charge_centimeter: 1.602_176_634_E-19 * prefix!(centi); "a.u. of charge · cm", "atomic unit of charge centimeter", "atomic unit of charge centimeters"; @elementary_charge_centimeter: 1.602_176_634_E-19 * prefix!(centi); "e · cm", "elementary charge centimeter", "elementary charge centimeters"; @debye: 1.0 / 299_792_458.0 * 1.0_E-21; "D", "debye", "debyes"; /// Hartree unit of electric dipole moment e·a₀, where e is elementary charge and a₀ is Bohr /// radius. @atomic_unit_of_electric_dipole_moment: 8.478_353_625_540_766_E-30; "e · a₀", "atomic unit of electric dipole moment", "atomic units of electric dipole moment"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::electric_dipole_moment as edm; use crate::si::electric_charge as ec; use crate::si::length as l; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricDipoleMoment = ElectricCharge::new::(V::one()) * Length::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); fn test, L: l::Conversion, EDM: edm::Conversion>() { Test::assert_approx_eq(&ElectricDipoleMoment::new::(V::one()), &(ElectricCharge::new::(V::one()) * Length::new::(V::one()))); } } } } uom-0.35.0/src/si/electric_displacement_field.rs000064400000000000000000000036551046102023000177570ustar 00000000000000//! Electric displacement field (base unit coulomb per square meter, m⁻² · A · s). quantity! { ///Electric displacement field (base unit coulomb per square meter, m⁻² · A · s). quantity: ElectricDisplacementField; "electric displacement field"; /// Dimension of electric displacement field, L⁻²TI (base unit coulomb per square meter, /// m⁻² · A · s). dimension: ISQ< N2, // length Z0, // mass P1, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @coulomb_per_square_meter: prefix!(none); "C/m²", "coulomb per square meter", "coulombs per square meter"; @coulomb_per_square_centimeter: prefix!(none) / prefix!(centi) / prefix!(centi); "C/cm²", "coulomb per square centimeter", "coulombs per square centimeter"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::electric_charge as q; use crate::si::electric_displacement_field as d; use crate::si::quantities::*; use crate::si::area as a; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricDisplacementField = ElectricCharge::new::(V::one()) / Area::new::(V::one()); } #[test] fn check_units() { test::(); test::(); fn test, A: a::Conversion, D: d::Conversion>() { Test::assert_approx_eq(&ElectricDisplacementField::new::(V::one()), &(ElectricCharge::new::(V::one()) / Area::new::(V::one()))); } } } } uom-0.35.0/src/si/electric_field.rs000064400000000000000000000076661046102023000152350ustar 00000000000000//! Electric field (base unit volt per meter, m ⋅ kg ⋅ s⁻³ ⋅ A⁻¹). quantity! { /// Electric field (base unit volt per meter, m ⋅ kg ⋅ s⁻³ ⋅ A⁻¹). quantity: ElectricField; "electric field"; /// Dimension of electric field, LMT⁻³I⁻¹ (base unit volt per meter, m ⋅ kg ⋅ s⁻³ ⋅ A⁻¹). dimension: ISQ< P1, // length P1, // mass N3, // time N1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @volt_per_meter: prefix!(none); "V/m", "volt per meter", "volts per meter"; @volt_per_centimeter: prefix!(none) / prefix!(centi); "V/cm", "volt per centimeter", "volts per centimeter"; @volt_per_millimeter: prefix!(none) / prefix!(milli); "V/mm", "volt per millimeter", "volts per millimeter"; @volt_per_micrometer: prefix!(none) / prefix!(micro); "V/μm", "volt per micrometer", "volts per micrometer"; @kilovolt_per_millimeter: prefix!(kilo) / prefix!(milli); "kV/mm", "kilovolt per millimeter", "kilovolts per millimeter"; @megavolt_per_meter: prefix!(mega); "MV/m", "megavolt per meter", "megavolts per meter"; @megavolt_per_centimeter: prefix!(mega) / prefix!(centi); "MV/cm", "megavolt per centimeter", "megavolts per centimeter"; @volt_per_mil: prefix!(none) / 2.54_E-5; "V/mil", "volt per mil", "volts per mil"; /// Hartree atomic unit of electric field Eₕ / (e ⋅ a₀), where Eₕ is Hartree energy, e is /// elementary charge, and a₀ is Bohr radius. @atomic_unit_of_electric_field: 5.142_206_747_632_595_E11; "a.u. of electric field", "atomic unit of electric field", "atomic units of electric field"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::electric_field as ef; use crate::si::quantities::*; use crate::si::electric_potential as ep; use crate::si::energy as en; use crate::si::electric_charge as ec; use crate::si::length as l; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricField = ElectricPotential::new::(V::one()) / Length::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, L: l::Conversion, EF: ef::Conversion>() { Test::assert_approx_eq(&ElectricField::new::(V::one()), &(ElectricPotential::new::(V::one()) / Length::new::(V::one()))); } } #[test] fn check_units_eql() { test::(); test::(); fn test, Q: ec::Conversion, L: l::Conversion, EF: ef::Conversion>() { Test::assert_approx_eq(&ElectricField::new::(V::one()), &(Energy::new::(V::one()) / ElectricCharge::new::(V::one()) / Length::new::(V::one()))); } } } } uom-0.35.0/src/si/electric_flux.rs000064400000000000000000000033231046102023000151120ustar 00000000000000//! Electric Flux (base unit volt meter, m³ ⋅ kg ⋅ s⁻³ ⋅ A⁻¹). quantity! { /// Electric Flux (base unit volt meter, m³ ⋅ kg ⋅ s⁻³ ⋅ A⁻¹). quantity: ElectricFlux; "electric flux"; /// Dimension of electric flux, L³MT⁻³I⁻¹ (base unit volt meter, m³ ⋅ kg ⋅ s⁻³ ⋅ A⁻¹). dimension: ISQ< P3, // length P1, // mass N3, // time N1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @volt_meter: prefix!(none); "V ⋅ m", "volt meter", "volt meters"; @volt_centimeter: prefix!(none) * prefix!(centi); "V ⋅ cm", "volt centimeter", "volt centimeters"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::electric_flux as ef; use crate::si::quantities::*; use crate::si::electric_potential as ep; use crate::si::length as l; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricFlux = ElectricPotential::new::(V::one()) * Length::new::(V::one()); } #[test] fn check_units() { test::(); test::(); fn test, L: l::Conversion, EP: ep::Conversion>() { Test::assert_approx_eq(&ElectricFlux::new::(V::one()), &(ElectricPotential::new::(V::one()) * Length::new::(V::one()))); } } } } uom-0.35.0/src/si/electric_permittivity.rs000064400000000000000000000033721046102023000167110ustar 00000000000000//! Electric permittivity (base unit farad per meter, m⁻³ · kg⁻¹ · s⁴ · A²). quantity! { /// Electric permittivity (base unit farad per meter, m⁻³ · kg⁻¹ · s⁴ · A²). quantity: ElectricPermittivity; "electric permittivity"; /// Dimension of electric permittivity, L⁻³M⁻¹T⁴I² (base unit farad per meter, /// m⁻³ · kg⁻¹ · s⁴ · A²). dimension: ISQ< N3, // length N1, // mass P4, // time P2, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @farad_per_meter: prefix!(none); "F/m", "farad per meter", "farads per meter"; @vacuum_electric_permittivity: 8.854_187_8128_E-12; "ε₀", "vacuum electric permittivity", "vacuum electric permittivity"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::capacitance as c; use crate::si::electric_permittivity as ep; use crate::si::length as l; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricPermittivity = Capacitance::new::(V::one()) / Length::new::(V::one()); } #[test] fn check_units() { test::(); fn test, C: c::Conversion, L: l::Conversion>() { Test::assert_approx_eq(&ElectricPermittivity::new::(V::one()), &(Capacitance::new::(V::one()) / Length::new::(V::one()))); } } } } uom-0.35.0/src/si/electric_potential.rs000064400000000000000000000106411046102023000161340ustar 00000000000000//! Electric potential (base unit volt, m² · kg · s⁻³ · A⁻¹). quantity! { /// Electric potential (base unit volt, m² · kg · s⁻³ · A⁻¹). quantity: ElectricPotential; "electric potential"; /// Dimension of electric potential, L²MT⁻³I⁻¹ (base unit volt, m² · kg · s⁻³ · A⁻¹). dimension: ISQ< P2, // length P1, // mass N3, // time N1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottavolt: prefix!(yotta); "YV", "yottavolt", "yottavolts"; @zettavolt: prefix!(zetta); "ZV", "zettavolt", "zettavolts"; @exavolt: prefix!(exa); "EV", "exavolt", "exavolts"; @petavolt: prefix!(peta); "PV", "petavolt", "petavolts"; @teravolt: prefix!(tera); "TV", "teravolt", "teravolts"; @gigavolt: prefix!(giga); "GV", "gigavolt", "gigavolts"; @megavolt: prefix!(mega); "MV", "megavolt", "megavolts"; @kilovolt: prefix!(kilo); "kV", "kilovolt", "kilovolts"; @hectovolt: prefix!(hecto); "hV", "hectovolt", "hectovolts"; @decavolt: prefix!(deca); "daV", "decavolt", "decavolts"; /// Derived unit of electric potential. @volt: prefix!(none); "V", "volt", "volts"; @decivolt: prefix!(deci); "dV", "decivolt", "decivolts"; @centivolt: prefix!(centi); "cV", "centivolt", "centivolts"; @millivolt: prefix!(milli); "mV", "millivolt", "millivolts"; @microvolt: prefix!(micro); "µV", "microvolt", "microvolts"; @nanovolt: prefix!(nano); "nV", "nanovolt", "nanovolts"; @picovolt: prefix!(pico); "pV", "picovolt", "picovolts"; @femtovolt: prefix!(femto); "fV", "femtovolt", "femtovolts"; @attovolt: prefix!(atto); "aV", "attovolt", "attovolts"; @zeptovolt: prefix!(zepto); "zV", "zeptovolt", "zeptovolts"; @yoctovolt: prefix!(yocto); "yV", "yoctovolt", "yoctovolts"; @abvolt: 1.0_E-8; "abV", "abvolt", "abvolts"; @statvolt: 2.997_925_E2; "statV", "statvolt", "statvolts"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::area as a; use crate::si::electric_current as i; use crate::si::electric_potential as v; use crate::si::mass as m; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricPotential = Area::new::(V::one()) * Mass::new::(V::one()) / (ElectricCurrent::new::(V::one()) * (Time::new::(V::one()) * Time::new::(V::one()) * Time::new::(V::one()))); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, E: v::Conversion>() { Test::assert_approx_eq(&ElectricPotential::new::(V::one()), &(Area::new::(V::one()) * Mass::new::(V::one()) / (ElectricCurrent::new::(V::one()) * (Time::new::(V::one()) * Time::new::(V::one()) * Time::new::(V::one()))))); } } } } uom-0.35.0/src/si/electric_quadrupole_moment.rs000064400000000000000000000053021046102023000176730ustar 00000000000000//! Electric quadrupole moment (base unit coulomb square meter, m² · s · A). quantity! { /// Electric quadrupole moment (base unit coulomb square meter, m² · s · A). quantity: ElectricQuadrupoleMoment; "electric quadrupole moment"; /// Dimension of electric quadrupole moment, LTI (base unit coulomb square meter, m² · s · A). dimension: ISQ< P2, // length Z0, // mass P1, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @coulomb_square_meter: prefix!(none); "C · m²", "coulomb square meter", "coulomb square meters"; @elementary_charge_barn: 1.602_176_634_E-19 * 1.0_E-28; "e · b", "elementary charge barn", "elementary charge barns"; /// Hartree unit of electric quadrupole moment e · a₀², where e is elementary charge and a₀ /// is Bohr radius. @atomic_unit_of_electric_quadrupole_moment: 4.486_551_524_613_E-40; "e · a₀²", "atomic unit of electric quadrupole moment", "atomic units of electric quadrupole moment"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::electric_quadrupole_moment as edm; use crate::si::electric_charge as ec; use crate::si::area as a; use crate::si::length as l; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricQuadrupoleMoment = ElectricCharge::new::(V::one()) * Area::new::(V::one()); } #[test] fn check_units() { test::(); test::(); fn test, A: a::Conversion, EDM: edm::Conversion>() { Test::assert_approx_eq(&ElectricQuadrupoleMoment::new::(V::one()), &(ElectricCharge::new::(V::one()) * Area::new::(V::one()))); } } #[test] fn check_units_charge_length() { test::(); fn test, L: l::Conversion, EDM: edm::Conversion>() { Test::assert_approx_eq(&ElectricQuadrupoleMoment::new::(V::one()), &(ElectricCharge::new::(V::one()) * Length::new::(V::one()) * Length::new::(V::one()))); } } } } uom-0.35.0/src/si/electrical_conductance.rs000064400000000000000000000106531046102023000167430ustar 00000000000000//! Electrical conductance (base unit siemens, m⁻² · kg⁻¹ · s³ · A²). quantity! { /// Electrical conductance (base unit siemens, m⁻² · kg⁻¹ · s³ · A²). quantity: ElectricalConductance; "electrical conductance"; /// Dimension of electrical conductance, L⁻²M⁻¹T³I² (base unit siemens, m⁻² · kg⁻¹ · s³ · A²). dimension: ISQ< N2, // length N1, // mass P3, // time P2, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottasiemens: prefix!(yotta); "YS", "yottasiemens", "yottasiemens"; @zettasiemens: prefix!(zetta); "ZS", "zettasiemens", "zettasiemens"; @exasiemens: prefix!(exa); "ES", "exasiemens", "exasiemens"; @petasiemens: prefix!(peta); "PS", "petasiemens", "petasiemens"; @terasiemens: prefix!(tera); "TS", "terasiemens", "terasiemens"; @gigasiemens: prefix!(giga); "GS", "gigasiemens", "gigasiemens"; @megasiemens: prefix!(mega); "MS", "megasiemens", "megasiemens"; @kilosiemens: prefix!(kilo); "kS", "kilosiemens", "kilosiemens"; @hectosiemens: prefix!(hecto); "hS", "hectosiemens", "hectosiemens"; @decasiemens: prefix!(deca); "daS", "decasiemens", "decasiemens"; /// Derived unit of electrical conductance. @siemens: prefix!(none); "S", "siemens", "siemens"; @mho: prefix!(none); "℧", "mho", "mhos"; @decisiemens: prefix!(deci); "dS", "decisiemens", "decisiemens"; @centisiemens: prefix!(centi); "cS", "centisiemens", "centisiemens"; @millisiemens: prefix!(milli); "mS", "millisiemens", "millisiemens"; @microsiemens: prefix!(micro); "µS", "microsiemens", "microsiemens"; @nanosiemens: prefix!(nano); "nS", "nanosiemens", "nanosiemens"; @picosiemens: prefix!(pico); "pS", "picosiemens", "picosiemens"; @femtosiemens: prefix!(femto); "fS", "femtosiemens", "femtosiemens"; @attosiemens: prefix!(atto); "aS", "attosiemens", "attosiemens"; @zeptosiemens: prefix!(zepto); "zS", "zeptosiemens", "zeptosiemens"; @yoctosiemens: prefix!(yocto); "yS", "yoctosiemens", "yoctosiemens"; @abmho: 1.0_E9; "abmho", "abmho", "abmhos"; @absiemens: 1.0_E9; "abS", "abmsiemens", "abmsiemens"; @statsiemens: 1.112_650_E-12; "statS", "statsiemens", "statsiemens"; @statmho: 1.112_650_E-12; "statmho", "statmho", "statmhos"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::electrical_conductance as g; use crate::si::electrical_resistance as r; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricalConductance = V::one() / ElectricalResistance::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, G: g::Conversion>() { Test::assert_approx_eq(&ElectricalConductance::new::(V::one()), &(V::one() / ElectricalResistance::new::(V::one()))); } } } } uom-0.35.0/src/si/electrical_conductivity.rs000064400000000000000000000035441046102023000172020ustar 00000000000000//! Electrical conductivity (base unit siemens per meter, m⁻³ · kg⁻¹ · s³ · A²). quantity! { /// Electrical conductivity (base unit siemens per meter, m⁻³ · kg⁻¹ · s³ · A²). quantity: ElectricalConductivity; "electrical conductivity"; /// Dimension of electrical conductivity, L⁻³M⁻¹T³I² (base unit siemens per meter, /// m⁻³ · kg⁻¹ · s³ · A²). dimension: ISQ< N3, // length N1, // mass P3, // time P2, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @siemens_per_meter: prefix!(none); "S/m", "siemens per meter", "siemens per meter"; @siemens_per_centimeter: prefix!(none) / prefix!(centi); "S/cm", "siemens per centimeter", "siemens per centimeter"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::electrical_conductance as g; use crate::si::length as l; use crate::si::electrical_conductivity as ec; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricalConductivity = ElectricalConductance::new::(V::one()) / Length::new::(V::one()); } #[test] fn check_units() { test::(); test::(); fn test, G: g::Conversion, L: l::Conversion>() { Test::assert_approx_eq(&ElectricalConductivity::new::(V::one()), &(ElectricalConductance::new::(V::one()) / Length::new::(V::one()))); } } } } uom-0.35.0/src/si/electrical_mobility.rs000064400000000000000000000043671046102023000163120ustar 00000000000000//! Electrical mobility (base unit square meter per volt second, kg⁻¹ · s² · A). quantity! { /// Electrical mobility (base unit square meter per volt second, kg⁻¹ · s² · A). quantity: ElectricalMobility; "electrical mobility"; /// Dimension of electrical mobility, M⁻¹T²I⁻¹ (base unit square meter per volt second, /// kg⁻¹ · s² · A). dimension: ISQ< Z0, // length N1, // mass P2, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @square_meter_per_volt_second: prefix!(none); "m²/(V · s)", "square meter per volt second", "square meters per volt second"; @square_centimeter_per_volt_second: prefix!(centi) * prefix!(centi); "cm²/(V · s)", "square centimeter per volt second", "square centimeters per volt second"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::electrical_mobility as em; use crate::si::electric_potential as ep; use crate::si::time as t; use crate::si::length as l; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricalMobility = Length::new::(V::one()) * Length::new::(V::one()) / Time::new::(V::one()) / ElectricPotential::new::(V::one()); } #[test] fn check_units() { test::(); test::(); fn test, EP: ep::Conversion, T: t::Conversion, EM: em::Conversion>() { Test::assert_approx_eq(&ElectricalMobility::new::(V::one()), &(Length::new::(V::one()) * Length::new::(V::one()) / ElectricPotential::new::(V::one()) / Time::new::(V::one()))); } } } } uom-0.35.0/src/si/electrical_resistance.rs000064400000000000000000000103761046102023000166170ustar 00000000000000//! Electrical resistance (base unit ohm, m² · kg · s⁻³ · A⁻²). quantity! { /// Electrical resistance (base unit ohm, m² · kg · s⁻³ · A⁻²). quantity: ElectricalResistance; "electrical resistance"; /// Dimension of electrical resistance, L²MT⁻³I⁻² (base unit ohm, m² · kg · s⁻³ · A⁻²). dimension: ISQ< P2, // length P1, // mass N3, // time N2, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottaohm: prefix!(yotta); "YΩ", "yottaohm", "yottaohms"; @zettaohm: prefix!(zetta); "ZΩ", "zettaohm", "zettaohms"; @exaohm: prefix!(exa); "EΩ", "exaohm", "exaohms"; @petaohm: prefix!(peta); "PΩ", "petaohm", "petaohms"; @teraohm: prefix!(tera); "TΩ", "teraohm", "teraohms"; @gigaohm: prefix!(giga); "GΩ", "gigaohm", "gigaohms"; @megaohm: prefix!(mega); "MΩ", "megaohm", "megaohms"; @kiloohm: prefix!(kilo); "kΩ", "kiloohm", "kiloohms"; @hectoohm: prefix!(hecto); "hΩ", "hectoohm", "hectoohms"; @decaohm: prefix!(deca); "daΩ", "decaohm", "decaohms"; /// Derived unit of electrical resistance. @ohm: prefix!(none); "Ω", "ohm", "ohms"; @deciohm: prefix!(deci); "dΩ", "deciohm", "deciohms"; @centiohm: prefix!(centi); "cΩ", "centiohm", "centiohms"; @milliohm: prefix!(milli); "mΩ", "milliohm", "milliohms"; @microohm: prefix!(micro); "µΩ", "microohm", "microohms"; @nanoohm: prefix!(nano); "nΩ", "nanoohm", "nanoohms"; @picoohm: prefix!(pico); "pΩ", "picoohm", "picoohms"; @femtoohm: prefix!(femto); "fΩ", "femtoohm", "femtoohms"; @attoohm: prefix!(atto); "aΩ", "attoohm", "attoohms"; @zeptoohm: prefix!(zepto); "zΩ", "zeptoohm", "zeptoohms"; @yoctoohm: prefix!(yocto); "yΩ", "yoctoohm", "yoctoohms"; @abohm: 1.0_E-9; "abΩ", "abohm", "abohms"; @statohm: 8.987_552_917_115_481_E11; "statΩ", "statohm", "statohms"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::electric_current as i; use crate::si::electric_potential as v; use crate::si::electrical_resistance as r; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricalResistance = ElectricPotential::new::(V::one()) / ElectricCurrent::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, I: i::Conversion, R: r::Conversion>() { Test::assert_approx_eq(&ElectricalResistance::new::(V::one()), &(ElectricPotential::new::(V::one()) / ElectricCurrent::new::(V::one()))); } } } } uom-0.35.0/src/si/electrical_resistivity.rs000064400000000000000000000140041046102023000170450ustar 00000000000000//! Electrical resistivity (base unit ohm meter, m³ · kg · s⁻³ · A⁻²). quantity! { /// Electrical resistivity (base unit ohm meter, m³ · kg · s⁻³ · A⁻²). quantity: ElectricalResistivity; "electrical resistivity"; /// Dimension of electrical resistivity, L³MT⁻³I⁻² (base unit ohm meter, m³ · kg · s⁻³ · A⁻²). dimension: ISQ< P3, // length P1, // mass N3, // time N2, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottaohm_meter: prefix!(yotta); "YΩ · m", "yottaohm meter", "yottaohm meters"; @zettaohm_meter: prefix!(zetta); "ZΩ · m", "zettaohm meter", "zettaohm meters"; @exaohm_meter: prefix!(exa); "EΩ · m", "exaohm meter", "exaohm meters"; @petaohm_meter: prefix!(peta); "PΩ · m", "petaohm meter", "petaohm meters"; @teraohm_meter: prefix!(tera); "TΩ · m", "teraohm meter", "teraohm meters"; @gigaohm_meter: prefix!(giga); "GΩ · m", "gigaohm meter", "gigaohm meters"; @megaohm_meter: prefix!(mega); "MΩ · m", "megaohm meter", "megaohm meters"; @kiloohm_meter: prefix!(kilo); "kΩ · m", "kiloohm meter", "kiloohm meters"; @hectoohm_meter: prefix!(hecto); "hΩ · m", "hectoohm meter", "hectoohm meters"; @decaohm_meter: prefix!(deca); "daΩ · m", "decaohm meter", "decaohm meters"; /// Derived unit of electrical resistance. @ohm_meter: prefix!(none); "Ω · m", "ohm meter", "ohm meters"; @deciohm_meter: prefix!(deci); "dΩ · m", "deciohm meter", "deciohm meters"; @centiohm_meter: prefix!(centi); "cΩ · m", "centiohm meter", "centiohm meters"; @milliohm_meter: prefix!(milli); "mΩ · m", "milliohm meter", "milliohm meters"; @microohm_meter: prefix!(micro); "µΩ · m", "microohm meter", "microohm meters"; @nanoohm_meter: prefix!(nano); "nΩ · m", "nanoohm meter", "nanoohm meters"; @picoohm_meter: prefix!(pico); "pΩ · m", "picoohm meter", "picoohm meters"; @femtoohm_meter: prefix!(femto); "fΩ · m", "femtoohm meter", "femtoohm meters"; @attoohm_meter: prefix!(atto); "aΩ · m", "attoohm meter", "attoohm meters"; @zeptoohm_meter: prefix!(zepto); "zΩ · m", "zeptoohm meter", "zeptoohm meters"; @yoctoohm_meter: prefix!(yocto); "yΩ · m", "yoctoohm meter", "yoctoohm meters"; @abohm_meter: 1.0_E-9; "abΩ · m", "abohm meter", "abohm meters"; @statohm_meter: 8.987_552_917_115_481_E11; "statΩ · m", "statohm meter", "statohm meters"; @ohm_centimeter: prefix!(none) * prefix!(centi); "Ω · cm", "ohm centimeter", "ohm centimeters"; @abohm_centimeter: 1.0_E-9 * prefix!(centi); "abΩ · cm", "abohm centimeter", "abohm centimeters"; @statohm_centimeter: 8.987_552_917_115_481_E11 * prefix!(centi); "statΩ · cm", "statohm centimeter", "statohm centimeters"; @ohm_inch: 2.54_E-2; "Ω · in", "ohm inch", "ohm inches"; @ohm_foot: 3.048_E-1; "Ω · ft", "ohm foot", "ohm feet"; @ohm_yard: 9.144_E-1; "Ω · yd", "ohm yard", "ohm yards"; @ohm_square_millimeter_per_meter: prefix!(milli) * prefix!(milli); "Ω · mm²/m", "ohm square millimeter per meter", "ohm square millimeters per meter"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::electrical_resistance as r; use crate::si::electrical_resistivity as er; use crate::si::length as l; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: ElectricalResistivity = ElectricalResistance::new::(V::one()) * Length::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, R: r::Conversion, L: l::Conversion>() { Test::assert_approx_eq(&ElectricalResistivity::new::(V::one()), &(ElectricalResistance::new::(V::one()) * Length::new::(V::one()))); } } } } uom-0.35.0/src/si/energy.rs000064400000000000000000000161161046102023000135570ustar 00000000000000//! Energy (base unit joule, kg · m² · s⁻²). quantity! { /// Energy (base unit joule, kg · m² · s⁻²). quantity: Energy; "energy"; /// Dimension of energy, L²MT⁻² (base unit joule, kg · m² · s⁻²). dimension: ISQ< P2, // length P1, // mass N2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottajoule: prefix!(yotta); "YJ", "yottajoule", "yottajoules"; @zettajoule: prefix!(zetta); "ZJ", "zettajoule", "zettajoules"; @exajoule: prefix!(exa); "EJ", "exajoule", "exajoules"; @petajoule: prefix!(peta); "PJ", "petajoule", "petajoules"; @terajoule: prefix!(tera); "TJ", "terajoule", "terajoules"; @gigajoule: prefix!(giga); "GJ", "gigajoule", "gigajoules"; @megajoule: prefix!(mega); "MJ", "megajoule", "megajoules"; @kilojoule: prefix!(kilo); "kJ", "kilojoule", "kilojoules"; @hectojoule: prefix!(hecto); "hJ", "hectojoule", "hectojoules"; @decajoule: prefix!(deca); "daJ", "decajoule", "decajoules"; /// Derived unit of energy. @joule: prefix!(none); "J", "joule", "joules"; @decijoule: prefix!(deci); "dJ", "decijoule", "decijoules"; @centijoule: prefix!(centi); "cJ", "centijoule", "centijoules"; @millijoule: prefix!(milli); "mJ", "millijoule", "millijoules"; @microjoule: prefix!(micro); "µJ", "microjoule", "microjoules"; @nanojoule: prefix!(nano); "nJ", "nanojoule", "nanojoules"; @picojoule: prefix!(pico); "pJ", "picojoule", "picojoules"; @femtojoule: prefix!(femto); "fJ", "femtojoule", "femtojoules"; @attojoule: prefix!(atto); "aJ", "attojoule", "attojoules"; @zeptojoule: prefix!(zepto); "zJ", "zeptojoule", "zeptojoules"; @yoctojoule: prefix!(yocto); "yJ", "yoctojoule", "yoctojoules"; @petawatt_hour: 3.6_E18; "PW · h", "petawatt hour", "petawatt hours"; @terawatt_hour: 3.6_E15; "TW · h", "terawatt hour", "terawatt hours"; @gigawatt_hour: 3.6_E12; "GW · h", "gigawatt hour", "gigawatt hours"; @megawatt_hour: 3.6_E9; "MW · h", "megawatt hour", "megawatt hours"; @kilowatt_hour: 3.6_E6; "kW · h", "kilowatt hour", "kilowatt hours"; @hectowatt_hour: 3.6_E5; "hW · h", "hectowatt hour", "hectowatt hours"; @decawatt_hour: 3.6_E4; "daW · h", "decawatt hour", "decawatt hours"; @watt_hour: 3.6_E3; "W · h", "watt hour", "watt hours"; @milliwatt_hour: 3.6_E0; "mW · h", "milliwatt hour", "milliwatt hours"; @microwatt_hour: 3.6_E-3; "µW · h", "microwatt hour", "microwatt hours"; @petaelectronvolt: 1.602_176_634_E-4; "PeV", "petaelectronvolt", "petaelectronvolts"; @teraelectronvolt: 1.602_176_634_E-7; "TeV", "teraelectronvolt", "teraelectronvolts"; @gigaelectronvolt: 1.602_176_634_E-10; "GeV", "gigaelectronvolt", "gigaelectronvolts"; @megaelectronvolt: 1.602_176_634_E-13; "MeV", "megaelectronvolt", "megaelectronvolts"; @kiloelectronvolt: 1.602_176_634_E-16; "keV", "kiloelectronvolt", "kiloelectronvolts"; @hectoelectronvolt: 1.602_176_634_E-17; "heV", "hectoelectronvolt", "hectoelectronvolts"; @decaelectronvolt: 1.602_176_634_E-18; "daeV", "decaelectronvolt", "decaelectronvolts"; @electronvolt: 1.602_176_634_E-19; "eV", "electronvolt", "electronvolts"; /// Atomic unit of energy (Hartree energy). @hartree: 4.359_744_722_207_1_E-18; "Eₕ", "hartree", "hartrees"; @btu_it: 1.055_056_E3; "Btu (IT)", "British thermal unit (IT)", "British thermal units (IT)"; @btu: 1.054_350_E3; "Btu", "British thermal unit", "British thermal units"; @btu_39: 1.059_67_E3; "Btu₃₉", "British thermal unit (39 °F)", "British thermal units (39 °F)"; @btu_59: 1.054_80_E3; "Btu₅₉", "British thermal unit (59 °F)", "British thermal units (59 °F)"; @btu_60: 1.054_68_E3; "Btu₆₀", "British thermal unit (60 °F)", "British thermal units (60 °F)"; @calorie_it: 4.186_8_E0; "cal (IT)", "calorie (IT)", "calories (IT)"; @calorie: 4.184_E0; "cal", "calorie", "calories"; @calorie_15: 4.185_80_E0; "cal₁₅", "calorie (15 °C)", "calories (15 °C)"; @calorie_20: 4.181_90_E0; "cal₂₀", "calorie (20 °C)", "calories (20 °C)"; @calorie_it_nutrition: 4.186_8_E3; "Cal (IT)", "Calorie (IT)", "Calories (IT)"; @calorie_nutrition: 4.184_E3; "Cal", "Calorie", "Calories"; @erg: 1.0_E-7; "erg", "erg", "ergs"; @foot_poundal: 4.214_011_E-2; "ft · pdl", "foot poundal", "foot poundals"; @foot_pound: 1.355_818_E0; "ft · lbf", "foot pound-force", "foot pounds-force"; // @foot_pound_force @kilocalorie_it: 4.186_8_E3; "kcal (IT)", "kilocalorie (IT)", "kilocalories (IT)"; @kilocalorie: 4.184_E3; "kcal", "kilocalorie", "kilocalories"; @quad: 1.055_056_E18; "10¹⁵ Btu (IT)", "quad", "quads"; @therm_ec: 1.055_06_E8; "thm (EC)", "therm (EC)", "therms (EC)"; @therm_us: 1.054_804_E8; "thm", "therm", "therms"; @ton_tnt: 4.184_E9; "t of TNT", "ton of TNT", "tons of TNT"; @watt_second: 1.0_E0; "W · s", "watt second", "watt seconds"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::area as a; use crate::si::energy as e; use crate::si::mass as m; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: Energy = Area::new::(V::one()) * Mass::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one())); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, E: e::Conversion>() { Test::assert_approx_eq(&Energy::new::(V::one()), &(Area::new::(V::one()) * Mass::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one())))); } } } } uom-0.35.0/src/si/force.rs000064400000000000000000000156471046102023000133740ustar 00000000000000//! Force (base unit newton, kg · m · s⁻²). quantity! { /// Force (base unit newton, kg · m · s⁻²). quantity: Force; "force"; /// Dimension of force, LMT⁻² (base unit newton, kg · m · s⁻²). dimension: ISQ< P1, // length P1, // mass N2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottanewton: prefix!(yotta); "YN", "yottanewton", "yottanewtons"; @zettanewton: prefix!(zetta); "ZN", "zettanewton", "zettanewtons"; @exanewton: prefix!(exa); "EN", "exanewton", "exanewtons"; @petanewton: prefix!(peta); "PN", "petanewton", "petanewtons"; @teranewton: prefix!(tera); "TN", "teranewton", "teranewtons"; @giganewton: prefix!(giga); "GN", "giganewton", "giganewtons"; @meganewton: prefix!(mega); "MN", "meganewton", "meganewtons"; @kilonewton: prefix!(kilo); "kN", "kilonewton", "kilonewtons"; @hectonewton: prefix!(hecto); "hN", "hectonewton", "hectonewtons"; @decanewton: prefix!(deca); "daN", "decanewton", "decanewtons"; /// Derived unit of force. @newton: prefix!(none); "N", "newton", "newtons"; @decinewton: prefix!(deci); "dN", "decinewton", "decinewtons"; @centinewton: prefix!(centi); "cN", "centinewton", "centinewtons"; @millinewton: prefix!(milli); "mN", "millinewton", "millinewtons"; @micronewton: prefix!(micro); "µN", "micronewton", "micronewtons"; @nanonewton: prefix!(nano); "nN", "nanonewton", "nanonewtons"; @piconewton: prefix!(pico); "pN", "piconewton", "piconewtons"; @femtonewton: prefix!(femto); "fN", "femtonewton", "femtonewtons"; @attonewton: prefix!(atto); "aN", "attonewton", "attonewtons"; @zeptonewton: prefix!(zepto); "zN", "zeptonewton", "zeptonewtons"; @yoctonewton: prefix!(yocto); "yN", "yoctonewton", "yoctonewtons"; @dyne: 1.0_E-5; "dyn", "dyne", "dynes"; @kilogram_force: 9.806_65_E0; "kgf", "kilogram-force", "kilograms-force"; // kilopond @kip: 4.448_222_E3; "kip", "kip", "kips"; @ounce_force: 2.780_139_E-1; "ozf", "ounce-force", "ounces-force"; @poundal: 1.382_550_E-1; "pdl", "poundal", "poundals"; @pound_force: 4.448_222_E0; "lbf", "pound-force", "pounds-force"; @ton_force: 8.896_443_E3; "2000 lbf", "ton-force", "tons-force"; // Uses the metric ton } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::force as f; use crate::si::length as l; use crate::si::mass as m; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: Force = (Mass::new::(V::one()) * Length::new::(V::one())) / (Time::new::(V::one()) * Time::new::(V::one())); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test< M: m::Conversion, L: l::Conversion, T: t::Conversion, F: f::Conversion>() { Test::assert_approx_eq(&Force::new::(V::one()), &((Mass::new::(V::one()) * Length::new::(V::one())) / (Time::new::(V::one()) * Time::new::(V::one())))); } } } } uom-0.35.0/src/si/frequency.rs000064400000000000000000000110161046102023000142610ustar 00000000000000//! Frequency (base unit hertz, s⁻¹). quantity! { /// Frequency (base unit hertz, s⁻¹). quantity: Frequency; "frequency"; /// Dimension of frequency, T⁻¹ (base unit hertz, s⁻¹). dimension: ISQ< Z0, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottahertz: prefix!(yotta); "YHz", "yottahertz", "yottahertz"; @zettahertz: prefix!(zetta); "ZHz", "zettahertz", "zettahertz"; @exahertz: prefix!(exa); "EHz", "exahertz", "exahertz"; @petahertz: prefix!(peta); "PHz", "petahertz", "petahertz"; @terahertz: prefix!(tera); "THz", "terahertz", "terahertz"; @gigahertz: prefix!(giga); "GHz", "gigahertz", "gigahertz"; @megahertz: prefix!(mega); "MHz", "megahertz", "megahertz"; @kilohertz: prefix!(kilo); "kHz", "kilohertz", "kilohertz"; @hectohertz: prefix!(hecto); "hHz", "hectohertz", "hectohertz"; @decahertz: prefix!(deca); "daHz", "decahertz", "decahertz"; /// The hertz is one cycle per second. @hertz: prefix!(none); "Hz", "hertz", "hertz"; @decihertz: prefix!(deci); "dHz", "decihertz", "decihertz"; @centihertz: prefix!(centi); "cHz", "centihertz", "centihertz"; @millihertz: prefix!(milli); "mHz", "millihertz", "millihertz"; @microhertz: prefix!(micro); "µHz", "microhertz", "microhertz"; @nanohertz: prefix!(nano); "nHz", "nanohertz", "nanohertz"; @picohertz: prefix!(pico); "pHz", "picohertz", "picohertz"; @femtohertz: prefix!(femto); "fHz", "femtohertz", "femtohertz"; @attohertz: prefix!(atto); "aHz", "attohertz", "attohertz"; @zeptohertz: prefix!(zepto); "zHz", "zeptohertz", "zeptohertz"; @yoctohertz: prefix!(yocto); "yHz", "yoctohertz", "yoctohertz"; @cycle_per_day: 1.157_407_407_407_407_4_E-5; "1/d", "cycle per day", "cycles per day"; @cycle_per_hour: 2.777_777_777_777_777_E-4; "1/h", "cycle per hour", "cycles per hour"; @cycle_per_minute: 1.666_666_666_666_666_6E-2; "1/min", "cycle per minute", "cycles per minute"; @cycle_per_shake: 1.0_E8; "100 MHz", "cycle per shake", "cycles per shake"; @cycle_per_year: 3.170_979_198_376_458_E-8; "1/a", "cycle per year", "cycles per year"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::frequency as f; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: Time = V::one() / Frequency::new::(V::one()); let _: Frequency = V::one() / Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, F: f::Conversion>() { Test::assert_approx_eq(&(V::one() / Time::new::(V::one())), &Frequency::new::(V::one())); Test::assert_approx_eq(&Time::new::(V::one()), &(V::one() / Frequency::new::(V::one()))); } } } } uom-0.35.0/src/si/frequency_drift.rs000064400000000000000000000045341046102023000154600ustar 00000000000000//! Frequency drift (base unit hertz per second, s⁻²). //! //! Typical application: Frequency slope in FMCW radars. quantity! { /// Frequency drift (base unit hertz per second, s⁻²). quantity: FrequencyDrift; "frequency drift"; /// Dimension of frequency drift, T⁻² (base unit hertz per second, s⁻²). dimension: ISQ< Z0, // length Z0, // mass N2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @terahertz_per_second: prefix!(tera) / prefix!(none); "THz/s", "terahertz per second", "terahertz per second"; @gigahertz_per_second: prefix!(giga) / prefix!(none); "GHz/s", "gigahertz per second", "gigahertz per second"; @megahertz_per_second: prefix!(mega) / prefix!(none); "MHz/s", "megahertz per second", "megahertz per second"; @kilohertz_per_second: prefix!(kilo) / prefix!(none); "kHz/s", "kilohertz per second", "kilohertz per second"; @hertz_per_second: prefix!(none) / prefix!(none); "Hz/s", "hertz per second", "hertz per second"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::frequency_drift as fd; use crate::si::frequency as f; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: FrequencyDrift = Frequency::new::(V::one()) / Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, FD: fd::Conversion>() { Test::assert_approx_eq(&FrequencyDrift::new::(V::one()), &(Frequency::new::(V::one()) / Time::new::(V::one()))); } } } } uom-0.35.0/src/si/heat_capacity.rs000064400000000000000000000367711046102023000150750ustar 00000000000000//! Heat capacity (base unit joule per kelvin, kg · m² · s⁻² · K⁻¹). //! //! Heat capacity has the same kind as [temperature interval][ti], as this quantity relates to //! change of temperature. Not of kind `TemperatureKind`, used by [thermodynamic temperature][tt]. //! See [thermodynamic temperature][tt] for a full explanation. //! //! This quantity might be used to define the heat capacity of an object. To define heat capacity //! of a material, use [specific heat capacity][shc]. //! //! [ti]: ../temperature_interval/index.html //! [tt]: ../thermodynamic_temperature/index.html //! [shc]: ../specific_heat_capacity/index.html quantity! { /// Heat capacity (base unit joule per kelvin, kg · m² · s⁻² · K⁻¹). quantity: HeatCapacity; "heat capacity"; /// Dimension of heat capacity, L²MT⁻²Th⁻¹ (base unit joule per kelvin, kg · m² · s⁻² · K⁻¹). dimension: ISQ< P2, // length P1, // mass N2, // time Z0, // electric current N1, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottagram_square_meter_per_second_squared_kelvin: prefix!(yotta) / prefix!(kilo); "Yg · m²/(s² · K)", "yottagram square meter per second squared kelvin", "yottagram square meters per second squared kelvin"; @zettagram_square_meter_per_second_squared_kelvin: prefix!(zetta) / prefix!(kilo); "Zg · m²/(s² · K)", "zettagram square meter per second squared kelvin", "zettagram square meters per second squared kelvin"; @exagram_square_meter_per_second_squared_kelvin: prefix!(exa) / prefix!(kilo); "Eg · m²/(s² · K)", "exagram square meter per second squared kelvin", "exagram square meters per second squared kelvin"; @petagram_square_meter_per_second_squared_kelvin: prefix!(peta) / prefix!(kilo); "Pg · m²/(s² · K)", "petagram square meter per second squared kelvin", "petagram square meters per second squared kelvin"; @teragram_square_meter_per_second_squared_kelvin: prefix!(tera) / prefix!(kilo); "Tg · m²/(s² · K)", "teragram square meter per second squared kelvin", "teragram square meters per second squared kelvin"; @gigagram_square_meter_per_second_squared_kelvin: prefix!(giga) / prefix!(kilo); "Gg · m²/(s² · K)", "gigagram square meter per second squared kelvin", "gigagram square meters per second squared kelvin"; @megagram_square_meter_per_second_squared_kelvin: prefix!(mega) / prefix!(kilo); "Mg · m²/(s² · K)", "megagram square meter per second squared kelvin", "megagram square meters per second squared kelvin"; /// The derived unit of heat capacity expressed in base units. Equivalent to J/K. @kilogram_square_meter_per_second_squared_kelvin: prefix!(kilo) / prefix!(kilo); "kg · m²/(s² · K)", "kilogram square meter per second squared kelvin", "kilogram square meters per second squared kelvin"; @hectogram_square_meter_per_second_squared_kelvin: prefix!(hecto) / prefix!(kilo); "hg · m²/(s² · K)", "hectogram square meter per second squared kelvin", "hectogram square meters per second squared kelvin"; @decagram_square_meter_per_second_squared_kelvin: prefix!(deca) / prefix!(kilo); "dag · m²/(s² · K)", "decagram square meter per second squared kelvin", "decagram square meters per second squared kelvin"; @gram_square_meter_per_second_squared_kelvin: prefix!(none) / prefix!(kilo); "g · m²/(s² · K)", "gram square meter per second squared kelvin", "gram square meters per second squared kelvin"; @decigram_square_meter_per_second_squared_kelvin: prefix!(deci) / prefix!(kilo); "dg · m²/(s² · K)", "decigram square meter per second squared kelvin", "decigram square meters per second squared kelvin"; @centigram_square_meter_per_second_squared_kelvin: prefix!(centi) / prefix!(kilo); "cg · m²/(s² · K)", "centigram square meter per second squared kelvin", "centigram square meters per second squared kelvin"; @milligram_square_meter_per_second_squared_kelvin: prefix!(milli) / prefix!(kilo); "mg · m²/(s² · K)", "milligram square meter per second squared kelvin", "milligram square meters per second squared kelvin"; @microgram_square_meter_per_second_squared_kelvin: prefix!(micro) / prefix!(kilo); "µg · m²/(s² · K)", "microgram square meter per second squared kelvin", "microgram square meters per second squared kelvin"; @nanogram_square_meter_per_second_squared_kelvin: prefix!(nano) / prefix!(kilo); "ng · m²/(s² · K)", "nanogram square meter per second squared kelvin", "nanogram square meters per second squared kelvin"; @picogram_square_meter_per_second_squared_kelvin: prefix!(pico) / prefix!(kilo); "pg · m²/(s² · K)", "picogram square meter per second squared kelvin", "picogram square meters per second squared kelvin"; @femtogram_square_meter_per_second_squared_kelvin: prefix!(femto) / prefix!(kilo); "fg · m²/(s² · K)", "femtogram square meter per second squared kelvin", "femtogram square meters per second squared kelvin"; @attogram_square_meter_per_second_squared_kelvin: prefix!(atto) / prefix!(kilo); "ag · m²/(s² · K)", "attogram square meter per second squared kelvin", "attogram square meters per second squared kelvin"; @zeptogram_square_meter_per_second_squared_kelvin: prefix!(zepto) / prefix!(kilo); "zg · m²/(s² · K)", "zeptogram square meter per second squared kelvin", "zeptogram square meters per second squared kelvin"; @yoctogram_square_meter_per_second_squared_kelvin: prefix!(yocto) / prefix!(kilo); "yg · m²/(s² · K)", "yoctogram square meter per second squared kelvin", "yoctogram square meters per second squared kelvin"; // Heat capacity is much more commonly expressed in terms of energy / temperature. @yottajoule_per_kelvin: prefix!(yotta); "YJ/K", "yottajoule per kelvin", "yottajoules per kelvin"; @zettajoule_per_kelvin: prefix!(zetta); "ZJ/K", "zettajoule per kelvin", "zettajoules per kelvin"; @exajoule_per_kelvin: prefix!(exa); "EJ/K", "exajoule per kelvin", "exajoules per kelvin"; @petajoule_per_kelvin: prefix!(peta); "PJ/K", "petajoule per kelvin", "petajoules per kelvin"; @terajoule_per_kelvin: prefix!(tera); "TJ/K", "terajoule per kelvin", "terajoules per kelvin"; @gigajoule_per_kelvin: prefix!(giga); "GJ/K", "gigajoule per kelvin", "gigajoules per kelvin"; @megajoule_per_kelvin: prefix!(mega); "MJ/K", "megajoule per kelvin", "megajoules per kelvin"; @kilojoule_per_kelvin: prefix!(kilo); "kJ/K", "kilojoule per kelvin", "kilojoules per kelvin"; @hectojoule_per_kelvin: prefix!(hecto); "hJ/K", "hectojoule per kelvin", "hectojoules per kelvin"; @decajoule_per_kelvin: prefix!(deca); "daJ/K", "decajoule per kelvin", "decajoules per kelvin"; /// Derived unit of heat capacity expressed in terms of derived unit Joule. Equivalent to /// kg · m²/(s² · K). @joule_per_kelvin: prefix!(none); "J/K", "joule per kelvin", "joules per kelvin"; @decijoule_per_kelvin: prefix!(deci); "dJ/K", "decijoule per kelvin", "decijoules per kelvin"; @centijoule_per_kelvin: prefix!(centi); "cJ/K", "centijoule per kelvin", "centijoules per kelvin"; @millijoule_per_kelvin: prefix!(milli); "mJ/K", "millijoule per kelvin", "millijoules per kelvin"; @microjoule_per_kelvin: prefix!(micro); "µJ/K", "microjoule per kelvin", "microjoules per kelvin"; @nanojoule_per_kelvin: prefix!(nano); "nJ/K", "nanojoule per kelvin", "nanojoules per kelvin"; @picojoule_per_kelvin: prefix!(pico); "pJ/K", "picojoule per kelvin", "picojoules per kelvin"; @femtojoule_per_kelvin: prefix!(femto); "fJ/K", "femtojoule per kelvin", "femtojoules per kelvin"; @attojoule_per_kelvin: prefix!(atto); "aJ/K", "attojoule per kelvin", "attojoules per kelvin"; @zeptojoule_per_kelvin: prefix!(zepto); "zJ/K", "zeptojoule per kelvin", "zeptojoules per kelvin"; @yoctojoule_per_kelvin: prefix!(yocto); "yJ/K", "yoctojoule per kelvin", "yoctojoules per kelvin"; @kilojoule_per_degree_celsius: 1.0_E3; "kJ/°C", "kilojoule per degree celsius", "kilojoules per degree celsius"; @joule_per_degree_celsius: 1.0_E0; "J/°C", "joule per degree celsius", "joules per degree celsius"; @millijoule_per_degree_celsius: 1.0_E-3; "mJ/°C", "millijoule per degree celsius", "millijoules per degree celsius"; @btu_per_degree_fahrenheit: 1.897_830_E3; "Btu/°F", "British thermal unit per degree Fahrenheit", "British thermal units per degree Fahrenheit"; @btu_it_per_degree_fahrenheit: 1.899_100_8_E3; "Btu (IT)/°F", "British thermal unit (IT) per degree Fahrenheit", "British thermal units (IT) per degree Fahrenheit"; @boltzmann_constant: 1.380_649_E-23; "k", "Boltzmann constant", "Boltzmann constants"; @calorie_per_kelvin: 4.184_E0; "cal/K", "calorie per kelvin", "calories per kelvin"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::energy as e; use crate::si::heat_capacity as hc; use crate::si::length as l; use crate::si::mass as m; use crate::si::quantities::*; use crate::si::temperature_interval as ti; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: HeatCapacity = Mass::new::(V::one()) * Length::new::(V::one()) * Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * TemperatureInterval::new::(V::one())); } #[test] fn check_base_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, HC: hc::Conversion>() { Test::assert_approx_eq(&HeatCapacity::new::(V::one()), &(Mass::new::(V::one()) * Length::new::(V::one()) * Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * TemperatureInterval::new::(V::one())))); } } #[test] fn check_energy_per_ti_hc_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, TI: ti::Conversion, HC: hc::Conversion>() { Test::assert_approx_eq(&HeatCapacity::new::(V::one()), &(Energy::new::(V::one()) / TemperatureInterval::new::(V::one()))); } } } } uom-0.35.0/src/si/heat_flux_density.rs000064400000000000000000000150001046102023000157730ustar 00000000000000//! Heat flux density (base unit watt per square meter, kg · s⁻³). quantity! { /// Heat flux density (base unit watt per square meter, kg · s⁻³). quantity: HeatFluxDensity; "heat flux density"; /// Dimension of heat flux density, MT⁻³ (base unit watt per square meter, kg · s⁻³). dimension: ISQ< Z0, // length P1, // mass N3, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottawatt_per_square_meter: prefix!(yotta); "YW/m²", "yottawatt per square meter", "yottawatts per square meter"; @zettawatt_per_square_meter: prefix!(zetta); "ZW/m²", "zettawatt per square meter", "zettawatts per square meter"; @exawatt_per_square_meter: prefix!(exa); "EW/m²", "exawatt per square meter", "exawatts per square meter"; @petawatt_per_square_meter: prefix!(peta); "PW/m²", "petawatt per square meter", "petawatts per square meter"; @terawatt_per_square_meter: prefix!(tera); "TW/m²", "terawatt per square meter", "terawatts per square meter"; @gigawatt_per_square_meter: prefix!(giga); "GW/m²", "gigawatt per square meter", "gigawatts per square meter"; @megawatt_per_square_meter: prefix!(mega); "MW/m²", "megawatt per square meter", "megawatts per square meter"; /// Derived unit of density. @kilowatt_per_square_meter: prefix!(kilo); "kW/m²", "kilowatt per square meter", "kilowatts per square meter"; @hectowatt_per_square_meter: prefix!(hecto); "hW/m²", "hectowatt per square meter", "hectowatts per square meter"; @decawatt_per_square_meter: prefix!(deca); "daW/m²", "decawatt per square meter", "decawatts per square meter"; @watt_per_square_meter: prefix!(none); "W/m²", "watt per square meter", "watts per square meter"; @deciwatt_per_square_meter: prefix!(deci); "dW/m²", "deciwatt per square meter", "deciwatts per square meter"; @centiwatt_per_square_meter: prefix!(centi); "cW/m²", "centiwatt per square meter", "centiwatts per square meter"; @milliwatt_per_square_meter: prefix!(milli); "mW/m²", "milliwatt per square meter", "milliwatts per square meter"; @microwatt_per_square_meter: prefix!(micro); "µW/m²", "microwatt per square meter", "microwatts per square meter"; @nanowatt_per_square_meter: prefix!(nano); "nW/m²", "nanowatt per square meter", "nanowatts per square meter"; @picowatt_per_square_meter: prefix!(pico); "pW/m²", "picowatt per square meter", "picowatts per square meter"; @femtowatt_per_square_meter: prefix!(femto); "fW/m²", "femtowatt per square meter", "femtowatts per square meter"; @attowatt_per_square_meter: prefix!(atto); "aW/m²", "attowatt per square meter", "attowatts per square meter"; @zeptowatt_per_square_meter: prefix!(zepto); "zW/m²", "zeptowatt per square meter", "zeptowatts per square meter"; @yoctowatt_per_square_meter: prefix!(yocto); "yW/m²", "yoctowatt per square meter", "yoctowatts per square meter"; @watt_per_square_centimeter: prefix!(none) / prefix!(centi) / prefix!(centi); "W/cm²", "watt per square centimeter", "watts per square centimeter"; @watt_per_square_millimeter: prefix!(none) / prefix!(milli) / prefix!(milli); "W/mm²", "watt per square millimeter", "watts per square millimeter"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::area as a; use crate::si::heat_flux_density as d; use crate::si::length as l; use crate::si::power as p; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: HeatFluxDensity = Power::new::(V::one()) / (Length::new::(V::one()) * Length::new::(V::one())); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, D: d::Conversion>() { Test::assert_approx_eq( &HeatFluxDensity::new::(V::one()), &(Power::new::

(V::one()) / (Length::new::(V::one()) * Length::new::(V::one())))); } } #[test] fn check_units_power_area() { test::(); test::(); test::(); fn test, A: a::Conversion, D: d::Conversion>() { Test::assert_approx_eq(&HeatFluxDensity::new::(V::one()), &(Power::new::

(V::one()) / Area::new::(V::one()))); } } } } uom-0.35.0/src/si/heat_transfer.rs000064400000000000000000000552221046102023000151140ustar 00000000000000//! Heat transfer (base unit watt per square meter kelvin, kg · s⁻³ · K⁻¹). //! //! Heat transfer is also known as heat transfer coefficient, film coefficient, or film //! effectiveness. Commonly expressed using derived units power and area: watt per square meter //! kelvin. //! //! Heat transfer has the same kind as [temperature interval][ti], as this quantity relates to //! change of temperature. Not of kind `TemperatureKind`, used by [thermodynamic temperature][tt]. //! See [thermodynamic temperature][tt] for a full explanation. //! //! [ti]: ../temperature_interval/index.html //! [tt]: ../thermodynamic_temperature/index.html quantity! { /// Heat transfer (base unit watt per square meter kelvin, kg · s⁻³ · K⁻¹). quantity: HeatTransfer; "heat transfer"; /// Dimension of heat transfer, MT⁻³Th⁻¹ (base unit watt per square meter kelvin, /// kg · s⁻³ · K⁻¹). dimension: ISQ< Z0, // length P1, // mass N3, // time Z0, // electric current N1, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottagram_per_second_cubed_kelvin: prefix!(yotta) / prefix!(kilo); "Yg/(s³ · K)", "yottagram per second cubed kelvin", "yottagrams per second cubed kelvin"; @zettagram_per_second_cubed_kelvin: prefix!(zetta) / prefix!(kilo); "Zg/(s³ · K)", "zettagram per second cubed kelvin", "zettagrams per second cubed kelvin"; @exagram_per_second_cubed_kelvin: prefix!(exa) / prefix!(kilo); "Eg/(s³ · K)", "exagram per second cubed kelvin", "exagrams per second cubed kelvin"; @petagram_per_second_cubed_kelvin: prefix!(peta) / prefix!(kilo); "Pg/(s³ · K)", "petagram per second cubed kelvin", "petagrams per second cubed kelvin"; @teragram_per_second_cubed_kelvin: prefix!(tera) / prefix!(kilo); "Tg/(s³ · K)", "teragram per second cubed kelvin", "teragrams per second cubed kelvin"; @gigagram_per_second_cubed_kelvin: prefix!(giga) / prefix!(kilo); "Gg/(s³ · K)", "gigagram per second cubed kelvin", "gigagrams per second cubed kelvin"; @megagram_per_second_cubed_kelvin: prefix!(mega) / prefix!(kilo); "Mg/(s³ · K)", "megagram per second cubed kelvin", "megagrams per second cubed kelvin"; /// Derived unit of heat transfer in base units. Equivalent to W/(m² · K). @kilogram_per_second_cubed_kelvin: prefix!(kilo) / prefix!(kilo); "kg/(s³ · K)", "kilogram per second cubed kelvin", "kilograms per second cubed kelvin"; @hectogram_per_second_cubed_kelvin: prefix!(hecto) / prefix!(kilo); "hg/(s³ · K)", "hectogram per second cubed kelvin", "hectograms per second cubed kelvin"; @decagram_per_second_cubed_kelvin: prefix!(deca) / prefix!(kilo); "dag/(s³ · K)", "decagram per second cubed kelvin", "decagrams per second cubed kelvin"; @gram_per_second_cubed_kelvin: prefix!(none) / prefix!(kilo); "g/(s³ · K)", "gram per second cubed kelvin", "grams per second cubed kelvin"; @decigram_per_second_cubed_kelvin: prefix!(deci) / prefix!(kilo); "dg/(s³ · K)", "decigram per second cubed kelvin", "decigrams per second cubed kelvin"; @centigram_per_second_cubed_kelvin: prefix!(centi) / prefix!(kilo); "cg/(s³ · K)", "centigram per second cubed kelvin", "centigrams per second cubed kelvin"; @milligram_per_second_cubed_kelvin: prefix!(milli) / prefix!(kilo); "mg/(s³ · K)", "milligram per second cubed kelvin", "milligrams per second cubed kelvin"; @microgram_per_second_cubed_kelvin: prefix!(micro) / prefix!(kilo); "µg/(s³ · K)", "microgram per second cubed kelvin", "micrograms per second cubed kelvin"; @nanogram_per_second_cubed_kelvin: prefix!(nano) / prefix!(kilo); "ng/(s³ · K)", "nanogram per second cubed kelvin", "nanograms per second cubed kelvin"; @picogram_per_second_cubed_kelvin: prefix!(pico) / prefix!(kilo); "pg/(s³ · K)", "picogram per second cubed kelvin", "picograms per second cubed kelvin"; @femtogram_per_second_cubed_kelvin: prefix!(femto) / prefix!(kilo); "fg/(s³ · K)", "femtogram per second cubed kelvin", "femtograms per second cubed kelvin"; @attogram_per_second_cubed_kelvin: prefix!(atto) / prefix!(kilo); "ag/(s³ · K)", "attogram per second cubed kelvin", "attograms per second cubed kelvin"; @zeptogram_per_second_cubed_kelvin: prefix!(zepto) / prefix!(kilo); "zg/(s³ · K)", "zeptogram per second cubed kelvin", "zeptograms per second cubed kelvin"; @yoctogram_per_second_cubed_kelvin: prefix!(yocto) / prefix!(kilo); "yg/(s³ · K)", "yoctogram per second cubed kelvin", "yoctograms per second cubed kelvin"; @kilogram_per_second_cubed_degree_celsius: prefix!(kilo) / prefix!(kilo); "kg/(s³ · °C)", "kilogram per second cubed degree celsius", "kilograms per second cubed degree celsius"; // Heat transfer is much more commonly expressed in terms of power / area (heat flux). @yottawatt_per_square_meter_kelvin: prefix!(yotta); "YW/(m² · K)", "yottawatt per square meter kelvin", "yottawatts per square meter kelvin"; @zettawatt_per_square_meter_kelvin: prefix!(zetta); "ZW/(m² · K)", "zettawatt per square meter kelvin", "zettawatts per square meter kelvin"; @exawatt_per_square_meter_kelvin: prefix!(exa); "EW/(m² · K)", "exawatt per square meter kelvin", "exawatts per square meter kelvin"; @petawatt_per_square_meter_kelvin: prefix!(peta); "PW/(m² · K)", "petawatt per square meter kelvin", "petawatts per square meter kelvin"; @terawatt_per_square_meter_kelvin: prefix!(tera); "TW/(m² · K)", "terawatt per square meter kelvin", "terawatts per square meter kelvin"; @gigawatt_per_square_meter_kelvin: prefix!(giga); "GW/(m² · K)", "gigawatt per square meter kelvin", "gigawatts per square meter kelvin"; @megawatt_per_square_meter_kelvin: prefix!(mega); "MW/(m² · K)", "megawatt per square meter kelvin", "megawatts per square meter kelvin"; @kilowatt_per_square_meter_kelvin: prefix!(kilo); "kW/(m² · K)", "kilowatt per square meter kelvin", "kilowatts per square meter kelvin"; @hectowatt_per_square_meter_kelvin: prefix!(hecto); "hW/(m² · K)", "hectowatt per square meter kelvin", "hectowatts per square meter kelvin"; @decawatt_per_square_meter_kelvin: prefix!(deca); "daW/(m² · K)", "decawatt per square meter kelvin", "decawatts per square meter kelvin"; /// Derived unit of heat transfer in derived units. Equivalent to kg/(s³ · K). @watt_per_square_meter_kelvin: prefix!(none); "W/(m² · K)", "watt per square meter kelvin", "watts per square meter kelvin"; @deciwatt_per_square_meter_kelvin: prefix!(deci); "dW/(m² · K)", "deciwatt per square meter kelvin", "deciwatts per square meter kelvin"; @centiwatt_per_square_meter_kelvin: prefix!(centi); "cW/(m² · K)", "centiwatt per square meter kelvin", "centiwatts per square meter kelvin"; @milliwatt_per_square_meter_kelvin: prefix!(milli); "mW/(m² · K)", "milliwatt per square meter kelvin", "milliwatts per square meter kelvin"; @microwatt_per_square_meter_kelvin: prefix!(micro); "µW/(m² · K)", "microwatt per square meter kelvin", "microwatts per square meter kelvin"; @nanowatt_per_square_meter_kelvin: prefix!(nano); "nW/(m² · K)", "nanowatt per square meter kelvin", "nanowatts per square meter kelvin"; @picowatt_per_square_meter_kelvin: prefix!(pico); "pW/(m² · K)", "picowatt per square meter kelvin", "picowatts per square meter kelvin"; @femtowatt_per_square_meter_kelvin: prefix!(femto); "fW/(m² · K)", "femtowatt per square meter kelvin", "femtowatts per square meter kelvin"; @attowatt_per_square_meter_kelvin: prefix!(atto); "aW/(m² · K)", "attowatt per square meter kelvin", "attowatts per square meter kelvin"; @zeptowatt_per_square_meter_kelvin: prefix!(zepto); "zW/(m² · K)", "zeptowatt per square meter kelvin", "zeptowatts per square meter kelvin"; @yoctowatt_per_square_meter_kelvin: prefix!(yocto); "yW/(m² · K)", "yoctowatt per square meter kelvin", "yoctowatts per square meter kelvin"; // Power per area temperature interval @watt_per_square_kilometer_degree_celsius: prefix!(none) / (prefix!(kilo) * prefix!(kilo)); "W/(km² · °C)", "watt per square kilometer degree celsius", "watts per square kilometer degree celsius"; @watt_per_square_meter_degree_celsius: prefix!(none); "W/(m² · °C)", "watt per square meter degree celsius", "watts per square meter degree celsius"; @watt_per_square_centimeter_degree_celsius: prefix!(none) / (prefix!(centi) * prefix!(centi)); "W/(cm² · °C)", "watt per square centimeter degree celsius", "watts per square centimeter degree celsius"; @watt_per_square_millimeter_degree_celsius: prefix!(none) / (prefix!(milli) * prefix!(milli)); "W/(mm² · °C)", "watt per square millimeter degree celsius", "watts per square millimeter degree celsius"; // Energy per time area temperature interval @joule_per_second_square_meter_kelvin: prefix!(none); "J/(s · m² · K)", "joule per second square meter kelvin", "joules per second square meter kelvin"; @joule_per_second_square_meter_degree_celsius: prefix!(none); "J/(s · m² · °C)", "joule per second square meter degree celsius", "joules per second square meter degree celsius"; @btu_it_per_hour_square_foot_degree_fahrenheit: 5.678_264_134_306_046; "Btu (IT)/(hr · ft² · °F)", "British thermal unit (IT) per hour square foot degree Fahrenheit", "British thermal units (IT) per hour square foot degree Fahrenheit"; @btu_it_per_hour_square_inch_degree_fahrenheit: 8.176_700_353_400_707_E2; "Btu (IT)/(hr · in² · °F)", "British thermal unit (IT) per hour square inch degree Fahrenheit", "British thermal units (IT) per hour square inch degree Fahrenheit"; @btu_it_per_minute_square_foot_degree_fahrenheit: 3.406_958_480_583_627_4_E2; "Btu (IT)/(min · ft² · °F)", "British thermal unit (IT) per minute square foot degree Fahrenheit", "British thermal units (IT) per minute square foot degree Fahrenheit"; @btu_it_per_minute_square_inch_degree_fahrenheit: 4.906_020_212_040_425_E4; "Btu (IT)/(min · in² · °F)", "British thermal unit (IT) per minute square inch degree Fahrenheit", "British thermal units (IT) per minute square inch degree Fahrenheit"; @btu_it_per_second_square_foot_degree_fahrenheit: 2.044_175_088_350_176_5_E4; "Btu (IT)/(s · ft² · °F)", "British thermal unit (IT) per second square foot degree Fahrenheit", "British thermal units (IT) per second square foot degree Fahrenheit"; @btu_it_per_second_square_inch_degree_fahrenheit: 2.943_612_127_224_254_4_E6; "Btu (IT)/(s · in² · °F)", "British thermal unit (IT) per second square inch degree Fahrenheit", "British thermal units (IT) per second square inch degree Fahrenheit"; @btu_per_hour_square_foot_degree_fahrenheit: 5.674_464_473_928_946; "Btu/(hr · ft² · °F)", "British thermal unit per hour square foot degree Fahrenheit", "British thermal units per hour square foot degree Fahrenheit"; @btu_per_hour_square_inch_degree_fahrenheit: 8.171_228_842_457_684_E2; "Btu/(hr · in² · °F)", "British thermal unit per hour square inch degree Fahrenheit", "British thermal units per hour square inch degree Fahrenheit"; @btu_per_minute_square_foot_degree_fahrenheit: 3.404_678_684_357_368_E2; "Btu/(min · ft² · °F)", "British thermal unit per minute square foot degree Fahrenheit", "British thermal units per minute square foot degree Fahrenheit"; @btu_per_minute_square_inch_degree_fahrenheit: 4.902_737_305_474_611_E4; "Btu/(min · in² · °F)", "British thermal unit per minute square inch degree Fahrenheit", "British thermal units per minute square inch degree Fahrenheit"; @btu_per_second_square_foot_degree_fahrenheit: 2.042_807_210_614_421_E4; "Btu/(s · ft² · °F)", "British thermal unit per second square foot degree Fahrenheit", "British thermal units per second square foot degree Fahrenheit"; @btu_per_second_square_inch_degree_fahrenheit: 2.941_642_383_284_766_E6; "Btu/(s · in² · °F)", "British thermal unit per second square inch degree Fahrenheit", "British thermal units per second square inch degree Fahrenheit"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::area as a; use crate::si::energy as e; use crate::si::heat_transfer as ht; use crate::si::mass as m; use crate::si::power as p; use crate::si::quantities::*; use crate::si::temperature_interval as ti; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: HeatTransfer = Mass::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * Time::new::(V::one()) * TemperatureInterval::new::(V::one())); } #[test] fn check_base_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test< M: m::Conversion, T: t::Conversion, TI: ti::Conversion, HT: ht::Conversion>() { Test::assert_approx_eq(&HeatTransfer::new::(V::one()), &(Mass::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * Time::new::(V::one()) * TemperatureInterval::new::(V::one())))); } } #[test] fn check_power_per_area_ti_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test< P: p::Conversion, A: a::Conversion, TI: ti::Conversion, HT: ht::Conversion>() { Test::assert_approx_eq(&HeatTransfer::new::(V::one()), &(Power::new::

(V::one()) / (Area::new::(V::one()) * TemperatureInterval::new::(V::one())))); } } #[test] fn check_energy_per_time_area_ti_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test< E: e::Conversion, T: t::Conversion, A: a::Conversion, TI: ti::Conversion, HT: ht::Conversion>() { Test::assert_approx_eq(&HeatTransfer::new::(V::one()), &(Energy::new::(V::one()) / (Time::new::(V::one()) * Area::new::(V::one()) * TemperatureInterval::new::(V::one())))); } } } } uom-0.35.0/src/si/inductance.rs000064400000000000000000000107541046102023000144050ustar 00000000000000//! Inductance (base unit henry, m² · kg · s⁻² · A⁻²). quantity! { /// Inductance (base unit henry, m² · kg · s⁻² · A⁻²). quantity: Inductance; "inductance"; /// Dimension of inductance, L²MT⁻²I⁻² (base unit henry, m² · kg · s⁻² · A⁻²). dimension: ISQ< P2, // length P1, // mass N2, // time N2, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottahenry: prefix!(yotta); "YH", "yottahenry", "yottahenries"; @zettahenry: prefix!(zetta); "ZH", "zettahenry", "zettahenries"; @exahenry: prefix!(exa); "EH", "exahenry", "exahenries"; @petahenry: prefix!(peta); "PH", "petahenry", "petahenries"; @terahenry: prefix!(tera); "TH", "terahenry", "terahenries"; @gigahenry: prefix!(giga); "GH", "gigahenry", "gigahenries"; @megahenry: prefix!(mega); "MH", "megahenry", "megahenries"; @kilohenry: prefix!(kilo); "kH", "kilohenry", "kilohenries"; @hectohenry: prefix!(hecto); "hH", "hectohenry", "hectohenries"; @decahenry: prefix!(deca); "daH", "decahenry", "decahenries"; /// Derived unit of inductance. @henry: prefix!(none); "H", "henry", "henries"; @decihenry: prefix!(deci); "dH", "decihenry", "decihenries"; @centihenry: prefix!(centi); "cH", "centihenry", "centihenries"; @millihenry: prefix!(milli); "mH", "millihenry", "millihenries"; @microhenry: prefix!(micro); "µH", "microhenry", "microhenries"; @nanohenry: prefix!(nano); "nH", "nanohenry", "nanohenries"; @picohenry: prefix!(pico); "pH", "picohenry", "picohenries"; @femtohenry: prefix!(femto); "fH", "femtohenry", "femtohenries"; @attohenry: prefix!(atto); "aH", "attohenry", "attohenries"; @zeptohenry: prefix!(zepto); "zH", "zeptohenry", "zeptohenries"; @yoctohenry: prefix!(yocto); "yH", "yoctohenry", "yoctohenries"; @abhenry: 1.0_E-9; "abH", "abhenry", "abhenries"; @stathenry: 8.987_552_917_115_481_E11; "statH", "stathenry", "stathenries"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::electric_current as i; use crate::si::electric_potential as v; use crate::si::inductance as l; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: Inductance = ElectricPotential::new::(V::one()) * Time::new::(V::one()) / ElectricCurrent::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, U: v::Conversion, L: l::Conversion>() { Test::assert_approx_eq(&Inductance::new::(V::one()), &(ElectricPotential::new::(V::one()) * Time::new::(V::one()) / ElectricCurrent::new::(V::one()))); } } } } uom-0.35.0/src/si/information.rs000064400000000000000000000103021046102023000146020ustar 00000000000000//! Information (dimensionless quantity). quantity! { /// Information (dimensionless quantity). quantity: Information; "information"; /// Dimension of information, 1 (dimensionless). dimension: ISQ< Z0, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::InformationKind); units { // Base-2. @yobibit: prefix!(yobi) / 8.0; "Yib", "yobibit", "yobibits"; @yottabit: prefix!(yotta) / 8.0; "Yb", "yottabit", "yottabits"; @zebibit: prefix!(zebi) / 8.0; "Zib", "zebibit", "zebibits"; @zettabit: prefix!(zetta) / 8.0; "Zb", "zettabit", "zettabits"; @exbibit: prefix!(exbi) / 8.0; "Eib", "exbibit", "exbibits"; @exabit: prefix!(exa) / 8.0; "Eb", "exabit", "exabits"; @pebibit: prefix!(pebi) / 8.0; "Pib", "pebibit", "pebibits"; @petabit: prefix!(peta) / 8.0; "Pb", "petabit", "petabits"; @tebibit: prefix!(tebi) / 8.0; "Tib", "tibibit", "tibibits"; @terabit: prefix!(tera) / 8.0; "Tb", "terabit", "terabits"; @gibibit: prefix!(gibi) / 8.0; "Gib", "gibibit", "gibibits"; @gigabit: prefix!(giga) / 8.0; "Gb", "gigabit", "gigabits"; @mebibit: prefix!(mebi) / 8.0; "Mib", "mebibit", "mebibits"; @megabit: prefix!(mega) / 8.0; "Mb", "megabit", "megabits"; @kibibit: prefix!(kibi) / 8.0; "Kib", "kibibit", "kibibits"; @kilobit: prefix!(kilo) / 8.0; "kb", "kilobit", "kilobits"; /// The bit is the basic unit of information. /// /// Although the bit is the base unit of information `uom` treats it as a derived unit. The /// byte is treated as the base unit in order to provide more accurate conversion factors /// for byte derived units which are more commonly used than bits. @bit: prefix!(none) / 8.0; "b", "bit", "bits"; @yobibyte: prefix!(yobi); "YiB", "yobibyte", "yobibytes"; @yottabyte: prefix!(yotta); "YB", "yottabyte", "yottabytes"; @zebibyte: prefix!(zebi); "ZiB", "zebibyte", "zebibytes"; @zettabyte: prefix!(zetta); "ZB", "zettabyte", "zettabytes"; @exbibyte: prefix!(exbi); "EiB", "exbibyte", "exbibytes"; @exabyte: prefix!(exa); "EB", "exabyte", "exabytes"; @pebibyte: prefix!(pebi); "PiB", "pebibyte", "pebibytes"; @petabyte: prefix!(peta); "PB", "petabyte", "petabytes"; @tebibyte: prefix!(tebi); "TiB", "tibibyte", "tibibytes"; @terabyte: prefix!(tera); "TB", "terabyte", "terabytes"; @gibibyte: prefix!(gibi); "GiB", "gibibyte", "gibibytes"; @gigabyte: prefix!(giga); "GB", "gigabyte", "gigabytes"; @mebibyte: prefix!(mebi); "MiB", "mebibyte", "mebibytes"; @megabyte: prefix!(mega); "MB", "megabyte", "megabytes"; @kibibyte: prefix!(kibi); "KiB", "kibibyte", "kibibytes"; @kilobyte: prefix!(kilo); "kB", "kilobyte", "kilobytes"; /// The byte is a unit of information consisting of 8 bits. /// /// Although the bit is the base unit of information `uom` treats it as a derived unit. The /// byte is treated as the base unit in order to provide more accurate conversion factors /// for byte derived units which are more commonly used than bits. @byte: prefix!(none); "B", "byte", "bytes"; @octet: prefix!(none); "o", "octet", "octets"; @nibble: prefix!(none) / 2.0; "nibble", "nibble", "nibbles"; @crumb: prefix!(none) / 4.0; "crumb", "crumb", "crumbs"; @shannon: prefix!(none) / 8.0; "Sh", "shannon", "shannons"; // Base-e. ln(2). @natural_unit_of_information: 1.442_695_040_888_963_E0 * prefix!(none) / 8.0; "nat", "natural unit of uniformation", "natural units of information"; // Base-3. log2(3). @trit: 1.584_962_500_721_156_E0 * prefix!(none) / 8.0; "trit", "trit", "trits"; // Base-10. log2(10). @hartley: 3.321_928_094_887_363_E0 * prefix!(none) / 8.0; "Hart", "hartley", "hartleys"; @deciban: 3.321_928_094_887_363_E0 * prefix!(deci) / 8.0; "deciban", "deciban", "decibans"; } } uom-0.35.0/src/si/information_rate.rs000064400000000000000000000166631046102023000156350ustar 00000000000000//! Information rate (base unit byte per second, s⁻¹). quantity! { /// Information rate (base unit byte per second, s⁻¹). quantity: InformationRate; "information rate"; /// Dimension of information rate, T⁻¹ (base unit byte per second, s⁻¹). dimension: ISQ< Z0, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::InformationKind); units { @yobibit_per_second: prefix!(yobi) * prefix!(none) / 8.0; "Yib/s", "yobibit per second", "yobibits per second"; @yottabit_per_second: prefix!(yotta) * prefix!(none) / 8.0; "Yb/s", "yottabit per second", "yottabits per second"; @zebibit_per_second: prefix!(zebi) * prefix!(none) / 8.0; "Zib/s", "zebibit per second", "zebibits per second"; @zettabit_per_second: prefix!(zetta) * prefix!(none) / 8.0; "Zb/s", "zettabit per second", "zettabits per second"; @exbibit_per_second: prefix!(exbi) * prefix!(none) / 8.0; "Eib/s", "exbibit per second", "exbibits per second"; @exabit_per_second: prefix!(exa) * prefix!(none) / 8.0; "Eb/s", "exabit per second", "exabits per second"; @pebibit_per_second: prefix!(pebi) * prefix!(none) / 8.0; "Pib/s", "pebibit per second", "pebibits per second"; @petabit_per_second: prefix!(peta) * prefix!(none) / 8.0; "Pb/s", "petabit per second", "petabits per second"; @tebibit_per_second: prefix!(tebi) * prefix!(none) / 8.0; "Tib/s", "tebibit per second", "tebibits per second"; @terabit_per_second: prefix!(tera) * prefix!(none) / 8.0; "Tb/s", "terabit per second", "terabits per second"; @gibibit_per_second: prefix!(gibi) * prefix!(none) / 8.0; "Gib/s", "gibibit per second", "gibibits per second"; @gigabit_per_second: prefix!(giga) * prefix!(none) / 8.0; "Gb/s", "gigabit per second", "gigabits per second"; @mebibit_per_second: prefix!(mebi) * prefix!(none) / 8.0; "Mib/s", "mebibit per second", "mebibits per second"; @megabit_per_second: prefix!(mega) * prefix!(none) / 8.0; "Mb/s", "megabit per second", "megabits per second"; @kibibit_per_second: prefix!(kibi) * prefix!(none) / 8.0; "Kib/s", "kibibit per second", "kibibits per second"; @kilobit_per_second: prefix!(kilo) * prefix!(none) / 8.0; "kb/s", "kilobit per second", "kilobits per second"; @bit_per_second: prefix!(none) / 8.0; "b/s", "bit per second", "bits per second"; @yobibyte_per_second: prefix!(yobi); "YiB/s", "yobibyte per second", "yobibytes per second"; @yottabyte_per_second: prefix!(yotta); "YB/s", "yottabyte per second", "yottabytes per second"; @zebibyte_per_second: prefix!(zebi); "ZiB/s", "zebibyte per second", "zebibytes per second"; @zettabyte_per_second: prefix!(zetta); "ZB/s", "zettabyte per second", "zettabytes per second"; @exbibyte_per_second: prefix!(exbi); "EiB/s", "exbibyte per second", "exbibytes per second"; @exabyte_per_second: prefix!(exa); "EB/s", "exabyte per second", "exabytes per second"; @pebibyte_per_second: prefix!(pebi); "PiB/s", "pebibyte per second", "pebibytes per second"; @petabyte_per_second: prefix!(peta); "PB/s", "petabyte per second", "petabytes per second"; @tebibyte_per_second: prefix!(tebi); "TiB/s", "tebibyte per second", "tebibytes per second"; @terabyte_per_second: prefix!(tera); "TB/s", "terabyte per second", "terabytes per second"; @gibibyte_per_second: prefix!(gibi); "GiB/s", "gibibyte per second", "gibibytes per second"; @gigabyte_per_second: prefix!(giga); "GB/s", "gigabyte per second", "gigabytes per second"; @mebibyte_per_second: prefix!(mebi); "MiB/s", "mebibyte per second", "mebibytes per second"; @megabyte_per_second: prefix!(mega); "MB/s", "megabyte per second", "megabytes per second"; @kibibyte_per_second: prefix!(kibi); "KiB/s", "kibibyte per second", "kibibytes per second"; @kilobyte_per_second: prefix!(kilo); "kB/s", "kilobyte per second", "kilobytes per second"; @byte_per_second: prefix!(none); "B/s", "byte per second", "bytes per second"; @octet_per_second: prefix!(none); "o/s", "octet per second", "octets per second"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::information as i; use crate::si::information_rate as r; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, R: r::Conversion>() { Test::assert_approx_eq(&InformationRate::new::(V::one()), &(Information::new::(V::one()) / Time::new::(V::one())).into()); } } } } uom-0.35.0/src/si/inverse_velocity.rs000064400000000000000000000144721046102023000156620ustar 00000000000000//! Inverse velocity (base unit second per meter, s · m⁻¹). quantity! { /// Inverse velocity (base unit second per meter, s · m⁻¹). quantity: InverseVelocity; "inverse velocity"; /// Dimension of inverse velocity, TL⁻¹ (base unit second per meter, s · m⁻¹). dimension: ISQ< N1, // length Z0, // mass P1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottasecond_per_meter: prefix!(yotta); "Ym/s", "yottasecond per meter", "yottaseconds per meter"; @zettasecond_per_meter: prefix!(zetta); "Zm/s", "zettasecond per meter", "zettaseconds per meter"; @exasecond_per_meter: prefix!(exa); "Em/s", "exasecond per meter", "exaseconds per meter"; @petasecond_per_meter: prefix!(peta); "Pm/s", "petasecond per meter", "petaseconds per meter"; @terasecond_per_meter: prefix!(tera); "Tm/s", "terasecond per meter", "teraseconds per meter"; @gigasecond_per_meter: prefix!(giga); "Gm/s", "gigasecond per meter", "gigaseconds per meter"; @megasecond_per_meter: prefix!(mega); "Mm/s", "megasecond per meter", "megaseconds per meter"; @kilosecond_per_meter: prefix!(kilo); "km/s", "kilosecond per meter", "kiloseconds per meter"; @hectosecond_per_meter: prefix!(hecto); "hm/s", "hectosecond per meter", "hectoseconds per meter"; @decasecond_per_meter: prefix!(deca); "dam/s", "decasecond per meter", "decaseconds per meter"; @second_per_meter: prefix!(none); "m/s", "second per meter", "seconds per meter"; @decisecond_per_meter: prefix!(deci); "dm/s", "decisecond per meter", "deciseconds per meter"; @centisecond_per_meter: prefix!(centi); "cm/s", "centisecond per meter", "centiseconds per meter"; @millisecond_per_meter: prefix!(milli); "mm/s", "millisecond per meter", "milliseconds per meter"; @microsecond_per_meter: prefix!(micro); "µm/s", "microsecond per meter", "microseconds per meter"; @nanosecond_per_meter: prefix!(nano); "nm/s", "nanosecond per meter", "nanoseconds per meter"; @picosecond_per_meter: prefix!(pico); "pm/s", "picosecond per meter", "picoseconds per meter"; @femtosecond_per_meter: prefix!(femto); "fm/s", "femtosecond per meter", "femtoseconds per meter"; @attosecond_per_meter: prefix!(atto); "am/s", "attosecond per meter", "attoseconds per meter"; @zeptosecond_per_meter: prefix!(zepto); "zm/s", "zeptosecond per meter", "zeptoseconds per meter"; @yoctosecond_per_meter: prefix!(yocto); "ym/s", "yoctosecond per meter", "yoctoseconds per meter"; @hour_per_foot: 1.181_102_362_204_724_3_E4; "h/ft", "hour per foot", "hours per foot"; @minute_per_foot: 1.968_503_937_007_873_8_E2; "min/ft", "minute per foot", "minutes per foot"; @second_per_foot: 3.280_839_895_013_123; "s/ft", "second per foot", "seconds per foot"; @second_per_inch: 3.937_007_874_015_748_E1; "s/in", "second per inch", "seconds per inch"; @hour_per_kilometer: 3.6; "h/km", "hour per kilometer", "hours per kilometer"; @hour_per_mile: 2.236_936_292_054_402; "h/mi", "hour per mile", "hours per mile"; @minute_per_mile: 3.728_227_153_E-2; "min/mi", "minute per mile", "minutes per mile"; @second_per_mile: 6.213_711_922_373_339_E-4; "s/mi", "second per mile", "seconds per mile"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::length as l; use crate::si::quantities::*; use crate::si::time as t; use crate::si::inverse_velocity as v; use crate::tests::Test; #[test] fn check_dimension() { let _: InverseVelocity = Time::new::(V::one()) / Length::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, E: v::Conversion>() { Test::assert_eq(&InverseVelocity::new::(V::one()), &(Time::new::(V::one()) / Length::new::(V::one()))); } } } } uom-0.35.0/src/si/jerk.rs000064400000000000000000000147231046102023000132230ustar 00000000000000//! Jerk (base unit meter per second cubed, m · s⁻³). quantity! { /// Jerk (base unit meter per second cubed, m · s⁻³). quantity: Jerk; "jerk"; /// Dimension of jerk, LT⁻³ (base unit meter per second cubed, m · s⁻³). dimension: ISQ< P1, // length Z0, // mass N3, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottameter_per_second_cubed: prefix!(yotta); "Ym/s³", "yottameter per second cubed", "yottameters per second cubed"; @zettameter_per_second_cubed: prefix!(zetta); "Zm/s³", "zettameter per second cubed", "zettameters per second cubed"; @exameter_per_second_cubed: prefix!(exa); "Em/s³", "exameter per second cubed", "exameters per second cubed"; @petameter_per_second_cubed: prefix!(peta); "Pm/s³", "petameter per second cubed", "petameters per second cubed"; @terameter_per_second_cubed: prefix!(tera); "Tm/s³", "terameter per second cubed", "terameters per second cubed"; @gigameter_per_second_cubed: prefix!(giga); "Gm/s³", "gigameter per second cubed", "gigameters per second cubed"; @megameter_per_second_cubed: prefix!(mega); "Mm/s³", "megameter per second cubed", "megameters per second cubed"; @kilometer_per_second_cubed: prefix!(kilo); "km/s³", "kilometer per second cubed", "kilometers per second cubed"; @hectometer_per_second_cubed: prefix!(hecto); "hm/s³", "hectometer per second cubed", "hectometers per second cubed"; @decameter_per_second_cubed: prefix!(deca); "dam/s³", "decameter per second cubed", "decameters per second cubed"; @meter_per_second_cubed: prefix!(none); "m/s³", "meter per second cubed", "meters per second cubed"; @decimeter_per_second_cubed: prefix!(deci); "dm/s³", "decimeter per second cubed", "decimeters per second cubed"; @centimeter_per_second_cubed: prefix!(centi); "cm/s³", "centimeter per second cubed", "centimeters per second cubed"; @millimeter_per_second_cubed: prefix!(milli); "mm/s³", "millimeter per second cubed", "millimeters per second cubed"; @micrometer_per_second_cubed: prefix!(micro); "µm/s³", "micrometer per second cubed", "micrometers per second cubed"; @nanometer_per_second_cubed: prefix!(nano); "nm/s³", "nanometer per second cubed", "nanometers per second cubed"; @picometer_per_second_cubed: prefix!(pico); "pm/s³", "picometer per second cubed", "picometers per second cubed"; @femtometer_per_second_cubed: prefix!(femto); "fm/s³", "femtometer per second cubed", "femtometers per second cubed"; @attometer_per_second_cubed: prefix!(atto); "am/s³", "attometer per second cubed", "attometers per second cubed"; @zeptometer_per_second_cubed: prefix!(zepto); "zm/s³", "zeptometer per second cubed", "zeptometers per second cubed"; @yoctometer_per_second_cubed: prefix!(yocto); "ym/s³", "yoctometer per second cubed", "yoctometers per second cubed"; @foot_per_second_cubed: 3.048_E-1; "ft/s³", "foot per second cubed", "feet per second cubed"; @inch_per_second_cubed: 2.54_E-2; "in/s³", "inch per second cubed", "inches per second cubed"; @kilometer_per_minute_cubed: 4.629_629_629_629_629_E-3; "km/min³", "kilometer per minute cubed", "kilometers per minute cubed"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::jerk as j; use crate::si::length as l; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: Jerk = Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * Time::new::(V::one())); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, J: j::Conversion>() { Test::assert_eq( &Jerk::new::(V::one()), &(Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * Time::new::(V::one())))); } } } } uom-0.35.0/src/si/length.rs000064400000000000000000000076761046102023000135620ustar 00000000000000//! Length (base unit meter, m). quantity! { /// Length (base unit meter, m). quantity: Length; "length"; /// Dimension of length, L (base unit meter, m). dimension: ISQ< P1, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottameter: prefix!(yotta); "Ym", "yottameter", "yottameters"; @zettameter: prefix!(zetta); "Zm", "zettameter", "zettameters"; @exameter: prefix!(exa); "Em", "exameter", "exameters"; @petameter: prefix!(peta); "Pm", "petameter", "petameters"; @terameter: prefix!(tera); "Tm", "terameter", "terameters"; @gigameter: prefix!(giga); "Gm", "gigameter", "gigameters"; @megameter: prefix!(mega); "Mm", "megameter", "megameters"; @kilometer: prefix!(kilo); "km", "kilometer", "kilometers"; @hectometer: prefix!(hecto); "hm", "hectometer", "hectometers"; @decameter: prefix!(deca); "dam", "decameter", "decameters"; /// The meter is the SI unit of length. It is defined by taking the fixed numerical value /// of the speed of light in vacuum *c* to be 299 792 458 when expressed in the unit m s⁻¹, /// where the second is defined in terms of the caesium frequency ∆*ν*Cs. @meter: prefix!(none); "m", "meter", "meters"; @decimeter: prefix!(deci); "dm", "decimeter", "decimeters"; @centimeter: prefix!(centi); "cm", "centimeter", "centimeters"; @millimeter: prefix!(milli); "mm", "millimeter", "millimeters"; @micrometer: prefix!(micro); "µm", "micrometer", "micrometers"; @nanometer: prefix!(nano); "nm", "nanometer", "nanometers"; @picometer: prefix!(pico); "pm", "picometer", "picometers"; @femtometer: prefix!(femto); "fm", "femtometer", "femtometers"; @attometer: prefix!(atto); "am", "attometer", "attometers"; @zeptometer: prefix!(zepto); "zm", "zeptometer", "zeptometers"; @yoctometer: prefix!(yocto); "ym", "yoctometer", "yoctometers"; @angstrom: 1.0_E-10; "Å", "ångström", "ångströms"; @bohr_radius: 5.291_772_109_03_E-11; "a₀", "bohr radius", "bohr radiuses"; /// Atomic unit of length (Bohr radius). @atomic_unit_of_length: 5.291_772_109_03_E-11; "a.u. of length", "atomic unit of length", "atomic units of length"; @astronomical_unit: 1.495_979_E11; "ua", "astronomical unit", "astronomical units"; @chain: 2.011_684_E1; "ch", "chain", "chains"; @fathom: 1.828_804_E0; "fathom", "fathom", "fathoms"; @fermi: 1.0_E-15; "fermi", "fermi", "fermis"; @foot: 3.048_E-1; "ft", "foot", "feet"; @foot_survey: 3.048_006_E-1; "ft (U.S. survey)", "foot (U.S. survey)", "feet (U.S. survey)"; @inch: 2.54_E-2; "in", "inch", "inches"; @light_year: 9.460_73_E15; "l. y.", "light year", "light years"; @microinch: 2.54_E-8; "μin", "microinch", "microinches"; @micron: 1.0_E-6; "μ", "micron", "microns"; @mil: 2.54_E-5; "0.001 in", "mil", "mils"; @mile: 1.609_344_E3; "mi", "mile", "miles"; @mile_survey: 1.609_347_E3; "mi (U.S. survey)", "mile (U.S. survey)", "miles (U.S. survey)"; @nautical_mile: 1.852_E3; "M", "nautical mile", "nautical miles"; @parsec: 3.085_678_E16; "pc", "parsec", "parsecs"; @pica_computer: 4.233_333_333_333_333_E-3; "1/6 in (computer)", "pica (computer)", "picas (computer)"; @pica_printers: 4.217_518_E-3; "1/6 in", "pica (printer's)", "picas (printer's)"; @point_computer: 3.527_778_E-4; "1/72 in (computer)", "point (computer)", "points (computer)"; @point_printers: 3.514_598_E-4; "1/72 in", "point (printer's)", "points (printer's)"; @rod: 5.029_21_E0; "rd", "rod", "rods"; @yard: 9.144_E-1; "yd", "yard", "yards"; } } uom-0.35.0/src/si/linear_density_of_states.rs000064400000000000000000000044651046102023000173520ustar 00000000000000//! Linear density of states (base unit 1 / meter joule, kg⁻¹ · m⁻³ · s²). quantity! { /// Linear density of states (base unit 1 / meter joule, kg⁻¹ · m⁻³ · s²). quantity: LinearDensityOfStates; "linear density of states"; /// Dimension of linear density of states, L⁻³M⁻¹T² (base unit 1 / meter joule, /// kg⁻¹ · m⁻³ · s²). dimension: ISQ< N3, // length N1, // mass P2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @state_per_meter_joule: prefix!(none); "1/(m · J)", "state per meter joule", "states per meter joule"; @state_per_centimeter_joule: prefix!(none) / prefix!(centi); "1/(cm · J)", "state per centimeter joule", "states per centimeter joule"; @state_per_centimeter_electronvolt: prefix!(none) / prefix!(centi) / 1.602_176_634_E-19; "1/(cm · eV)", "state per centimeter electronvolt", "states per centimeter electronvolt"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::linear_density_of_states as ldos; use crate::si::energy as e; use crate::si::quantities::*; use crate::si::length as l; use crate::tests::Test; #[test] fn check_dimension() { let _: LinearDensityOfStates = (V::one() / Energy::new::(V::one()) / Length::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); fn test, E: e::Conversion, LDOS: ldos::Conversion>() { Test::assert_approx_eq(&LinearDensityOfStates::new::(V::one()), &(V::one() / Energy::new::(V::one()) / Length::new::(V::one())).into()); } } } } uom-0.35.0/src/si/linear_mass_density.rs000064400000000000000000000052201046102023000163140ustar 00000000000000//! Linear mass density (base unit kilogram per meter, m⁻¹ · kg). quantity! { /// Linear mass density (base unit kilogram per meter, m⁻¹ · kg). quantity: LinearMassDensity; "linear mass density"; /// Dimension of linear mass density, L⁻¹M (base unit kilogram per meter, m⁻¹ · kg). dimension: ISQ< N1, // length P1, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @kilogram_per_meter: prefix!(none); "kg/m", "kilogram per meter", "kilograms per meter"; @gram_per_kilometer: prefix!(milli) / prefix!(kilo); "g/km", "gram per kilometer", "grams per kilometer"; @gram_per_centimeter: prefix!(milli) / prefix!(centi); "g/cm", "gram per centimeter", "grams per centimeter"; @ounce_per_foot: 2.834_952_E-2 / 3.048_E-1; "oz/ft", "ounce per foot", "ounces per foot"; @ounce_per_inch: 2.834_952_E-2 / 2.54_E-2; "oz/in", "ounce per inch", "ounces per inch"; @pound_per_yard: 4.535_924_E-1 / 9.144_E-1; "lb/yd", "pound per yard", "pounds per yard"; @pound_per_foot: 4.535_924_E-1 / 3.048_E-1; "lb/ft", "pound per foot", "pounds per foot"; @pound_per_inch: 4.535_924_E-1 / 2.54_E-2; "lb/in", "pound per inch", "pounds per inch"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::mass as m; use crate::si::linear_mass_density as d; use crate::si::quantities::*; use crate::si::length as l; use crate::tests::Test; #[test] fn check_dimension() { let _: LinearMassDensity = Mass::new::(V::one()) / Length::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, L: l::Conversion, D: d::Conversion>() { Test::assert_approx_eq(&LinearMassDensity::new::(V::one()), &(Mass::new::(V::one()) / Length::new::(V::one()))); } } } } uom-0.35.0/src/si/linear_number_density.rs000064400000000000000000000053371046102023000166520ustar 00000000000000//! Linear number density (base unit 1 per meter, m⁻¹). quantity! { /// Linear number density (base unit 1 per meter, m⁻¹). quantity: LinearNumberDensity; "linear number density"; /// Dimension of linear number density, L⁻¹ (base 1 unit per meter, m⁻¹). dimension: ISQ< N1, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @per_kilometer: prefix!(none) / prefix!(kilo); "km⁻¹", "per kilometer", "per kilometer"; @per_meter: prefix!(none); "m⁻¹", "per meter", "per meter"; @per_decimeter: prefix!(none) / prefix!(deci); "dm⁻¹", "per decimeter", "per decimeter"; @per_centimeter: prefix!(none) / prefix!(centi); "cm⁻¹", "per centimeter", "per centimeter"; @per_millimeter: prefix!(none) / prefix!(milli); "mm⁻¹", "per millimeter", "per millimeter"; @per_foot: prefix!(none) / 3.048_E-1; "ft⁻¹", "per foot", "per foot"; @per_foot_survey: prefix!(none) / 3.048_006_E-1; "ft (U.S. survey)", "foot (U.S. survey)", "foot (U.S. survey)"; @per_inch: prefix!(none) / 2.54_E-2; "in⁻¹", "per inch", "per inch"; @per_mile: prefix!(none) / 1.609_344_E3; "mi⁻¹", "per mile", "per mile"; @per_mile_survey: prefix!(none) / 1.609_347_E3; "mi⁻¹ (U.S. survey)", "per mile (U.S. survey)", "per mile (U.S. survey)"; @per_nautical_mile: prefix!(none) / 1.852_E3; "M⁻¹", "per nautical mile", "per nautical mile"; @per_yard: prefix!(none) / 9.144_E-1; "yd⁻¹", "per yard", "per yard"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::length as l; use crate::si::linear_number_density as n; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: LinearNumberDensity = (V::one() / Length::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); fn test, L: l::Conversion>() { Test::assert_approx_eq(&LinearNumberDensity::new::(V::one()), &(V::one() / Length::new::(V::one())).into()); } } } } uom-0.35.0/src/si/linear_number_rate.rs000064400000000000000000000070611046102023000161220ustar 00000000000000//! Linear number rate (base unit 1 per meter second, m⁻¹ · s⁻¹). quantity! { /// Linear number rate (base unit 1 per meter second, m⁻¹ · s⁻¹). quantity: LinearNumberRate; "linear number rate"; /// Dimension of linear number rate, L⁻¹T⁻¹ (base unit 1 per meter second, m⁻¹ · s⁻¹). dimension: ISQ< N1, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @per_kilometer_second: prefix!(none) / prefix!(kilo); "km⁻¹ · s⁻¹", "per kilometer second", "per kilometer second"; @per_meter_second: prefix!(none); "m⁻¹ · s⁻¹", "per meter second", "per meter second"; @per_centimeter_second: prefix!(none) / prefix!(centi); "cm⁻¹ · s⁻¹", "per centimeter second", "per centimeter second"; @per_millimeter_second: prefix!(none) / prefix!(milli); "mm⁻¹ · s⁻¹", "per millimeter second", "per millimeter second"; @per_foot_second: prefix!(none) / 3.048_E-1; "ft⁻¹ · s⁻¹", "per foot second", "per foot second"; @per_foot_survey_second: prefix!(none) / 3.048_006_E-1; "ft⁻¹ (U.S. survey) · s⁻¹", "per foot (U.S. survey) second", "per foot (U.S. survey) second"; @per_inch_second: prefix!(none) / 2.54_E-2; "in⁻¹ · s⁻¹", "per inch second", "per inch second"; @per_mile_second: prefix!(none) / 1.609_344_E3; "mi⁻¹ · s⁻¹", "per mile second", "per mile second"; @per_mile_survey_second: prefix!(none) / 1.609_347_E3; "mi⁻¹ (U.S. survey) · s⁻¹", "per mile (U.S. survey) second", "per mile (U.S. survey) second"; @per_yard_second: prefix!(none) / 9.144_E-1; "yd⁻¹ · s⁻¹", "per yard second", "per yard second"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::linear_number_rate as lnr; use crate::si::quantities::*; use crate::si::time as t; use crate::si::length as l; use crate::tests::Test; #[test] fn check_dimension() { let _: LinearNumberRate = (V::one() / Time::new::(V::one()) / Length::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, L: l::Conversion, T: t::Conversion>() { Test::assert_approx_eq(&LinearNumberRate::new::(V::one()), &(V::one() / Time::new::(V::one()) / Length::new::(V::one())).into()); } } } } uom-0.35.0/src/si/linear_power_density.rs000064400000000000000000000036041046102023000165110ustar 00000000000000//! Linear power density (base unit watt per meter, m · kg · s⁻³). quantity! { /// Linear power density (base unit watt per meter, m · kg · s⁻³). quantity: LinearPowerDensity; "linear power density"; /// Dimension of linear power density, LMT⁻³ (base unit watt per meter, m · kg · s⁻³). dimension: ISQ< P1, // length P1, // mass N3, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @watt_per_meter: prefix!(none); "W/m", "watt per meter", "watts per meter"; @watt_per_centimeter: prefix!(none) / prefix!(centi); "W/cm", "watt per centimeter", "watts per centimeter"; @watt_per_millimeter: prefix!(none) / prefix!(milli); "W/mm", "watt per millimeter", "watts per millimeter"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::power as p; use crate::si::quantities::*; use crate::si::linear_power_density as lpd; use crate::si::length as l; use crate::tests::Test; #[test] fn check_dimension() { let _: LinearPowerDensity = Power::new::(V::one()) / Length::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); fn test, L: l::Conversion, LPD: lpd::Conversion>() { Test::assert_approx_eq(&LinearPowerDensity::new::(V::one()), &(Power::new::

(V::one()) / Length::new::(V::one()))); } } } } uom-0.35.0/src/si/luminance.rs000064400000000000000000000214111046102023000142330ustar 00000000000000//! Luminance (base unit candela per square meter, cd · m⁻²). quantity! { /// Luminance (base unit candela per square meter, cd · m⁻²). quantity: Luminance; "luminance"; /// Dimension of luminance, L⁻²J (base unit candela per square meter, cd · m⁻²). dimension: ISQ< N2, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance P1>; // luminous intensity units { @yottacandela_per_square_meter: prefix!(yotta); "Ycd/m²", "yottacandela per square meter", "yottacandelas per square meter"; @zettacandela_per_square_meter: prefix!(zetta); "Zcd/m²", "zettacandela per square meter", "zettacandelas per square meter"; @exacandela_per_square_meter: prefix!(exa); "Ecd/m²", "exacandela per square meter", "exacandelas per square meter"; @petacandela_per_square_meter: prefix!(peta); "Pcd/m²", "petacandela per square meter", "petacandelas per square meter"; @teracandela_per_square_meter: prefix!(tera); "Tcd/m²", "teracandela per square meter", "teracandelas per square meter"; @gigacandela_per_square_meter: prefix!(giga); "Gcd/m²", "gigacandela per square meter", "gigacandelas per square meter"; @megacandela_per_square_meter: prefix!(mega); "Mcd/m²", "megacandela per square meter", "megacandelas per square meter"; @kilocandela_per_square_meter: prefix!(kilo); "kcd/m²", "kilocandela per square meter", "kilocandelas per square meter"; @hectocandela_per_square_meter: prefix!(hecto); "hcd/m²", "hectocandela per square meter", "hectocandelas per square meter"; @decacandela_per_square_meter: prefix!(deca); "dacd/m²", "decacandela per square meter", "decacandelas per square meter"; /// Derived unit of luminance. @candela_per_square_meter: prefix!(none); "cd/m²", "candela per square meter", "candelas per square meter"; @decicandela_per_square_meter: prefix!(deci); "dcd/m²", "decicandela per square meter", "decicandelas per square meter"; @centicandela_per_square_meter: prefix!(centi); "ccd/m²", "centicandela per square meter", "centicandelas per square meter"; @millicandela_per_square_meter: prefix!(milli); "mcd/m²", "millicandela per square meter", "millicandelas per square meter"; @microcandela_per_square_meter: prefix!(micro); "µcd/m²", "microcandela per square meter", "microcandelas per square meter"; @nanocandela_per_square_meter: prefix!(nano); "ncd/m²", "nanocandela per square meter", "nanocandelas per square meter"; @picocandela_per_square_meter: prefix!(pico); "pcd/m²", "picocandela per square meter", "picocandelas per square meter"; @femtocandela_per_square_meter: prefix!(femto); "fcd/m²", "femtocandela per square meter", "femtocandelas per square meter"; @attocandela_per_square_meter: prefix!(atto); "acd/m²", "attocandela per square meter", "attocandelas per square meter"; @zeptocandela_per_square_meter: prefix!(zepto); "zcd/m²", "zeptocandela per square meter", "zeptocandelas per square meter"; @yoctocandela_per_square_meter: prefix!(yocto); "ycd/m²", "yoctocandela per square meter", "yoctocandelas per square meter"; @candela_per_square_picometer: prefix!(yotta); "cd/pm²", "candela per square picometer", "candelas per square picometer"; @candela_per_square_nanometer: prefix!(exa); "cd/nm²", "candela per square nanometer", "candelas per square nanometer"; @candela_per_square_micrometer: prefix!(tera); "cd/µm²", "candela per square micrometer", "candelas per square micrometer"; @candela_per_square_millimeter: prefix!(mega); "cd/mm²", "candela per square millimeter", "candelas per square millimeter"; @candela_per_square_centimeter: 1.0_E4; "cd/cm²", "candela per square centimeter", "candelas per square centimeter"; @candela_per_square_kilometer: prefix!(micro); "cd/km²", "candela per square kilometer", "candelas per square kilometer"; @candela_per_square_megameter: prefix!(pico); "cd/Mm²", "candela per square megameter", "candelas per square megameter"; @candela_per_square_gigameter: prefix!(atto); "cd/Gm²", "candela per square gigameter", "candelas per square gigameter"; @candela_per_square_terameter: prefix!(yocto); "cd/Tm²", "candela per square terameter", "candelas per square terameter"; @candela_per_square_inch: 1.550_003_100_006_200_2_E3; "cd/in²", "candela per square inch", "candelas per square inch"; @candela_per_square_foot: 1.076_391_041_670_972_2_E1; "cd/ft²", "candela per square foot", "candelas per square foot"; @footlambert: 3.426_259_099_635_390_5_E0; "fl", "footlambert", "footlamberts"; @lambert: 3.183_098_861_837_906_7_E3; "la", "lambert", "lamberts"; @stilb: 1.0_E4; "sb", "stilb", "stilbs"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::area as a; use crate::si::luminance as l; use crate::si::luminous_intensity as i; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: Luminance = LuminousIntensity::new::(V::one()) / Area::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, A: a::Conversion, L: l::Conversion>() { Test::assert_approx_eq(&Luminance::new::(V::one()), &(LuminousIntensity::new::(V::one()) / Area::new::(V::one()))); } } } } uom-0.35.0/src/si/luminous_intensity.rs000064400000000000000000000050401046102023000162410ustar 00000000000000//! Luminous intensity (base unit candela, cd). quantity! { /// Luminous intensity (base unit candela, cd). quantity: LuminousIntensity; "luminous intensity"; /// Dimension of luminous intensity, J (base unit candela, cd). dimension: ISQ< Z0, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance P1>; // luminous intensity units { @yottacandela: prefix!(yotta); "Ycd", "yottacandela", "yottacandelas"; @zettacandela: prefix!(zetta); "Zcd", "zettacandela", "zettacandelas"; @exacandela: prefix!(exa); "Ecd", "exacandela", "exacandelas"; @petacandela: prefix!(peta); "Pcd", "petacandela", "petacandelas"; @teracandela: prefix!(tera); "Tcd", "teracandela", "teracandelas"; @gigacandela: prefix!(giga); "Gcd", "gigacandela", "gigacandelas"; @megacandela: prefix!(mega); "Mcd", "megacandela", "megacandelas"; @kilocandela: prefix!(kilo); "kcd", "kilocandela", "kilocandelas"; @hectocandela: prefix!(hecto); "hcd", "hectocandela", "hectocandelas"; @decacandela: prefix!(deca); "dacd", "decacandela", "decacandelas"; /// The candela is the SI unit of luminous intensity in a given direction. It is defined by /// taking the fixed numerical value of the luminous efficacy of monochromatic radiation of /// frequency 540 × 10¹² Hz, *K*cd, to be 683 when expressed in the unit lm W⁻¹, /// which is equal to cd sr W⁻¹, or cd sr kg⁻¹ m⁻² s³, where the kilogram, meter, and second /// are defined in terms of *h*, *c* and ∆*ν*Cs. @candela: prefix!(none); "cd", "candela", "candelas"; @decicandela: prefix!(deci); "dcd", "decicandela", "decicandelas"; @centicandela: prefix!(centi); "ccd", "centicandela", "centicandelas"; @millicandela: prefix!(milli); "mcd", "millicandela", "millicandelas"; @microcandela: prefix!(micro); "µcd", "microcandela", "microcandelas"; @nanocandela: prefix!(nano); "ncd", "nanocandela", "nanocandelas"; @picocandela: prefix!(pico); "pcd", "picocandela", "picocandelas"; @femtocandela: prefix!(femto); "fcd", "femtocandela", "femtocandelas"; @attocandela: prefix!(atto); "acd", "attocandela", "attocandelas"; @zeptocandela: prefix!(zepto); "zcd", "zeptocandela", "zeptocandelas"; @yoctocandela: prefix!(yocto); "ycd", "yoctocandela", "yoctocandelas"; } } uom-0.35.0/src/si/magnetic_field_strength.rs000064400000000000000000000044471046102023000171420ustar 00000000000000//! Magnetic field strength (H field) (base unit ampere per meter, m⁻¹ · A). quantity! { /// Magnetic field strength (H field) (base unit ampere per meter, m⁻¹ · A). quantity: MagneticFieldStrength; "magnetic field strength (H field)"; /// Dimension of magnetic field strength (H field), L⁻¹I (base unit ampere per meter, m⁻¹ · A). dimension: ISQ< N1, // length Z0, // mass Z0, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @ampere_per_meter: prefix!(none); "A/m", "ampere per meter", "amperes per meter"; @ampere_per_centimeter: prefix!(none) / prefix!(centi); "A/cm", "ampere per centimeter", "amperes per centimeter"; @ampere_per_millimeter: prefix!(none) / prefix!(milli); "A/mm", "ampere per millimeter", "amperes per millimeter"; @ampere_per_micrometer: prefix!(none) / prefix!(micro); "A/μm", "ampere per micrometer", "amperes per micrometer"; /// 1 oersted = 1000/(4π) A/m @oersted: 79.577_471_545_947_67; "Oe", "oersted", "oersteds"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::length as l; use crate::si::electric_current as i; use crate::si::magnetic_field_strength as h; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: MagneticFieldStrength = ElectricCurrent::new::(V::one()) / Length::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); fn test, L: l::Conversion, H: h::Conversion>() { Test::assert_approx_eq(&MagneticFieldStrength::new::(V::one()), &(ElectricCurrent::new::(V::one()) / Length::new::(V::one()))); } } } } uom-0.35.0/src/si/magnetic_flux.rs000064400000000000000000000076151046102023000151170ustar 00000000000000//! Magnetic flux (base unit weber, m² · kg · s⁻² · A⁻¹). quantity! { /// Magnetic flux (base unit weber, m² · kg · s⁻² · A⁻¹). quantity: MagneticFlux; "magnetic flux"; /// Dimension of magnetic flux, L²MT⁻²I⁻¹ (base unit weber, m² · kg · s⁻² · A⁻¹). dimension: ISQ< P2, // length P1, // mass N2, // time N1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottaweber: prefix!(yotta); "YWb", "yottaweber", "yottawebers"; @zettaweber: prefix!(zetta); "ZWb", "zettaweber", "zettawebers"; @exaweber: prefix!(exa); "EWb", "exaweber", "exawebers"; @petaweber: prefix!(peta); "PWb", "petaweber", "petawebers"; @teraweber: prefix!(tera); "TWb", "teraweber", "terawebers"; @gigaweber: prefix!(giga); "GWb", "gigaweber", "gigawebers"; @megaweber: prefix!(mega); "MWb", "megaweber", "megawebers"; @kiloweber: prefix!(kilo); "kWb", "kiloweber", "kilowebers"; @hectoweber: prefix!(hecto); "hWb", "hectoweber", "hectowebers"; @decaweber: prefix!(deca); "daWb", "decaweber", "decawebers"; /// Derived unit of magnetic flux. @weber: prefix!(none); "Wb", "weber", "webers"; @deciweber: prefix!(deci); "dWb", "deciweber", "deciwebers"; @centiweber: prefix!(centi); "cWb", "centiweber", "centiwebers"; @milliweber: prefix!(milli); "mWb", "milliweber", "milliwebers"; @microweber: prefix!(micro); "µWb", "microweber", "microwebers"; @nanoweber: prefix!(nano); "nWb", "nanoweber", "nanowebers"; @picoweber: prefix!(pico); "pWb", "picoweber", "picowebers"; @femtoweber: prefix!(femto); "fWb", "femtoweber", "femtowebers"; @attoweber: prefix!(atto); "aWb", "attoweber", "attowebers"; @zeptoweber: prefix!(zepto); "zWb", "zeptoweber", "zeptowebers"; @yoctoweber: prefix!(yocto); "yWb", "yoctoweber", "yoctowebers"; @maxwell: 1.0_E-8; "Mx", "maxwell", "maxwells"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::electric_potential as v; use crate::si::magnetic_flux as f; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: MagneticFlux = ElectricPotential::new::(V::one()) * Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, F: f::Conversion>() { Test::assert_approx_eq(&MagneticFlux::new::(V::one()), &(ElectricPotential::new::(V::one()) * Time::new::(V::one()))); } } } } uom-0.35.0/src/si/magnetic_flux_density.rs000064400000000000000000000100211046102023000166370ustar 00000000000000//! Magnetic flux density (base unit tesla, kg · s⁻² · A⁻¹). quantity! { /// Magnetic flux density (base unit tesla, kg · s⁻² · A⁻¹). quantity: MagneticFluxDensity; "magnetic flux density"; /// Dimension of magnetic flux density, MT⁻²I⁻¹ (base unit tesla, kg · s⁻² · A⁻¹). dimension: ISQ< Z0, // length P1, // mass N2, // time N1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottatesla: prefix!(yotta); "YT", "yottatesla", "yottateslas"; @zettatesla: prefix!(zetta); "ZT", "zettatesla", "zettateslas"; @exatesla: prefix!(exa); "ET", "exatesla", "exateslas"; @petatesla: prefix!(peta); "PT", "petatesla", "petateslas"; @teratesla: prefix!(tera); "TT", "teratesla", "terateslas"; @gigatesla: prefix!(giga); "GT", "gigatesla", "gigateslas"; @megatesla: prefix!(mega); "MT", "megatesla", "megateslas"; @kilotesla: prefix!(kilo); "kT", "kilotesla", "kiloteslas"; @hectotesla: prefix!(hecto); "hT", "hectotesla", "hectoteslas"; @decatesla: prefix!(deca); "daT", "decatesla", "decateslas"; /// Derived unit of magnetic flux density. @tesla: prefix!(none); "T", "tesla", "teslas"; @decitesla: prefix!(deci); "dT", "decitesla", "deciteslas"; @centitesla: prefix!(centi); "cT", "centitesla", "centiteslas"; @millitesla: prefix!(milli); "mT", "millitesla", "milliteslas"; @microtesla: prefix!(micro); "µT", "microtesla", "microteslas"; @nanotesla: prefix!(nano); "nT", "nanotesla", "nanoteslas"; @picotesla: prefix!(pico); "pT", "picotesla", "picoteslas"; @femtotesla: prefix!(femto); "fT", "femtotesla", "femtoteslas"; @attotesla: prefix!(atto); "aT", "attotesla", "attoteslas"; @zeptotesla: prefix!(zepto); "zT", "zeptotesla", "zeptoteslas"; @yoctotesla: prefix!(yocto); "yT", "yoctotesla", "yoctoteslas"; @gamma: 1.0_E-9; "γ", "gamma", "gammas"; @gauss: 1.0_E-4; "G", "gauss", "gauss"; } } #[cfg(test)] mod tests { storage_types! { use crate::si::area as a; use crate::si::magnetic_flux as f; use crate::si::magnetic_flux_density as b; use crate::si::quantities::*; use crate::tests::Test; use crate::num::One; #[test] fn check_dimension() { let _: MagneticFluxDensity = MagneticFlux::new::(V::one()) / Area::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, B: b::Conversion>() { Test::assert_approx_eq(&MagneticFluxDensity::new::(V::one()), &(MagneticFlux::new::(V::one()) / Area::new::(V::one()))); } } } } uom-0.35.0/src/si/magnetic_moment.rs000064400000000000000000000115401046102023000154300ustar 00000000000000//! Magnetic moment (base unit ampere square meter A · m²). quantity! { /// Magnetic moment (base unit ampere square meter A · m²). quantity: MagneticMoment; "magnetic moment"; /// Dimension of magnetic moment, IL² (base unit ampere square meter A · m²). dimension: ISQ< P2, // length Z0, // mass Z0, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @ampere_square_meter: prefix!(none); "A · m²", "ampere square meter", "ampere square meters"; @joule_per_tesla: prefix!(none); "J/T", "joule per tesla", "joules per tesla"; @newton_meter_per_tesla: prefix!(none); "N · m/T", "newton meter per tesla", "newton meters per tesla"; @ampere_square_centimeter: prefix!(none) * prefix!(centi) * prefix!(centi); "A · cm²", "ampere square centimeter", "ampere square centimeters"; @statampere_square_centimeter: 3.335_641_E-10 * prefix!(centi) * prefix!(centi); "statA · cm²", "statampere square centimeter", "statampere square centimeters"; @erg_per_gauss: 1.0_E-7 / 1.0_E-4; "erg/G", "erg per gauss", "ergs per gauss"; @bohr_magneton: 9.274_010_0783_E-24; "µ(Bohr)", "Bohr magneton", "Bohr magnetons"; @nuclear_magneton: 5.050_783_7461_E-27; "μ(Nuclear)", "nuclear magneton", "nuclear magnetons"; @atomic_unit_of_magnetic_dipole_moment: 1.854_802_015_66_E-23; "ħ · e/mₑ", "atomic unit of magnetic dipole moment", " atomic units of magnetic dipole moment"; @deuteron_magnetic_moment: 4.330_735_094_E-27; "μ(deuteron)", "deuteron magnetic moment", "deuteron magnetic moments"; @electron_magnetic_moment: -9.284_764_704_3_E-24; "μₑ", "electron magnetic moment", "electron magnetic moments"; @helion_magnetic_moment: -1.074_617_532_E-26; "μ(helion)", "helion magnetic moment", "helion magnetic moments"; @muon_magnetic_moment: -4.490_448_30_E-26; "μ(muon)", "muon magnetic moment", "muon magnetic moments"; @neutron_magnetic_moment: -9.662_365_1_E-27; "μ(neutron)", "neutron magnetic moment", "neutron magnetic moments"; @proton_magnetic_moment: 1.410_606_797_36_E-26; "μ(proton)", "proton magnetic moment", "proton magnetic moments"; @shielded_helion_magnetic_moment: -1.074_553_090_E-26; "μ’(helion)", "shielded helion magnetic moment", "shielded helion magnetic moments"; @shielded_proton_magnetic_moment: 1.410_570_560_E-26; "μ’(proton)", "shielded proton magnetic moment", "shielded proton magnetic moments"; @triton_magnetic_moment: 1.504_609_520_2_E-26; "μ(triton)", "triton magnetic moment", "triton magnetic moments"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::magnetic_moment as mm; use crate::si::electric_current as ec; use crate::si::quantities::*; use crate::si::energy as e; use crate::si::magnetic_flux_density as mfd; use crate::si::area as area; use crate::tests::Test; #[test] fn check_dimension() { let _: MagneticMoment = ElectricCurrent::new::(V::one()) * Area::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); fn test, A: area::Conversion, MM: mm::Conversion>() { Test::assert_approx_eq(&MagneticMoment::new::(V::one()), &(ElectricCurrent::new::(V::one()) * Area::new::(V::one()))); } } #[test] fn check_units_energy_per_field() { test::(); test::(); test::(); test::(); fn test, MFD: mfd::Conversion, MM: mm::Conversion>() { Test::assert_approx_eq(&MagneticMoment::new::(V::one()), &(Energy::new::(V::one()) / MagneticFluxDensity::new::(V::one()))); } } } } uom-0.35.0/src/si/magnetic_permeability.rs000064400000000000000000000033601046102023000166200ustar 00000000000000//! Magnetic permeability (base unit henry per meter, m · kg · s⁻² · A⁻²). quantity! { /// Magnetic permeability (base unit henry per meter, m · kg · s⁻² · A⁻²). quantity: MagneticPermeability; "magnetic permeability"; /// Dimension of magnetic permeability, LMT⁻²I⁻² (base unit henry per meter, /// m · kg · s⁻² · A⁻²). dimension: ISQ< P1, // length P1, // mass N2, // time N2, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @henry_per_meter: prefix!(none); "H/m", "henry per meter", "henrys per meter"; @vacuum_magnetic_permeability: 1.256_637_062_12_E-6; "µ₀", "vacuum magnetic permeability", "vacuum magnetic permeability"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::inductance as ind; use crate::si::magnetic_permeability as mp; use crate::si::length as l; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: MagneticPermeability = Inductance::new::(V::one()) / Length::new::(V::one()); } #[test] fn check_units() { test::(); fn test, IND: ind::Conversion, L: l::Conversion>() { Test::assert_approx_eq(&MagneticPermeability::new::(V::one()), &(Inductance::new::(V::one()) / Length::new::(V::one()))); } } } } uom-0.35.0/src/si/mass.rs000064400000000000000000000070051046102023000132260ustar 00000000000000//! Mass (base unit kilogram, kg). quantity! { /// Mass (base unit kilogram, kg). quantity: Mass; "mass"; /// Mass dimension, M (base unit kilogram, kg). dimension: ISQ< Z0, // length P1, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottagram: prefix!(yotta) / prefix!(kilo); "Yg", "yottagram", "yottagrams"; @zettagram: prefix!(zetta) / prefix!(kilo); "Zg", "zettagram", "zettagrams"; @exagram: prefix!(exa) / prefix!(kilo); "Eg", "exagram", "exagrams"; @petagram: prefix!(peta) / prefix!(kilo); "Pg", "petagram", "petagrams"; @teragram: prefix!(tera) / prefix!(kilo); "Tg", "teragram", "teragrams"; @gigagram: prefix!(giga) / prefix!(kilo); "Gg", "gigagram", "gigagrams"; @megagram: prefix!(mega) / prefix!(kilo); "Mg", "megagram", "megagrams"; /// The kilogram is the SI unit of mass. It is defined by taking the fixed numerical value /// of the Planck constant *h* to be 6.626 070 15 × 10⁻³⁴ when expressed in the unit J s, /// which is equal to kg m² s⁻¹, where the meter and the second are defined in terms of *c* /// and ∆*ν*Cs. @kilogram: prefix!(kilo) / prefix!(kilo); "kg", "kilogram", "kilograms"; @hectogram: prefix!(hecto) / prefix!(kilo); "hg", "hectogram", "hectograms"; @decagram: prefix!(deca) / prefix!(kilo); "dag", "decagram", "decagrams"; @gram: prefix!(none) / prefix!(kilo); "g", "gram", "grams"; @decigram: prefix!(deci) / prefix!(kilo); "dg", "decigram", "decigrams"; @centigram: prefix!(centi) / prefix!(kilo); "cg", "centigram", "centigrams"; @milligram: prefix!(milli) / prefix!(kilo); "mg", "milligram", "milligrams"; @microgram: prefix!(micro) / prefix!(kilo); "µg", "microgram", "micrograms"; @nanogram: prefix!(nano) / prefix!(kilo); "ng", "nanogram", "nanograms"; @picogram: prefix!(pico) / prefix!(kilo); "pg", "picogram", "picograms"; @femtogram: prefix!(femto) / prefix!(kilo); "fg", "femtogram", "femtograms"; @attogram: prefix!(atto) / prefix!(kilo); "ag", "attogram", "attograms"; @zeptogram: prefix!(zepto) / prefix!(kilo); "zg", "zeptogram", "zeptograms"; @yoctogram: prefix!(yocto) / prefix!(kilo); "yg", "yoctogram", "yoctograms"; @carat: 2.0_E-4; "ct", "carat", "carats"; /// Unified atomic mass unit. @dalton: 1.660_539_066_60_E-27; "Da", "dalton", "daltons"; @grain: 6.479_891_E-5; "gr", "grain", "grains"; @hundredweight_long: 5.080_235_E1; "cwt long", "hundredweight (long)", "hundredweight (long)"; @hundredweight_short: 4.535_924_E1; "cwt short", "hundredweight (short)", "hundredweight (short)"; @ounce: 2.834_952_E-2; "oz", "ounce", "ounces"; @ounce_troy: 3.110_348_E-2; "oz t", "troy ounce", "troy ounces"; @pennyweight: 1.555_174_E-3; "dwt", "pennyweight", "pennyweight"; @pound: 4.535_924_E-1; "lb", "pound", "pounds"; @pound_troy: 3.732_417_E-1; "lb t", "troy pound", "troy pounds"; @slug: 1.459_390_E1; "slug", "slug", "slugs"; @ton_assay: 2.916_667_E-2; "AT", "assay ton", "assay tons"; @ton_long: 1.016_047_E3; "2240 lb", "long ton", "long tons"; @ton_short: 9.071_847_E2; "2000 lb", "short ton", "short tons"; /// Ton Metric @ton: 1.0_E3; "t", "ton", "tons"; } } uom-0.35.0/src/si/mass_concentration.rs000064400000000000000000000324731046102023000161630ustar 00000000000000//! Mass concentration (base unit kilogram per cubic meter, kg · m⁻³). quantity! { /// Mass concentration (base unit kilogram per cubic meter, kg · m⁻³). quantity: MassConcentration; "mass concentration"; /// Dimension of mass concentration, L⁻³M (base unit kilogram per cubic meter, kg · m⁻³). dimension: ISQ< N3, // length P1, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @yottagram_per_cubic_meter: prefix!(yotta) / prefix!(kilo); "Yg/m³", "yottagram per cubic meter", "yottagrams per cubic meter"; @zettagram_per_cubic_meter: prefix!(zetta) / prefix!(kilo); "Zg/m³", "zettagram per cubic meter", "zettagrams per cubic meter"; @exagram_per_cubic_meter: prefix!(exa) / prefix!(kilo); "Eg/m³", "exagram per cubic meter", "exagrams per cubic meter"; @petagram_per_cubic_meter: prefix!(peta) / prefix!(kilo); "Pg/m³", "petagram per cubic meter", "petagrams per cubic meter"; @teragram_per_cubic_meter: prefix!(tera) / prefix!(kilo); "Tg/m³", "teragram per cubic meter", "teragrams per cubic meter"; @gigagram_per_cubic_meter: prefix!(giga) / prefix!(kilo); "Gg/m³", "gigagram per cubic meter", "gigagrams per cubic meter"; @megagram_per_cubic_meter: prefix!(mega) / prefix!(kilo); "Mg/m³", "megagram per cubic meter", "megagrams per cubic meter"; @kilogram_per_cubic_meter: prefix!(kilo) / prefix!(kilo); "kg/m³", "kilogram per cubic meter", "kilograms per cubic meter"; @hectogram_per_cubic_meter: prefix!(hecto) / prefix!(kilo); "hg/m³", "hectogram per cubic meter", "hectograms per cubic meter"; @decagram_per_cubic_meter: prefix!(deca) / prefix!(kilo); "dag/m³", "decagram per cubic meter", "decagrams per cubic meter"; @gram_per_cubic_meter: prefix!(none) / prefix!(kilo); "g/m³", "gram per cubic meter", "grams per cubic meter"; @decigram_per_cubic_meter: prefix!(deci) / prefix!(kilo); "dg/m³", "decigram per cubic meter", "decigrams per cubic meter"; @centigram_per_cubic_meter: prefix!(centi) / prefix!(kilo); "cg/m³", "centigram per cubic meter", "centigrams per cubic meter"; @milligram_per_cubic_meter: prefix!(milli) / prefix!(kilo); "mg/m³", "milligram per cubic meter", "milligrams per cubic meter"; @microgram_per_cubic_meter: prefix!(micro) / prefix!(kilo); "µg/m³", "microgram per cubic meter", "micrograms per cubic meter"; @nanogram_per_cubic_meter: prefix!(nano) / prefix!(kilo); "ng/m³", "nanogram per cubic meter", "nanograms per cubic meter"; @picogram_per_cubic_meter: prefix!(pico) / prefix!(kilo); "pg/m³", "picogram per cubic meter", "picograms per cubic meter"; @femtogram_per_cubic_meter: prefix!(femto) / prefix!(kilo); "fg/m³", "femtogram per cubic meter", "femtograms per cubic meter"; @attogram_per_cubic_meter: prefix!(atto) / prefix!(kilo); "ag/m³", "attogram per cubic meter", "attograms per cubic meter"; @zeptogram_per_cubic_meter: prefix!(zepto) / prefix!(kilo); "zg/m³", "zeptogram per cubic meter", "zeptograms per cubic meter"; @yoctogram_per_cubic_meter: prefix!(yocto) / prefix!(kilo); "yg/m³", "yoctogram per cubic meter", "yoctograms per cubic meter"; @kilogram_per_cubic_decimeter: (prefix!(kilo) / prefix!(kilo)) / prefix!(deci) / prefix!(deci) / prefix!(deci); "kg/dm³", "kilogram per cubic decimeter", "kilograms per cubic decimeter"; @kilogram_per_liter: (prefix!(kilo) / prefix!(kilo)) / prefix!(milli); "kg/L", "kilogram per liter", "kilograms per liter"; @gram_per_cubic_decimeter: (prefix!(none) / prefix!(kilo)) / prefix!(deci) / prefix!(deci) / prefix!(deci); "g/dm³", "gram per cubic decimeter", "grams per cubic decimeter"; @gram_per_liter: (prefix!(none) / prefix!(kilo)) / prefix!(milli); "g/L", "gram per liter", "grams per liter"; @milligram_per_cubic_decimeter: (prefix!(milli) / prefix!(kilo)) / prefix!(deci) / prefix!(deci) / prefix!(deci); "mg/dm³", "milligram per cubic decimeter", "milligrams per cubic decimeter"; @milligram_per_liter: (prefix!(milli) / prefix!(kilo)) / prefix!(milli); "mg/L", "milligram per liter", "milligrams per liter"; @microgram_per_cubic_decimeter: (prefix!(micro) / prefix!(kilo)) / prefix!(deci) / prefix!(deci) / prefix!(deci); "μg/dm³", "microgram per cubic decimeter", "micrograms per cubic decimeter"; @microgram_per_liter: (prefix!(micro) / prefix!(kilo)) / prefix!(milli); "μg/L", "microgram per liter", "micrograms per liter"; @nanogram_per_cubic_decimeter: (prefix!(nano) / prefix!(kilo)) / prefix!(deci) / prefix!(deci) / prefix!(deci); "ng/dm³", "nanogram per cubic decimeter", "nanograms per cubic decimeter"; @nanogram_per_liter: (prefix!(nano) / prefix!(kilo)) / prefix!(milli); "ng/L", "nanogram per liter", "nanograms per liter"; @picogram_per_cubic_decimeter: (prefix!(pico) / prefix!(kilo)) / prefix!(deci) / prefix!(deci) / prefix!(deci); "pg/dm³", "picogram per cubic decimeter", "picograms per cubic decimeter"; @picogram_per_liter: (prefix!(pico) / prefix!(kilo)) / prefix!(milli); "pg/L", "picogram per liter", "picograms per liter"; @femtogram_per_cubic_decimeter: (prefix!(femto) / prefix!(kilo)) / prefix!(deci) / prefix!(deci) / prefix!(deci); "fg/dm³", "femtogram per cubic decimeter", "femtograms per cubic decimeter"; @femtogram_per_liter: (prefix!(femto) / prefix!(kilo)) / prefix!(milli); "fg/L", "femtogram per liter", "femtograms per liter"; @kilogram_per_deciliter: (prefix!(kilo) / prefix!(kilo)) / prefix!(deci) / prefix!(milli); "kg/dL", "kilogram per deciliter", "kilograms per deciliter"; @gram_per_deciliter: (prefix!(none) / prefix!(kilo)) / prefix!(deci) / prefix!(milli); "g/dL", "gram per deciliter", "grams per deciliter"; @milligram_per_deciliter: (prefix!(milli) / prefix!(kilo)) / prefix!(deci) / prefix!(milli); "mg/dL", "milligram per deciliter", "milligrams per deciliter"; @microgram_per_deciliter: (prefix!(micro) / prefix!(kilo)) / prefix!(deci) / prefix!(milli); "μg/dL", "microgram per deciliter", "micrograms per deciliter"; @nanogram_per_deciliter: (prefix!(nano) / prefix!(kilo)) / prefix!(deci) / prefix!(milli); "ng/dL", "nanogram per deciliter", "nanograms per deciliter"; @picogram_per_deciliter: (prefix!(pico) / prefix!(kilo)) / prefix!(deci) / prefix!(milli); "pg/dL", "picogram per deciliter", "picograms per deciliter"; @femtogram_per_deciliter: (prefix!(femto) / prefix!(kilo)) / prefix!(deci) / prefix!(milli); "fg/dL", "femtogram per deciliter", "femtograms per deciliter"; @kilogram_per_milliliter: (prefix!(kilo) / prefix!(kilo)) / prefix!(milli) / prefix!(milli); "kg/mL", "kilogram per milliliter", "kilograms per milliliter"; @gram_per_milliliter: (prefix!(none) / prefix!(kilo)) / prefix!(milli) / prefix!(milli); "g/mL", "gram per milliliter", "grams per milliliter"; @milligram_per_milliliter: (prefix!(milli) / prefix!(kilo)) / prefix!(milli) / prefix!(milli); "mg/mL", "milligram per milliliter", "milligrams per milliliter"; @microgram_per_milliliter: (prefix!(micro) / prefix!(kilo)) / prefix!(milli) / prefix!(milli); "μg/mL", "microgram per milliliter", "micrograms per milliliter"; @nanogram_per_milliliter: (prefix!(nano) / prefix!(kilo)) / prefix!(milli) / prefix!(milli); "ng/mL", "nanogram per milliliter", "nanograms per milliliter"; @picogram_per_milliliter: (prefix!(pico) / prefix!(kilo)) / prefix!(milli) / prefix!(milli); "pg/mL", "picogram per milliliter", "picograms per milliliter"; @femtogram_per_milliliter: (prefix!(femto) / prefix!(kilo)) / prefix!(milli) / prefix!(milli); "fg/mL", "femtogram per milliliter", "femtograms per milliliter"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::mass as m; use crate::si::mass_concentration as r; use crate::si::quantities::*; use crate::si::volume as v; use crate::tests::Test; #[test] fn check_dimension() { let _: MassConcentration = (Mass::new::(V::one()) / Volume::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, U: v::Conversion, R: r::Conversion>() { Test::assert_approx_eq(&MassConcentration::new::(V::one()), &(Mass::new::(V::one()) / Volume::new::(V::one())).into()); } } } } uom-0.35.0/src/si/mass_density.rs000064400000000000000000000251721046102023000147720ustar 00000000000000//! Mass density (base unit kilogram per cubic meter, kg · m⁻³). /// Mass density (base unit kilogram per cubic meter, kg · m⁻³). #[deprecated(since = "0.23.0", note = "Please use the more descriptive MassDensity instead.")] pub type Density = MassDensity; quantity! { /// Mass density (base unit kilogram per cubic meter, kg · m⁻³). quantity: MassDensity; "mass density"; /// Dimension of mass density, L⁻³M (base unit kilogram per cubic meter, kg · m⁻³). dimension: ISQ< N3, // length P1, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottagram_per_cubic_meter: prefix!(yotta) / prefix!(kilo); "Yg/m³", "yottagram per cubic meter", "yottagrams per cubic meter"; @zettagram_per_cubic_meter: prefix!(zetta) / prefix!(kilo); "Zg/m³", "zettagram per cubic meter", "zettagrams per cubic meter"; @exagram_per_cubic_meter: prefix!(exa) / prefix!(kilo); "Eg/m³", "exagram per cubic meter", "exagrams per cubic meter"; @petagram_per_cubic_meter: prefix!(peta) / prefix!(kilo); "Pg/m³", "petagram per cubic meter", "petagrams per cubic meter"; @teragram_per_cubic_meter: prefix!(tera) / prefix!(kilo); "Tg/m³", "teragram per cubic meter", "teragrams per cubic meter"; @gigagram_per_cubic_meter: prefix!(giga) / prefix!(kilo); "Gg/m³", "gigagram per cubic meter", "gigagrams per cubic meter"; @megagram_per_cubic_meter: prefix!(mega) / prefix!(kilo); "Mg/m³", "megagram per cubic meter", "megagrams per cubic meter"; /// Derived unit of density. @kilogram_per_cubic_meter: prefix!(kilo) / prefix!(kilo); "kg/m³", "kilogram per cubic meter", "kilograms per cubic meter"; @hectogram_per_cubic_meter: prefix!(hecto) / prefix!(kilo); "hg/m³", "hectogram per cubic meter", "hectograms per cubic meter"; @decagram_per_cubic_meter: prefix!(deca) / prefix!(kilo); "dag/m³", "decagram per cubic meter", "decagrams per cubic meter"; @gram_per_cubic_meter: prefix!(none) / prefix!(kilo); "g/m³", "gram per cubic meter", "grams per cubic meter"; @decigram_per_cubic_meter: prefix!(deci) / prefix!(kilo); "dg/m³", "decigram per cubic meter", "decigrams per cubic meter"; @centigram_per_cubic_meter: prefix!(centi) / prefix!(kilo); "cg/m³", "centigram per cubic meter", "centigrams per cubic meter"; @milligram_per_cubic_meter: prefix!(milli) / prefix!(kilo); "mg/m³", "milligram per cubic meter", "milligrams per cubic meter"; @microgram_per_cubic_meter: prefix!(micro) / prefix!(kilo); "µg/m³", "microgram per cubic meter", "micrograms per cubic meter"; @nanogram_per_cubic_meter: prefix!(nano) / prefix!(kilo); "ng/m³", "nanogram per cubic meter", "nanograms per cubic meter"; @picogram_per_cubic_meter: prefix!(pico) / prefix!(kilo); "pg/m³", "picogram per cubic meter", "picograms per cubic meter"; @femtogram_per_cubic_meter: prefix!(femto) / prefix!(kilo); "fg/m³", "femtogram per cubic meter", "femtograms per cubic meter"; @attogram_per_cubic_meter: prefix!(atto) / prefix!(kilo); "ag/m³", "attogram per cubic meter", "attograms per cubic meter"; @zeptogram_per_cubic_meter: prefix!(zepto) / prefix!(kilo); "zg/m³", "zeptogram per cubic meter", "zeptograms per cubic meter"; @yoctogram_per_cubic_meter: prefix!(yocto) / prefix!(kilo); "yg/m³", "yoctogram per cubic meter", "yoctograms per cubic meter"; @carat_per_cubic_meter: 2.0_E-4; "ct/m³", "carat per cubic meter", "carats per cubic meter"; @grain_per_cubic_meter: 6.479_891_E-5; "gr/m³", "grain per cubic meter", "grains per cubic meter"; @hundredweight_long_per_cubic_meter: 5.080_235_E1; "cwt long/m³", "hundredweight (long) per cubic meter", "hundredweight (long) per cubic meter"; @hundredweight_short_per_cubic_meter: 4.535_924_E1; "cwt short/m³", "hundredweight (short) per cubic meter", "hundredweight (short) per cubic meter"; @ounce_per_cubic_meter: 2.834_952_E-2; "oz/m³", "ounce per cubic meter", "ounces per cubic meter"; @ounce_troy_per_cubic_meter: 3.110_348_E-2; "oz t/m³", "troy ounce per cubic meter", "troy ounces per cubic meter"; @pennyweight_per_cubic_meter: 1.555_174_E-3; "dwt/m³", "pennyweight per cubic meter", "pennyweight per cubic meter"; @pound_per_cubic_meter: 4.535_924_E-1; "lb/m³", "pound per cubic meter", "pounds per cubic meter"; @pound_troy_per_cubic_meter: 3.732_417_E-1; "lb t/m³", "troy pound per cubic meter", "troy pounds per cubic meter"; @slug_per_cubic_meter: 1.459_390_E1; "slug/m³", "slug per cubic meter", "slugs per cubic meter"; @ton_assay_per_cubic_meter: 2.916_667_E-2; "AT/m³", "assay ton per cubic meter", "assay tons per cubic meter"; @ton_long_per_cubic_meter: 1.016_047_E3; "2240 lb/m³", "long ton per cubic meter", "long tons per cubic meter"; @ton_short_per_cubic_meter: 9.071_847_E2; "2000 lb/m³", "short ton per cubic meter", "short tons per cubic meter"; @ton_per_cubic_meter: 1.0_E3; "t/m³", "ton per cubic meter", "tons per cubic meter"; // ton per cubic meter, metric @grain_per_gallon: 1.711_806_006_849_452_E-2; "gr/gal", "grain per gallon", "grains per gallon"; @gram_per_cubic_centimeter: 1.0_E3; "g/cm³", "gram per cubic centimeter", "grams per cubic centimeter"; @ounce_per_cubic_inch: 1.729_994_275_971_406_5_E3; "oz/in³", "ounce per cubic inch", "ounces per cubic inch"; @ounce_per_gallon_imperial: 6.236_022_604_039_955_E0; "oz/gal (UK)", "ounce per Imperial gallon", "ounces per Imperial gallon"; @ounce_per_gallon: 7.489_150_454_428_738_E0; "oz/gal", "ounce per gallon", "ounces per gallon"; @pound_per_cubic_foot: 1.601_846_250_553_998_6_E1; "lb/ft³", "pound per cubic foot", "pounds per cubic foot"; @pound_per_cubic_inch: 2.767_991_329_744_322_5_E4; "lb/in³", "pound per cubic inch", "pounds per cubic inch"; @pound_per_cubic_yard: 5.932_764_278_928_825_E-1; "lb/yd³", "pound per cubic yard", "pounds per cubic yard"; @pound_per_gallon_imperial: 9.977_637_926_217_915_E1; "lb/gal (UK)", "pound per Imperial gallon", "pounds per Imperial gallon"; @pound_per_gallon: 1.198_264_284_046_228_E2; "lb/gal", "pound per gallon", "pounds per gallon"; @slug_per_cubic_foot: 5.153_786_526_396_827_E2; "slug/ft³", "slug per cubic foot", "slugs per cubic foot"; @ton_long_per_cubic_yard: 1.328_939_229_870_87_E3; "2240 lb/yd³", "long ton per cubic yard", "long tons per cubic yard"; @ton_short_per_cubic_yard: 1.186_552_724_990_710_2_E3; "2000 lb/yd³", "short ton per cubic yard", "short tons per cubic yard"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::mass as m; use crate::si::mass_density as d; use crate::si::quantities::*; use crate::si::volume as v; use crate::tests::Test; #[test] fn check_dimension() { let _: MassDensity = Mass::new::(V::one()) / Volume::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, U: v::Conversion, D: d::Conversion>() { Test::assert_approx_eq(&MassDensity::new::(V::one()), &(Mass::new::(V::one()) / Volume::new::(V::one()))); } } } } uom-0.35.0/src/si/mass_flux.rs000064400000000000000000000042341046102023000142650ustar 00000000000000//! Mass flux (base unit kilogram per square meter second, m⁻² · kg · s⁻¹). quantity! { /// Mass flux (base unit kilogram per square meter second, m⁻² · kg · s⁻¹). quantity: MassFlux; "mass flux"; /// Dimension of mass flux, L⁻²MT⁻¹ (base unit kilogram per square meter second, /// m⁻² · kg · s⁻¹). dimension: ISQ< N2, // length P1, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @kilogram_per_square_meter_second: prefix!(none); "kg/(m² · s)", "kilogram per square meter second", "kilograms per square meter second"; @gram_per_square_centimeter_second: prefix!(milli) / prefix!(centi) / prefix!(centi); "g/(cm² · s)", "gram per square centimeter second", "grams per square centimeter second"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::mass as m; use crate::si::mass_flux as mf; use crate::si::quantities::*; use crate::si::time as t; use crate::si::area as a; use crate::tests::Test; #[test] fn check_dimension() { let _: MassFlux = Mass::new::(V::one()) / Time::new::(V::one()) / Area::new::(V::one()); } #[test] fn check_units() { test::(); test::(); fn test, A: a::Conversion, T: t::Conversion, MF: mf::Conversion>() { Test::assert_approx_eq(&MassFlux::new::(V::one()), &(Mass::new::(V::one()) / Time::new::(V::one()) / Area::new::(V::one()))); } } } } uom-0.35.0/src/si/mass_per_energy.rs000064400000000000000000000143301046102023000154440ustar 00000000000000//! Mass per energy (base unit kilogram per joule, m⁻² · s²). //! //! This quantity is typically used to express an emission intensity, also known as carbon //! intensity. Emission intensity is a measure of how much mass of carbon dioxide (CO2) is emitted //! per unit of energy. quantity! { /// Mass per energy (base unit kilogram per joule, m⁻² · s²). quantity: MassPerEnergy; "mass per energy"; /// Dimension of mass per energy, L⁻²T² (base unit kilogram per joule, m⁻² · s²). dimension: ISQ< N2, // length Z0, // mass P2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @teragram_per_joule: prefix!(tera) / prefix!(kilo); "Tg/J", "teragram per joule", "teragrams per joule"; @gigagram_per_joule: prefix!(giga) / prefix!(kilo); "Gg/J", "gigagram per joule", "gigagrams per joule"; @megagram_per_joule: prefix!(mega) / prefix!(kilo); "Mg/J", "megagram per joule", "megagrams per joule"; /// Derived unit of Mass per energy. @kilogram_per_joule: prefix!(kilo) / prefix!(kilo); "kg/J", "kilogram per joule", "kilograms per joule"; @hectogram_per_joule: prefix!(hecto) / prefix!(kilo); "hg/J", "hectogram per joule", "hectograms per joule"; @decagram_per_joule: prefix!(deca) / prefix!(kilo); "dag/J", "decagram per joule", "decagrams per joule"; @gram_per_joule: prefix!(none) / prefix!(kilo); "g/J", "gram per joule", "grams per joule"; @decigram_per_joule: prefix!(deci) / prefix!(kilo); "dg/J", "decigram per joule", "decigrams per joule"; @centigram_per_joule: prefix!(centi) / prefix!(kilo); "cg/J", "centigram per joule", "centigrams per joule"; @milligram_per_joule: prefix!(milli) / prefix!(kilo); "mg/J", "milligram per joule", "milligrams per joule"; @microgram_per_joule: prefix!(micro) / prefix!(kilo); "µg/J", "microgram per joule", "micrograms per joule"; @pound_per_joule: 4.535_924_E-1; "lb/J", "pound per joule", "pounds per joule"; @pound_per_gigawatt_hour: 4.535_924_E-1 / 3.6_E12; "lb/GWh", "pound per gigawatt hour", "pounds per gigawatt hour"; @pound_per_megawatt_hour: 4.535_924_E-1 / 3.6_E9; "lb/MWh", "pound per megawatt hour", "pounds per megawatt hour"; @pound_per_kilowatt_hour: 4.535_924_E-1 / 3.6_E6; "lb/kWh", "pound per kilowatt hour", "pounds per kilowatt hour"; @pound_per_watt_hour: 4.535_924_E-1 / 3.6_E3; "lb/Wh", "pound per watt hour", "pounds per watt hour"; @kilogram_per_gigawatt_hour: prefix!(none) / 3.6_E12; "g/GWh", "kilogram per gigawatt hour", "kilograms per gigawatt hour"; @kilogram_per_megawatt_hour: prefix!(none) / 3.6_E9; "g/MWh", "kilogram per megawatt hour", "kilograms per megawatt hour"; @kilogram_per_kilowatt_hour: prefix!(none) / 3.6_E6; "g/kWh", "kilogram per kilowatt hour", "kilograms per kilowatt hour"; @kilogram_per_watt_hour: prefix!(none) / 3.6_E3; "g/Wh", "kilogram per watt hour", "kilograms per watt hour"; @gram_per_gigawatt_hour: 1_E-3 / 3.6_E12; "g/GWh", "gram per gigawatt hour", "grams per gigawatt hour"; @gram_per_megawatt_hour: 1_E-3 / 3.6_E9; "g/MWh", "gram per megawatt hour", "grams per megawatt hour"; @gram_per_kilowatt_hour: 1_E-3 / 3.6_E6; "g/kWh", "gram per kilowatt hour", "grams per kilowatt hour"; @gram_per_watt_hour: 1_E-3 / 3.6_E3; "g/Wh", "gram per watt hour", "grams per watt hour"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::mass_per_energy as v; use crate::si::energy as e; use crate::si::mass as m; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: MassPerEnergy = Mass::new::(V::one()) / Energy::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, E: e::Conversion, A: v::Conversion>() { Test::assert_approx_eq(&MassPerEnergy::new::(V::one()), &(Mass::new::(V::one()) / Energy::new::(V::one()))); } } } } uom-0.35.0/src/si/mass_rate.rs000064400000000000000000000241541046102023000142450ustar 00000000000000//! Mass rate (base unit kilogram per second, kg · s⁻¹). quantity! { /// Mass rate (base unit kilogram per second, kg · s⁻¹). quantity: MassRate; "mass rate"; /// Dimension of mass rate, MT⁻¹ (base unit kilogram per second, kg · s⁻¹). dimension: ISQ< Z0, // length P1, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottagram_per_second: prefix!(yotta) / prefix!(kilo); "Yg/s", "yottagram per second", "yottagrams per second"; @zettagram_per_second: prefix!(zetta) / prefix!(kilo); "Zg/s", "zettagram per second", "zettagrams per second"; @exagram_per_second: prefix!(exa) / prefix!(kilo); "Eg/s", "exagram per second", "exagrams per second"; @petagram_per_second: prefix!(peta) / prefix!(kilo); "Pg/s", "petagram per second", "petagrams per second"; @teragram_per_second: prefix!(tera) / prefix!(kilo); "Tg/s", "teragram per second", "teragrams per second"; @gigagram_per_second: prefix!(giga) / prefix!(kilo); "Gg/s", "gigagram per second", "gigagrams per second"; @megagram_per_second: prefix!(mega) / prefix!(kilo); "Mg/s", "megagram per second", "megagrams per second"; /// Derived unit of mass rate. @kilogram_per_second: prefix!(kilo) / prefix!(kilo); "kg/s", "kilogram per second", "kilograms per second"; @hectogram_per_second: prefix!(hecto) / prefix!(kilo); "hg/s", "hectogram per second", "hectograms per second"; @decagram_per_second: prefix!(deca) / prefix!(kilo); "dag/s", "decagram per second", "decagrams per second"; @gram_per_second: prefix!(none) / prefix!(kilo); "g/s", "gram per second", "grams per second"; @decigram_per_second: prefix!(deci) / prefix!(kilo); "dg/s", "decigram per second", "decigrams per second"; @centigram_per_second: prefix!(centi) / prefix!(kilo); "cg/s", "centigram per second", "centigrams per second"; @milligram_per_second: prefix!(milli) / prefix!(kilo); "mg/s", "milligram per second", "milligrams per second"; @microgram_per_second: prefix!(micro) / prefix!(kilo); "µg/s", "microgram per second", "micrograms per second"; @nanogram_per_second: prefix!(nano) / prefix!(kilo); "ng/s", "nanogram per second", "nanograms per second"; @picogram_per_second: prefix!(pico) / prefix!(kilo); "pg/s", "picogram per second", "picograms per second"; @femtogram_per_second: prefix!(femto) / prefix!(kilo); "fg/s", "femtogram per second", "femtograms per second"; @attogram_per_second: prefix!(atto) / prefix!(kilo); "ag/s", "attogram per second", "attograms per second"; @zeptogram_per_second: prefix!(zepto) / prefix!(kilo); "zg/s", "zeptogram per second", "zeptograms per second"; @yoctogram_per_second: prefix!(yocto) / prefix!(kilo); "yg/s", "yoctogram per second", "yoctograms per second"; @kilogram_per_minute: 1.666_666_666_666_666_6_E-2; "kg/min", "kilogram per minute", "kilograms per minute"; @kilogram_per_hour: 2.777_777_777_777_777_7_E-4; "kg/h", "kilogram per hour", "kilograms per hour"; @kilogram_per_day: 1.157_407_407_407_407_4_E-5; "kg/d", "kilogram per day", "kilograms per day"; @gram_per_minute: 1.666_666_666_666_666_6_E-5; "g/min", "gram per minute", "grams per minute"; @gram_per_hour: 2.777_777_777_777_777_7_E-7; "g/h", "gram per hour", "grams per hour"; @gram_per_day: 1.157_407_407_407_407_4_E-8; "g/d", "gram per day", "grams per day"; @carat_per_second: 2.0_E-4; "ct/s", "carat per second", "carats per second"; @grain_per_second: 6.479_891_E-5; "gr/s", "grain per second", "grains per second"; @hundredweight_long_per_second: 5.080_235_E1; "cwt long/s", "hundredweight (long) per second", "hundredweight (long) per second"; @hundredweight_short_per_second: 4.535_924_E1; "cwt short/s", "hundredweight (short) per second", "hundredweight (short) per second"; @ounce_per_second: 2.834_952_E-2; "oz/s", "ounce per second", "ounces per second"; @ounce_troy_per_second: 3.110_348_E-2; "oz t/s", "troy ounce per second", "troy ounces per second"; @pennyweight_per_second: 1.555_174_E-3; "dwt/s", "pennyweight per second", "pennyweight per second"; @pound_per_second: 4.535_924_E-1; "lb/s", "pound per second", "pounds per second"; @pound_per_minute: 7.559_873_333_333_333_E-3; "lb/min", "pound per minute", "pounds per minute"; @pound_per_hour: 1.259_978_888_888_888_8_E-4; "lb/h", "pound per hour", "pounds per hour"; @pound_per_day: 5.249_912_037_037_037_0_E-6; "lb/d", "pound per day", "pounds per day"; @pound_troy_per_second: 3.732_417_E-1; "lb t/s", "troy pound per second", "troy pounds per second"; @slug_per_second: 1.459_390_E1; "slug/s", "slug per second", "slugs per second"; @ton_assay_per_second: 2.916_667_E-2; "AT/s", "assay ton per second", "assay tons per second"; @ton_long_per_second: 1.016_047_E3; "2240 lb/s", "long ton per second", "long tons per second"; @ton_short_per_second: 9.071_847_E2; "2000 lb/s", "short ton per second", "short tons per second"; @ton_short_per_hour: 2.519_957_5_E-1; "2000 lb/h", "short ton per hour", "short tons per hour"; /// Ton per second, metric. @ton_per_second: 1.0_E3; "t/s", "ton per second", "tons per second"; /// Ton per minute, metric. @ton_per_minute: 1.666_666_666_666_666_6_E1; "t/min", "ton per minute", "tons per minute"; /// Ton per hour, metric. @ton_per_hour: 2.777777777777778_E-1; "t/h", "ton per hour", "tons per hour"; /// Ton per day, metric. @ton_per_day: 1.157_407_407_407_407_4_E-2; "t/d", "ton per day", "tons per day"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::mass as m; use crate::si::mass_rate as r; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: MassRate = Mass::new::(V::one()) / Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, R: r::Conversion>() { Test::assert_approx_eq(&MassRate::new::(V::one()), &(Mass::new::(V::one()) / Time::new::(V::one()))); } } } } uom-0.35.0/src/si/mod.rs000064400000000000000000000360551046102023000130510ustar 00000000000000//! [International System of Units][si] (SI) and [International System of Quantities][isq] (ISQ) //! implementations. //! //! [si]: https://jcgm.bipm.org/vim/en/1.16.html //! [isq]: https://jcgm.bipm.org/vim/en/1.6.html #[macro_use] mod prefix; system! { /// [International System of Quantities](https://jcgm.bipm.org/vim/en/1.6.html) (ISQ). /// /// ## Generic Parameters /// * `L`: Length dimension. /// * `M`: Mass dimension. /// * `T`: Time dimension. /// * `I`: Electric current dimension. /// * `Th`: Thermodynamic temperature dimension. /// * `N`: Amount of substance dimension. /// * `J`: Luminous intensity dimension. /// * `K`: Kind. quantities: ISQ { /// Length, one of the base quantities in the ISQ, denoted by the symbol L. The base unit /// for length is meter in the SI. length: meter, L; /// Mass, one of the base quantities in the ISQ, denoted by the symbol M. The base unit /// for mass is kilogram in the SI. mass: kilogram, M; /// Time, one of the base quantities in the ISQ, denoted by the symbol T. The base unit /// for time is second in the SI. time: second, T; /// Electric current, one of the base quantities in the ISQ, denoted by the symbol I. The /// base unit for electric current is ampere in the SI. electric_current: ampere, I; /// Thermodynamic temperature, one of the base quantities in the ISQ, denoted by the symbol /// Th (Θ). The base unit for thermodynamic temperature is kelvin in the SI. thermodynamic_temperature: kelvin, Th; /// Amount of substance, one of the base quantities in the ISQ, denoted by the symbol N. /// The base unit for amount of substance is mole in the SI. amount_of_substance: mole, N; /// Luminous intensity, one of the base quantities in the ISQ, denoted by the symbol J. The /// base unit for luminous intensity is candela in the SI. luminous_intensity: candela, J; } /// [International System of Units](https://jcgm.bipm.org/vim/en/1.16.html) (SI). units: SI { absement::Absement, acceleration::Acceleration, action::Action, amount_of_substance::AmountOfSubstance, angle::Angle, angular_absement::AngularAbsement, angular_acceleration::AngularAcceleration, angular_jerk::AngularJerk, angular_velocity::AngularVelocity, area::Area, areal_density_of_states::ArealDensityOfStates, areal_mass_density::ArealMassDensity, areal_number_density::ArealNumberDensity, areal_number_rate::ArealNumberRate, available_energy::AvailableEnergy, capacitance::Capacitance, catalytic_activity::CatalyticActivity, catalytic_activity_concentration::CatalyticActivityConcentration, curvature::Curvature, diffusion_coefficient::DiffusionCoefficient, dynamic_viscosity::DynamicViscosity, electric_charge::ElectricCharge, electric_charge_areal_density::ElectricChargeArealDensity, electric_charge_linear_density::ElectricChargeLinearDensity, electric_charge_volumetric_density::ElectricChargeVolumetricDensity, electric_current::ElectricCurrent, electric_current_density::ElectricCurrentDensity, electric_dipole_moment::ElectricDipoleMoment, electric_displacement_field::ElectricDisplacementField, electric_field::ElectricField, electric_flux::ElectricFlux, electric_permittivity::ElectricPermittivity, electric_potential::ElectricPotential, electric_quadrupole_moment::ElectricQuadrupoleMoment, electrical_conductance::ElectricalConductance, electrical_conductivity::ElectricalConductivity, electrical_mobility::ElectricalMobility, electrical_resistance::ElectricalResistance, electrical_resistivity::ElectricalResistivity, energy::Energy, force::Force, frequency::Frequency, frequency_drift::FrequencyDrift, heat_capacity::HeatCapacity, heat_flux_density::HeatFluxDensity, heat_transfer::HeatTransfer, inductance::Inductance, information::Information, information_rate::InformationRate, inverse_velocity::InverseVelocity, jerk::Jerk, length::Length, linear_density_of_states::LinearDensityOfStates, linear_mass_density::LinearMassDensity, linear_number_density::LinearNumberDensity, linear_number_rate::LinearNumberRate, linear_power_density::LinearPowerDensity, luminance::Luminance, luminous_intensity::LuminousIntensity, magnetic_field_strength::MagneticFieldStrength, magnetic_flux::MagneticFlux, magnetic_flux_density::MagneticFluxDensity, magnetic_moment::MagneticMoment, magnetic_permeability::MagneticPermeability, mass::Mass, mass_concentration::MassConcentration, mass_density::MassDensity, mass_flux::MassFlux, mass_per_energy::MassPerEnergy, mass_rate::MassRate, molality::Molality, molar_concentration::MolarConcentration, molar_energy::MolarEnergy, molar_flux::MolarFlux, molar_heat_capacity::MolarHeatCapacity, molar_mass::MolarMass, molar_radioactivity::MolarRadioactivity, molar_volume::MolarVolume, moment_of_inertia::MomentOfInertia, momentum::Momentum, power::Power, power_rate::PowerRate, pressure::Pressure, radiant_exposure::RadiantExposure, radioactivity::Radioactivity, ratio::Ratio, reciprocal_length::ReciprocalLength, solid_angle::SolidAngle, specific_area::SpecificArea, specific_heat_capacity::SpecificHeatCapacity, specific_power::SpecificPower, specific_radioactivity::SpecificRadioactivity, specific_volume::SpecificVolume, surface_electric_current_density::SurfaceElectricCurrentDensity, temperature_coefficient::TemperatureCoefficient, temperature_gradient::TemperatureGradient, temperature_interval::TemperatureInterval, thermal_conductance::ThermalConductance, thermal_conductivity::ThermalConductivity, thermodynamic_temperature::ThermodynamicTemperature, time::Time, torque::Torque, velocity::Velocity, volume::Volume, volume_rate::VolumeRate, volumetric_density_of_states::VolumetricDensityOfStates, volumetric_heat_capacity::VolumetricHeatCapacity, volumetric_number_density::VolumetricNumberDensity, volumetric_number_rate::VolumetricNumberRate, volumetric_power_density::VolumetricPowerDensity, } } /// [`Quantity`](struct.Quantity.html) type aliases using the default base units and parameterized /// on the underlying storage type. pub mod quantities { ISQ!(crate::si); } storage_types! { /// [`Quantity`](struct.Quantity.html) type aliases using the default base units. pub types: All; ISQ!(crate::si, V); } /// Primitive traits and types representing basic properties of types specific to the SI. pub mod marker { use super::{Dimension, Quantity, Units}; use crate::Kind; /// `AngleKind` is a `Kind` for separating angular quantities from their identically dimensioned /// non-angular quantity counterparts. Conversions to and from `AngleKind` quantities are /// supported through implementations of the `From` trait. /// #[cfg_attr(feature = "f32", doc = " ```rust")] #[cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::angle::radian; /// let a: Angle = Angle::new::(1.0); /// let r: Ratio = a.into(); /// ``` pub trait AngleKind: Kind {} /// `SolidAngleKind` is a `Kind` for separating quantities of solid angles from other /// identically dimensioned quantities. Conversions to and from `SolidAngleKind` quantities are /// supported through implementations of the `From` trait. /// #[cfg_attr(feature = "f32", doc = " ```rust")] #[cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::solid_angle::steradian; /// let a: SolidAngle = SolidAngle::new::(1.0); /// let r: Ratio = a.into(); /// ``` pub trait SolidAngleKind: Kind {} /// `InformationKind` is a `Kind` for separating information quantities from their identically /// dimensioned non-information quantity counterparts. Conversions to and from `InformationKind` /// quantities are supported through implementations of the `From` trait. /// #[cfg_attr(feature = "f32", doc = " ```rust")] #[cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::information::kilobyte; /// let i: Information = Information::new::(1.0); /// let r: Ratio = i.into(); /// ``` pub trait InformationKind: Kind {} /// Kind of thermodynamic temperature. pub trait TemperatureKind: crate::marker::Mul + crate::marker::MulAssign + crate::marker::Div + crate::marker::DivAssign + crate::marker::Rem + crate::marker::RemAssign { } /// Kind of constituent concentration in chemical mixtures, which separates mass concentration /// from mass density. This `Kind` is also applied to molar concentration and to catalytic /// activity concentration. pub trait ConstituentConcentrationKind: Kind {} /// `impl_from` generates generic inter-Kind implementations of `From`. #[cfg(feature = "autoconvert")] #[macro_export] macro_rules! impl_from { ($a:ident, $b:ident) => { impl From< Quantity< dyn Dimension< L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = dyn $a, >, Ur, V, >, > for Quantity< dyn Dimension, Ul, V, > where L: $crate::typenum::Integer, M: $crate::typenum::Integer, T: $crate::typenum::Integer, I: $crate::typenum::Integer, Th: $crate::typenum::Integer, N: $crate::typenum::Integer, J: $crate::typenum::Integer, Ul: Units + ?Sized, Ur: Units + ?Sized, V: $crate::num_traits::Num + $crate::Conversion, { fn from( val: Quantity< dyn Dimension< L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = dyn $a, >, Ur, V, >, ) -> Quantity< dyn Dimension, Ul, V, > { Self { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: super::change_base::< dyn Dimension< L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = dyn $b, >, Ul, Ur, V, >(&val.value), } } } }; } /// `impl_from` generates generic inter-Kind implementations of `From`. #[cfg(not(feature = "autoconvert"))] #[macro_export] macro_rules! impl_from { ($a:ident, $b:ident) => { impl From< Quantity< dyn Dimension< L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = dyn $a, >, U, V, >, > for Quantity< dyn Dimension, U, V, > where L: $crate::typenum::Integer, M: $crate::typenum::Integer, T: $crate::typenum::Integer, I: $crate::typenum::Integer, Th: $crate::typenum::Integer, N: $crate::typenum::Integer, J: $crate::typenum::Integer, U: Units + ?Sized, V: $crate::num_traits::Num + $crate::Conversion, { fn from( val: Quantity< dyn Dimension< L = L, M = M, T = T, I = I, Th = Th, N = N, J = J, Kind = dyn $a, >, U, V, >, ) -> Quantity< dyn Dimension, U, V, > { Self { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: val.value, } } } }; } impl_from!(AngleKind, Kind); impl_from!(Kind, AngleKind); impl_from!(SolidAngleKind, Kind); impl_from!(Kind, SolidAngleKind); impl_from!(InformationKind, Kind); impl_from!(Kind, InformationKind); impl_from!(ConstituentConcentrationKind, Kind); impl_from!(Kind, ConstituentConcentrationKind); } uom-0.35.0/src/si/molality.rs000064400000000000000000000030741046102023000141170ustar 00000000000000//! Molality (base unit mole per kilogram, kg⁻¹ · mol). quantity! { /// Molality (base unit mole per kilogram, kg⁻¹ · mol). quantity: Molality; "molality"; /// Dimension of molality, M⁻¹N (base unit mole per kilogram, kg⁻¹ · mol). dimension: ISQ< Z0, // length N1, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature P1, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @mole_per_kilogram: prefix!(none); "mol/kg", "mole per kilogram", "moles per kilogram"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::amount_of_substance as aos; use crate::si::mass as m; use crate::si::molality as mol; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: Molality = (AmountOfSubstance::new::(V::one()) / Mass::new::(V::one())).into(); } #[test] fn check_units() { test::(); fn test, M: m::Conversion, MOL: mol::Conversion>() { Test::assert_approx_eq(&Molality::new::(V::one()), &(AmountOfSubstance::new::(V::one()) / Mass::new::(V::one())).into()); } } } } uom-0.35.0/src/si/molar_concentration.rs000064400000000000000000000337241046102023000163320ustar 00000000000000//! Molar concentration (base unit mole per cubic meter, mol · m⁻³). quantity! { /// Molar concentration (base unit mole per cubic meter, mol · m⁻³). quantity: MolarConcentration; "molar concentration"; /// Dimension of molar concentration, L⁻³N (base unit mole per cubic meter, mol · m⁻³). dimension: ISQ< N3, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature P1, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @yottamole_per_cubic_meter: prefix!(yotta); "Ymol/m³", "yottamole per cubic meter", "yottamoles per cubic meter"; @zettamole_per_cubic_meter: prefix!(zetta); "Zmol/m³", "zettamole per cubic meter", "zettamoles per cubic meter"; @examole_per_cubic_meter: prefix!(exa); "Emol/m³", "examole per cubic meter", "examoles per cubic meter"; @petamole_per_cubic_meter: prefix!(peta); "Pmol/m³", "petamole per cubic meter", "petamoles per cubic meter"; @teramole_per_cubic_meter: prefix!(tera); "Tmol/m³", "teramole per cubic meter", "teramoles per cubic meter"; @gigamole_per_cubic_meter: prefix!(giga); "Gmol/m³", "gigamole per cubic meter", "gigamoles per cubic meter"; @megamole_per_cubic_meter: prefix!(mega); "Mmol/m³", "megamole per cubic meter", "megamoles per cubic meter"; @kilomole_per_cubic_meter: prefix!(kilo); "kmol/m³", "kilomole per cubic meter", "kilomoles per cubic meter"; @hectomole_per_cubic_meter: prefix!(hecto); "hmol/m³", "hectomole per cubic meter", "hectomoles per cubic meter"; @decamole_per_cubic_meter: prefix!(deca); "damol/m³", "decamole per cubic meter", "decamoles per cubic meter"; @mole_per_cubic_meter: prefix!(none); "mol/m³", "mole per cubic meter", "moles per cubic meter"; @decimole_per_cubic_meter: prefix!(deci); "dmol/m³", "decimole per cubic meter", "decimoles per cubic meter"; @centimole_per_cubic_meter: prefix!(centi); "cmol/m³", "centimole per cubic meter", "centimoles per cubic meter"; @millimole_per_cubic_meter: prefix!(milli); "mmol/m³", "millimole per cubic meter", "millimoles per cubic meter"; @micromole_per_cubic_meter: prefix!(micro); "µmol/m³", "micromole per cubic meter", "micromoles per cubic meter"; @nanomole_per_cubic_meter: prefix!(nano); "nmol/m³", "nanomole per cubic meter", "nanomoles per cubic meter"; @picomole_per_cubic_meter: prefix!(pico); "pmol/m³", "picomole per cubic meter", "picomoles per cubic meter"; @femtomole_per_cubic_meter: prefix!(femto); "fmol/m³", "femtomole per cubic meter", "femtomoles per cubic meter"; @attomole_per_cubic_meter: prefix!(atto); "amol/m³", "attomole per cubic meter", "attomoles per cubic meter"; @zeptomole_per_cubic_meter: prefix!(zepto); "zmol/m³", "zeptomole per cubic meter", "zeptomoles per cubic meter"; @yoctomole_per_cubic_meter: prefix!(yocto); "ymol/m³", "yoctomole per cubic meter", "yoctomoles per cubic meter"; @kilomole_per_cubic_decimeter: prefix!(kilo) / prefix!(deci) / prefix!(deci) / prefix!(deci); "kmol/dm³", "kilomole per cubic decimeter", "kilomoles per cubic decimeter"; @kilomole_per_liter: prefix!(kilo) / prefix!(milli); "kmol/L", "kilomole per liter", "kilomoles per liter"; @mole_per_cubic_decimeter: prefix!(none) / prefix!(deci) / prefix!(deci) / prefix!(deci); "mol/dm³", "mole per cubic decimeter", "moles per cubic decimeter"; @mole_per_liter: prefix!(none) / prefix!(milli); "mol/L", "mole per liter", "moles per liter"; @millimole_per_cubic_decimeter: prefix!(milli) / prefix!(deci) / prefix!(deci) / prefix!(deci); "mmol/dm³", "millimole per cubic decimeter", "millimoles per cubic decimeter"; @millimole_per_liter: prefix!(milli) / prefix!(milli); "mmol/L", "millimole per liter", "millimoles per liter"; @micromole_per_cubic_decimeter: prefix!(micro) / prefix!(deci) / prefix!(deci) / prefix!(deci); "μmol/dm³", "micromole per cubic decimeter", "micromoles per cubic decimeter"; @micromole_per_liter: prefix!(micro) / prefix!(milli); "μmol/L", "micromole per liter", "micromoles per liter"; @nanomole_per_cubic_decimeter: prefix!(nano) / prefix!(deci) / prefix!(deci) / prefix!(deci); "nmol/dm³", "nanomole per cubic decimeter", "nanomoles per cubic decimeter"; @nanomole_per_liter: prefix!(nano) / prefix!(milli); "nmol/L", "nanomole per liter", "nanomoles per liter"; @picomole_per_cubic_decimeter: prefix!(pico) / prefix!(deci) / prefix!(deci) / prefix!(deci); "pmol/dm³", "picomole per cubic decimeter", "picomoles per cubic decimeter"; @picomole_per_liter: prefix!(pico) / prefix!(milli); "pmol/L", "picomole per liter", "picomoles per liter"; @femtomole_per_cubic_decimeter: prefix!(femto) / prefix!(deci) / prefix!(deci) / prefix!(deci); "fmol/dm³", "femtomole per cubic decimeter", "femtomoles per cubic decimeter"; @femtomole_per_liter: prefix!(femto) / prefix!(milli); "fmol/L", "femtomole per liter", "femtomoles per liter"; @kilomole_per_deciliter: prefix!(kilo) / prefix!(deci) / prefix!(milli); "kmol/dL", "kilomole per deciliter", "kilomoles per deciliter"; @mole_per_deciliter: prefix!(none) / prefix!(deci) / prefix!(milli); "mol/dL", "mole per deciliter", "moles per deciliter"; @millimole_per_deciliter: prefix!(milli) / prefix!(deci) / prefix!(milli); "mmol/dL", "millimole per deciliter", "millimoles per deciliter"; @micromole_per_deciliter: prefix!(micro) / prefix!(deci) / prefix!(milli); "μmol/dL", "micromole per deciliter", "micromoles per deciliter"; @nanomole_per_deciliter: prefix!(nano) / prefix!(deci) / prefix!(milli); "nmol/dL", "nanomole per deciliter", "nanomoles per deciliter"; @picomole_per_deciliter: prefix!(pico) / prefix!(deci) / prefix!(milli); "pmol/dL", "picomole per deciliter", "picomoles per deciliter"; @femtomole_per_deciliter: prefix!(femto) / prefix!(deci) / prefix!(milli); "fmol/dL", "femtomole per deciliter", "femtomoles per deciliter"; @kilomole_per_milliliter: prefix!(kilo) / prefix!(milli) / prefix!(milli); "kmol/mL", "kilomole per milliliter", "kilomoles per milliliter"; @mole_per_milliliter: prefix!(none) / prefix!(milli) / prefix!(milli); "mol/mL", "mole per milliliter", "moles per milliliter"; @millimole_per_milliliter: prefix!(milli) / prefix!(milli) / prefix!(milli); "mmol/mL", "millimole per milliliter", "millimoles per milliliter"; @micromole_per_milliliter: prefix!(micro) / prefix!(milli) / prefix!(milli); "μmol/mL", "micromole per milliliter", "micromoles per milliliter"; @nanomole_per_milliliter: prefix!(nano) / prefix!(milli) / prefix!(milli); "nmol/mL", "nanomole per milliliter", "nanomoles per milliliter"; @picomole_per_milliliter: prefix!(pico) / prefix!(milli) / prefix!(milli); "pmol/mL", "picomole per milliliter", "picomoles per milliliter"; @femtomole_per_milliliter: prefix!(femto) / prefix!(milli) / prefix!(milli); "fmol/mL", "femtomole per milliliter", "femtomoles per milliliter"; @particle_per_cubic_meter: 1.0_E0 / 6.022_140_76_E23; "particle/m³", "particle per cubic meter", "particles per cubic meter"; @particle_per_cubic_decimeter: 1.0_E0 / 6.022_140_76_E23 / prefix!(deci) / prefix!(deci) / prefix!(deci); "particle/dm³", "particle per cubic decimeter", "particles per cubic decimeter"; @particle_per_liter: 1.0_E0 / 6.022_140_76_E23 / prefix!(milli); "particle/L", "particle per liter", "particles per liter"; @particle_per_deciliter: 1.0_E0 / 6.022_140_76_E23 / prefix!(deci) / prefix!(milli); "particle/dL", "particle per deciliter", "particles per deciliter"; @particle_per_milliliter: 1.0_E0 / 6.022_140_76_E23 / prefix!(milli) / prefix!(milli); "particle/mL", "particle per milliliter", "particles per milliliter"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::amount_of_substance as aos; use crate::si::molar_concentration as c; use crate::si::quantities::*; use crate::si::volume as v; use crate::tests::Test; #[test] fn check_dimension() { let _: MolarConcentration = (AmountOfSubstance::new::(V::one()) / Volume::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, U: v::Conversion, C: c::Conversion>() { Test::assert_approx_eq(&MolarConcentration::new::(V::one()), &(AmountOfSubstance::new::(V::one()) / Volume::new::(V::one())).into()); } } } } uom-0.35.0/src/si/molar_energy.rs000064400000000000000000000321761046102023000147550ustar 00000000000000//! Molar energy (base unit joule per mole, kg · m² · s⁻² · mol⁻¹). quantity! { /// Molar energy (base unit joule per mole, kg · m² · s⁻² · mol⁻¹). quantity: MolarEnergy; "molar energy"; /// Dimension of molar energy, L²MT⁻²N⁻¹ (base unit joule per mole, kg · m² · s⁻² · mol⁻¹). dimension: ISQ< P2, // length P1, // mass N2, // time Z0, // electric current Z0, // thermodynamic temperature N1, // amount of substance Z0>; // luminous intensity units { /// Molar energy expressed in base units. Equivalent to J/mol. @kilogram_square_meter_per_second_squared_mole: prefix!(kilo) / prefix!(kilo); "kg · m²/(s² · mol)", "kilogram square meter per second squared mole", "kilograms square meter per second squared mole"; // Molar energy is commonly expressed in terms of derived unit joule @yottajoule_per_mole: prefix!(yotta); "YJ/mol", "yottajoule per mole", "yottajoules per mole"; @zettajoule_per_mole: prefix!(zetta); "ZJ/mol", "zettajoule per mole", "zettajoules per mole"; @exajoule_per_mole: prefix!(exa); "EJ/mol", "exajoule per mole", "exajoules per mole"; @petajoule_per_mole: prefix!(peta); "PJ/mol", "petajoule per mole", "petajoules per mole"; @terajoule_per_mole: prefix!(tera); "TJ/mol", "terajoule per mole", "terajoules per mole"; @gigajoule_per_mole: prefix!(giga); "GJ/mol", "gigajoule per mole", "gigajoules per mole"; @megajoule_per_mole: prefix!(mega); "MJ/mol", "megajoule per mole", "megajoules per mole"; @kilojoule_per_mole: prefix!(kilo); "kJ/mol", "kilojoule per mole", "kilojoules per mole"; @hectojoule_per_mole: prefix!(hecto); "hJ/mol", "hectojoule per mole", "hectojoules per mole"; @decajoule_per_mole: prefix!(deca); "daJ/mol", "decajoule per mole", "decajoules per mole"; /// The derived unit of molar energy. Equivalent to kg · m²/(s² · mol). @joule_per_mole: prefix!(none); "J/mol", "joule per mole", "joules per mole"; @decijoule_per_mole: prefix!(deci); "dJ/mol", "decijoule per mole", "decijoules per mole"; @centijoule_per_mole: prefix!(centi); "cJ/mol", "centijoule per mole", "centijoules per mole"; @millijoule_per_mole: prefix!(milli); "mJ/mol", "millijoule per mole", "millijoules per mole"; @microjoule_per_mole: prefix!(micro); "µJ/mol", "microjoule per mole", "microjoules per mole"; @nanojoule_per_mole: prefix!(nano); "nJ/mol", "nanojoule per mole", "nanojoules per mole"; @picojoule_per_mole: prefix!(pico); "pJ/mol", "picojoule per mole", "picojoules per mole"; @femtojoule_per_mole: prefix!(femto); "fJ/mol", "femtojoule per mole", "femtojoules per mole"; @attojoule_per_mole: prefix!(atto); "aJ/mol", "attojoule per mole", "attojoules per mole"; @zeptojoule_per_mole: prefix!(zepto); "zJ/mol", "zeptojoule per mole", "zeptojoules per mole"; @yoctojoule_per_mole: prefix!(yocto); "yJ/mol", "yoctojoule per mole", "yoctojoules per mole"; @petawatt_hour_per_mole: 3.6_E18; "PW · h/mol", "petawatt hour per mole", "petawatt hours per mole"; @terawatt_hour_per_mole: 3.6_E15; "TW · h/mol", "terawatt hour per mole", "terawatt hours per mole"; @gigawatt_hour_per_mole: 3.6_E12; "GW · h/mol", "gigawatt hour per mole", "gigawatt hours per mole"; @megawatt_hour_per_mole: 3.6_E9; "MW · h/mol", "megawatt hour per mole", "megawatt hours per mole"; @kilowatt_hour_per_mole: 3.6_E6; "kW · h/mol", "kilowatt hour per mole", "kilowatt hours per mole"; @hectowatt_hour_per_mole: 3.6_E5; "hW · h/mol", "hectowatt hour per mole", "hectowatt hours per mole"; @decawatt_hour_per_mole: 3.6_E4; "daW · h/mol", "decawatt hour per mole", "decawatt hours per mole"; @watt_hour_per_mole: 3.6_E3; "W · h/mol", "watt hour per mole", "watt hours per mole"; @milliwatt_hour_per_mole: 3.6_E0; "mW · h/mol", "milliwatt hour per mole", "milliwatt hours per mole"; @microwatt_hour_per_mole: 3.6_E-3; "µW · h/mol", "microwatt hour per mole", "microwatt hours per mole"; @btu_it_per_mole: 1.055_056_E3; "Btu (IT)/mol", "British thermal unit (IT) per mole", "British thermal units (IT) per mole"; @btu_per_mole: 1.054_350_E3; "Btu/mol", "British thermal unit per mole", "British thermal units per mole"; @btu_39_per_mole: 1.059_67_E3; "Btu₃₉/mol", "British thermal unit (39 °F) per mole", "British thermal units (39 °F) per mole"; @btu_59_per_mole: 1.054_80_E3; "Btu₅₉/mol", "British thermal unit (59 °F) per mole", "British thermal units (59 °F) per mole"; @btu_60_per_mole: 1.054_68_E3; "Btu₆₀/mol", "British thermal unit (60 °F) per mole", "British thermal units (60 °F) per mole"; @calorie_it_per_mole: 4.186_8_E0; "cal (IT)/mol", "calorie (IT) per mole", "calories (IT) per mole"; @calorie_per_mole: 4.184_E0; "cal/mol", "calorie per mole", "calories per mole"; @calorie_15_per_mole: 4.185_80_E0; "cal₁₅/mol", "calorie (15 °C) per mole", "calories (15 °C) per mole"; @calorie_20_per_mole: 4.181_90_E0; "cal₂₀/mol", "calorie (20 °C) per mole", "calories (20 °C) per mole"; @calorie_it_nutrition_per_mole: 4.186_8_E3; "Cal (IT)/mol", "Calorie (IT) per mole", "Calories (IT) per mole"; @calorie_nutrition_per_mole: 4.184_E3; "Cal/mol", "Calorie per mole", "Calories per mole"; @electronvolt_per_mole: 1.602_176_634_E-19; "eV/mol", "electronvolt per mole", "electronvolts per mole"; @erg_per_mole: 1.0_E-7; "erg/mol", "erg per mole", "ergs per mole"; @foot_poundal_per_mole: 4.214_011_E-2; "ft · pdl/mol", "foot poundal per mole", "foot poundals per mole"; @foot_pound_force_per_mole: 1.355_818_E0; "ft · lbf/mol", "foot pound-force per mole", "foot pounds-force per mole"; @kilocalorie_it_per_mole: 4.186_8_E3; "kcal (IT)/mol", "kilocalorie (IT) per mole", "kilocalories (IT) per mole"; @kilocalorie_per_mole: 4.184_E3; "kcal/mol", "kilocalorie per mole", "kilocalories per mole"; @quad_per_mole: 1.055_056_E18; "10¹⁵ Btu (IT)/mol", "quad per mole", "quads per mole"; @therm_ec_per_mole: 1.055_06_E8; "thm (EC)/mol", "therm (EC) per mole", "therms (EC) per mole"; @therm_us_per_mole: 1.054_804_E8; "thm/mol", "therm per mole", "therms per mole"; @ton_tnt_per_mole: 4.184_E9; "t of TNT/mol", "ton of TNT per mole", "tons of TNT per mole"; @watt_second_per_mole: 1.0_E0; "W · s/mol", "watt second per mole", "watt seconds per mole"; @joule_per_particle: 6.022_140_76_E23; "J/particle", "joule per particle", "joules per particle"; @electronvolt_per_particle: 1.602_176_634_E-19 * 6.022_140_76_E23; "eV/particle", "electronvolt per particle", "electronvolts per particle"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::amount_of_substance as aos; use crate::si::energy as e; use crate::si::length as l; use crate::si::mass as m; use crate::si::molar_energy as me; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _base: MolarEnergy = Mass::new::(V::one()) * Length::new::(V::one()) * Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * AmountOfSubstance::new::(V::one())); let _derived: MolarEnergy = Energy::new::(V::one()) / AmountOfSubstance::new::(V::one()); } #[test] fn check_base_units() { test::(); fn test, A: aos::Conversion, ME: me::Conversion>() { Test::assert_approx_eq(&MolarEnergy::new::(V::one()), &(Mass::new::(V::one()) * Length::new::(V::one()) * Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * AmountOfSubstance::new::(V::one())))); } } #[test] fn check_derived_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, AOS: aos::Conversion, ME: me::Conversion>() { Test::assert_approx_eq(&MolarEnergy::new::(V::one()), &(Energy::new::(V::one()) / AmountOfSubstance::new::(V::one()))); } } } } uom-0.35.0/src/si/molar_flux.rs000064400000000000000000000034561046102023000144410ustar 00000000000000//! Molar flux (base unit mole per square meter second, m⁻² · s⁻¹ · mol). quantity! { /// Molar flux (base unit mole per square meter second, m⁻² · s⁻¹ · mol). quantity: MolarFlux; "molar flux"; /// Dimension of molar flux, L⁻²T⁻¹N (base unit mole per square meter second, m⁻² · s⁻¹ · mol). dimension: ISQ< N2, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature P1, // amount of substance Z0>; // luminous intensity units { @mole_per_square_meter_second: prefix!(none); "mol/(m² · s)", "mole per square meter second", "moles per square meter second"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::amount_of_substance as aos; use crate::si::molar_flux as mf; use crate::si::quantities::*; use crate::si::time as t; use crate::si::area as area; use crate::tests::Test; #[test] fn check_dimension() { let _: MolarFlux = AmountOfSubstance::new::(V::one()) / Time::new::(V::one()) / Area::new::(V::one()); } #[test] fn check_units() { test::(); fn test, T: t::Conversion, A: area::Conversion, R: mf::Conversion>() { Test::assert_approx_eq(&MolarFlux::new::(V::one()), &(AmountOfSubstance::new::(V::one()) / Time::new::(V::one()) / Area::new::(V::one()))); } } } } uom-0.35.0/src/si/molar_heat_capacity.rs000064400000000000000000000244551046102023000162630ustar 00000000000000//! Molar heat capacity (base unit joule per kelvin mole, m² · kg · s⁻² · K⁻¹ · mol⁻¹). quantity! { /// Molar heat capacity (base unit joule per kelvin mole, m² · kg · s⁻² · K⁻¹ · mol⁻¹). quantity: MolarHeatCapacity; "molar heat capacity"; /// Dimension of molar heat capacity, L²MT⁻²Th⁻¹N⁻¹ (base unit joule per kelvin mole, /// m² · kg · s⁻² · K⁻¹ · mol⁻¹). dimension: ISQ< P2, // length P1, // mass N2, // time Z0, // electric current N1, // thermodynamic temperature N1, // amount of substance Z0>; // luminous intensity units { @yottajoule_per_kelvin_mole: prefix!(yotta); "YJ/(K · mol)", "yottajoule per kelvin mole", "yottajoules per kelvin mole"; @zettajoule_per_kelvin_mole: prefix!(zetta); "ZJ/(K · mol)", "zettajoule per kelvin mole", "zettajoules per kelvin mole"; @exajoule_per_kelvin_mole: prefix!(exa); "EJ/(K · mol)", "exajoule per kelvin mole", "exajoules per kelvin mole"; @petajoule_per_kelvin_mole: prefix!(peta); "PJ/(K · mol)", "petajoule per kelvin mole", "petajoules per kelvin mole"; @terajoule_per_kelvin_mole: prefix!(tera); "TJ/(K · mol)", "terajoule per kelvin mole", "terajoules per kelvin mole"; @gigajoule_per_kelvin_mole: prefix!(giga); "GJ/(K · mol)", "gigajoule per kelvin mole", "gigajoules per kelvin mole"; @megajoule_per_kelvin_mole: prefix!(mega); "MJ/(K · mol)", "megajoule per kelvin mole", "megajoules per kelvin mole"; @kilojoule_per_kelvin_mole: prefix!(kilo); "kJ/(K · mol)", "kilojoule per kelvin mole", "kilojoules per kelvin mole"; @hectojoule_per_kelvin_mole: prefix!(hecto); "hJ/(K · mol)", "hectojoule per kelvin mole", "hectojoules per kelvin mole"; @decajoule_per_kelvin_mole: prefix!(deca); "daJ/(K · mol)", "decajoule per kelvin mole", "decajoules per kelvin mole"; /// Derived unit of molar heat capacity. @joule_per_kelvin_mole: prefix!(none); "J/(K · mol)", "joule per kelvin mole", "joules per kelvin mole"; @decijoule_per_kelvin_mole: prefix!(deci); "dJ/(K · mol)", "decijoule per kelvin mole", "decijoules per kelvin mole"; @centijoule_per_kelvin_mole: prefix!(centi); "cJ/(K · mol)", "centijoule per kelvin mole", "centijoules per kelvin mole"; @millijoule_per_kelvin_mole: prefix!(milli); "mJ/(K · mol)", "millijoule per kelvin mole", "millijoules per kelvin mole"; @microjoule_per_kelvin_mole: prefix!(micro); "µJ/(K · mol)", "microjoule per kelvin mole", "microjoules per kelvin mole"; @nanojoule_per_kelvin_mole: prefix!(nano); "nJ/(K · mol)", "nanojoule per kelvin mole", "nanojoules per kelvin mole"; @picojoule_per_kelvin_mole: prefix!(pico); "pJ/(K · mol)", "picojoule per kelvin mole", "picojoules per kelvin mole"; @femtojoule_per_kelvin_mole: prefix!(femto); "fJ/(K · mol)", "femtojoule per kelvin mole", "femtojoules per kelvin mole"; @attojoule_per_kelvin_mole: prefix!(atto); "aJ/(K · mol)", "attojoule per kelvin mole", "attojoules per kelvin mole"; @zeptojoule_per_kelvin_mole: prefix!(zepto); "zJ/(K · mol)", "zeptojoule per kelvin mole", "zeptojoules per kelvin mole"; @yoctojoule_per_kelvin_mole: prefix!(yocto); "yJ/(K · mol)", "yoctojoule per kelvin mole", "yoctojoules per kelvin mole"; @btu_it_per_kelvin_mole: 1.055_056_E3; "Btu (IT)/(K · mol)", "British thermal unit (IT) per kelvin mole", "British thermal units (IT) per kelvin mole"; @btu_per_kelvin_mole: 1.054_350_E3; "Btu/(K · mol)", "British thermal unit per kelvin mole", "British thermal units per kelvin mole"; @btu_39_per_kelvin_mole: 1.059_67_E3; "Btu₃₉/(K · mol)", "British thermal unit (39 °F) per kelvin mole", "British thermal units (39 °F) per kelvin mole"; @btu_59_per_kelvin_mole: 1.054_80_E3; "Btu₅₉/(K · mol)", "British thermal unit (59 °F) per kelvin mole", "British thermal units (59 °F) per kelvin mole"; @btu_60_per_kelvin_mole: 1.054_68_E3; "Btu₆₀/(K · mol)", "British thermal unit (60 °F) per kelvin mole", "British thermal units (60 °F) per kelvin mole"; @calorie_it_per_kelvin_mole: 4.186_8_E0; "cal (IT)/(K · mol)", "calorie (IT) per kelvin mole", "calories (IT) per kelvin mole"; @calorie_per_kelvin_mole: 4.184_E0; "cal/(K · mol)", "calorie per kelvin mole", "calories per kelvin mole"; @calorie_15_per_kelvin_mole: 4.185_80_E0; "cal₁₅/(K · mol)", "calorie (15 °C) per kelvin mole", "calories (15 °C) per kelvin mole"; @calorie_20_per_kelvin_mole: 4.181_90_E0; "cal₂₀/(K · mol)", "calorie (20 °C) per kelvin mole", "calories (20 °C) per kelvin mole"; @calorie_it_nutrition_per_kelvin_mole: 4.186_8_E3; "Cal (IT)/(K · mol)", "Calorie (IT) per kelvin mole", "Calories (IT) per kelvin mole"; @calorie_nutrition_per_kelvin_mole: 4.184_E3; "Cal/(K · mol)", "Calorie per kelvin mole", "Calories per kelvin mole"; @kilocalorie_it_per_kelvin_mole: 4.186_8_E3; "kcal (IT)/(K · mol)", "kilocalorie (IT) per kelvin mole", "kilocalories (IT) per kelvin mole"; @kilocalorie_per_kelvin_mole: 4.184_E3; "kcal/(K · mol)", "kilocalorie per kelvin mole", "kilocalories per kelvin mole"; @joule_per_kelvin_particle: 6.022_140_76_E23; "J/(K · particle)", "joule per kelvin particle", "joules per kelvin particle"; @electronvolt_per_kelvin_particle: 6.022_140_76_E23 * 1.602_176_634_E-19; "eV/(K · particle)", "electronvolt per kelvin particle", "electronvolts per kelvin particle"; @molar_gas_constant: 8.314_462_618_E0; "R", "molar gas constant", "molar gas constants"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::amount_of_substance as aos; use crate::si::energy as e; use crate::si::molar_heat_capacity as m; use crate::si::quantities::*; use crate::si::temperature_interval as t; use crate::tests::Test; #[test] fn check_dimension() { let _: MolarHeatCapacity = Energy::new::(V::one()) / (TemperatureInterval::new::(V::one()) * AmountOfSubstance::new::(V::one())); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, AOS: aos::Conversion, M: m::Conversion>() { Test::assert_approx_eq(&MolarHeatCapacity::new::(V::one()), &(Energy::new::(V::one()) / (TemperatureInterval::new::(V::one()) * AmountOfSubstance::new::(V::one())))); } } } } uom-0.35.0/src/si/molar_mass.rs000064400000000000000000000121661046102023000144240ustar 00000000000000//! Molar mass (base unit kilogram per mole, kg · mol⁻¹). quantity! { /// Molar mass (base unit kilogram per mole, kg · mol⁻¹). quantity: MolarMass; "molar mass"; /// Dimension of molar mass, MN⁻¹ (base unit kilogram per mole, kg · mol⁻¹). dimension: ISQ< Z0, // length P1, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature N1, // amount of substance Z0>; // luminous intensity units { @yottagram_per_mole: prefix!(yotta) / prefix!(kilo); "Yg/mol", "yottagram per mole", "yottagrams per mole"; @zettagram_per_mole: prefix!(zetta) / prefix!(kilo); "Zg/mol", "zettagram per mole", "zettagrams per mole"; @exagram_per_mole: prefix!(exa) / prefix!(kilo); "Eg/mol", "exagram per mole", "exagrams per mole"; @petagram_per_mole: prefix!(peta) / prefix!(kilo); "Pg/mol", "petagram per mole", "petagrams per mole"; @teragram_per_mole: prefix!(tera) / prefix!(kilo); "Tg/mol", "teragram per mole", "teragrams per mole"; @gigagram_per_mole: prefix!(giga) / prefix!(kilo); "Gg/mol", "gigagram per mole", "gigagrams per mole"; @megagram_per_mole: prefix!(mega) / prefix!(kilo); "Mg/mol", "megagram per mole", "megagrams per mole"; /// The derived unit of molar mass. @kilogram_per_mole: prefix!(kilo) / prefix!(kilo); "kg/mol", "kilogram per mole", "kilograms per mole"; @hectogram_per_mole: prefix!(hecto) / prefix!(kilo); "hg/mol", "hectogram per mole", "hectograms per mole"; @decagram_per_mole: prefix!(deca) / prefix!(kilo); "dag/mol", "decagram per mole", "decagrams per mole"; @gram_per_mole: prefix!(none) / prefix!(kilo); "g/mol", "gram per mole", "grams per mole"; @decigram_per_mole: prefix!(deci) / prefix!(kilo); "dg/mol", "decigram per mole", "decigrams per mole"; @centigram_per_mole: prefix!(centi) / prefix!(kilo); "cg/mol", "centigram per mole", "centigrams per mole"; @milligram_per_mole: prefix!(milli) / prefix!(kilo); "mg/mol", "milligram per mole", "milligrams per mole"; @microgram_per_mole: prefix!(micro) / prefix!(kilo); "µg/mol", "microgram per mole", "micrograms per mole"; @nanogram_per_mole: prefix!(nano) / prefix!(kilo); "ng/mol", "nanogram per mole", "nanograms per mole"; @picogram_per_mole: prefix!(pico) / prefix!(kilo); "pg/mol", "picogram per mole", "picograms per mole"; @femtogram_per_mole: prefix!(femto) / prefix!(kilo); "fg/mol", "femtogram per mole", "femtograms per mole"; @attogram_per_mole: prefix!(atto) / prefix!(kilo); "ag/mol", "attogram per mole", "attograms per mole"; @zeptogram_per_mole: prefix!(zepto) / prefix!(kilo); "zg/mol", "zeptogram per mole", "zeptograms per mole"; @yoctogram_per_mole: prefix!(yocto) / prefix!(kilo); "yg/mol", "yoctogram per mole", "yoctograms per mole"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::amount_of_substance as aos; use crate::si::mass as m; use crate::si::molar_mass as mm; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: MolarMass = Mass::new::(V::one()) / AmountOfSubstance::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, MM: mm::Conversion>() { Test::assert_approx_eq(&MolarMass::new::(V::one()), &(Mass::new::(V::one()) / AmountOfSubstance::new::(V::one()))); } } } } uom-0.35.0/src/si/molar_radioactivity.rs000064400000000000000000000042161046102023000163310ustar 00000000000000//! Molar radioactivity (base unit becquerel per mole, s⁻¹ · mol⁻¹). quantity! { /// Molar radioactivity (base unit becquerel per mole, s⁻¹ · mol⁻¹). quantity: MolarRadioactivity; "molar radioactivity"; /// Dimension of molar radioactivity, T⁻¹N⁻¹ (base unit becquerel per mole, s⁻¹ · mol⁻¹). dimension: ISQ< Z0, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature N1, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @becquerel_per_mole: prefix!(none); "Bq/mol", "becquerel per mole", "becquerels per mole"; @curie_per_mole: 3.7_E10; "Ci/mol", "curie per mole", "curies per mole"; @disintegrations_per_minute_per_mole: 1.0 / 6.0_E1; "dpm/mol", "disintegration per minute per mole", "disintegrations per minute per mole"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::radioactivity as rad; use crate::si::molar_radioactivity as mrad; use crate::si::quantities::*; use crate::si::amount_of_substance as aos; use crate::tests::Test; #[test] fn check_dimension() { let _: MolarRadioactivity = (Radioactivity::new::(V::one()) / AmountOfSubstance::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); fn test, AOS: aos::Conversion, SRAD: mrad::Conversion>() { Test::assert_approx_eq(&MolarRadioactivity::new::(V::one()), &(Radioactivity::new::(V::one()) / AmountOfSubstance::new::(V::one())).into()); } } } } uom-0.35.0/src/si/molar_volume.rs000064400000000000000000000055301046102023000147650ustar 00000000000000//! Molar volume (base unit cubic meter per mole, m³ · mol⁻¹). quantity! { /// Molar volume (base unit cubic meter per mole, m³ · mol⁻¹). quantity: MolarVolume; "molar volume"; /// Dimension of molar volume, L³N⁻¹ (base unit cubic meter per mole, m³ · mol⁻¹). dimension: ISQ< P3, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature N1, // amount of substance Z0>; // luminous intensity units { @cubic_meter_per_mole: prefix!(none); "m³/mol", "cubic meter per mole", "cubic meters per mole"; @cubic_decimeter_per_mole: prefix!(deci) * prefix!(deci) * prefix!(deci); "dm³/mol", "cubic decimeter per mole", "cubic decimeters per mole"; @cubic_centimeter_per_mole: prefix!(centi) * prefix!(centi) * prefix!(centi); "cm³/mol", "cubic centimeter per mole", "cubic centimeters per mole"; @cubic_meter_per_particle: 6.022_140_76_E23; "m³/particle", "cubic meter per particle", "cubic meters per particle"; @cubic_micrometer_per_particle: prefix!(micro) * prefix!(micro) * prefix!(micro) * 6.022_140_76_E23; "µm³/particle", "cubic micrometer per particle", "cubic micrometers per particle"; @cubic_nanometer_per_particle: prefix!(nano) * prefix!(nano) * prefix!(nano) * 6.022_140_76_E23; "nm³/particle", "cubic nanometer per particle", "cubic nanometers per particle"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::amount_of_substance as aos; use crate::si::molar_volume as mv; use crate::si::quantities::*; use crate::si::volume as v; use crate::tests::Test; #[test] fn check_dimension() { let _: MolarVolume = Volume::new::(V::one()) / AmountOfSubstance::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); fn test, AOS: aos::Conversion, MV: mv::Conversion>() { Test::assert_approx_eq(&MolarVolume::new::(V::one()), &(Volume::new::(V::one()) / AmountOfSubstance::new::(V::one()))); } } } } uom-0.35.0/src/si/moment_of_inertia.rs000064400000000000000000000035471046102023000157700ustar 00000000000000//! Moment of inertia (base unit kilogram square meter, kg · m² ). quantity! { /// Moment of inertia (base unit kilogram square meter, kg · m² ). quantity: MomentOfInertia; "moment of inertia"; /// Dimension of moment of inertia, L²M (base unit kilogram square meter, kg · m² ). dimension: ISQ< P2, // length P1, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @kilogram_square_meter: prefix!(none); "kg · m²", "kilogram square meter", "kilogram square meters"; @dalton_square_angstrom: 1.660_539_066_60_E-27 * 1_E-20; "Da · Ų", "dalton square ångström", "dalton square ångströms"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::moment_of_inertia as moi; use crate::si::quantities::*; use crate::si::length as l; use crate::si::mass as m; use crate::tests::Test; #[test] fn check_dimension() { let _: MomentOfInertia = Mass::new::(V::one()) * Length::new::(V::one()) * Length::new::(V::one()); } #[test] fn check_units() { test::(); test::(); fn test, L: l::Conversion, MOI: moi::Conversion>() { Test::assert_approx_eq(&MomentOfInertia::new::(V::one()), &(Mass::new::(V::one()) * Length::new::(V::one()) * Length::new::(V::one()))); } } } } uom-0.35.0/src/si/momentum.rs000064400000000000000000000320141046102023000141220ustar 00000000000000//! Momentum (base unit kilogram meter per second, kg · m · s⁻¹). quantity! { /// Momentum (base unit kilogram meter per second, kg · m · s⁻¹). quantity: Momentum; "momentum"; /// Dimension of momentum, LMT⁻¹ (base unit kilogram meter per second, kg · m · s⁻¹). dimension: ISQ< P1, // length P1, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottagram_meter_per_second: prefix!(yotta) / prefix!(kilo); "Yg · m/s", "yottagram meter per second", "yottagram meters per second"; @zettagram_meter_per_second: prefix!(zetta) / prefix!(kilo); "Zg · m/s", "zettagram meter per second", "zettagram meters per second"; @exagram_meter_per_second: prefix!(exa) / prefix!(kilo); "Eg · m/s", "exagram meter per second", "exagram meters per second"; @petagram_meter_per_second: prefix!(peta) / prefix!(kilo); "Pg · m/s", "petagram meter per second", "petagram meters per second"; @teragram_meter_per_second: prefix!(tera) / prefix!(kilo); "Tg · m/s", "teragram meter per second", "teragram meters per second"; @gigagram_meter_per_second: prefix!(giga) / prefix!(kilo); "Gg · m/s", "gigagram meter per second", "gigagram meters per second"; @megagram_meter_per_second: prefix!(mega) / prefix!(kilo); "Mg · m/s", "megagram meter per second", "megagram meters per second"; /// Derived unit of momentum. @kilogram_meter_per_second: prefix!(kilo) / prefix!(kilo); "kg · m/s", "kilogram meter per second", "kilogram meters per second"; @hectogram_meter_per_second: prefix!(hecto) / prefix!(kilo); "hg · m/s", "hectogram meter per second", "hectogram meters per second"; @decagram_meter_per_second: prefix!(deca) / prefix!(kilo); "dag · m/s", "decagram meter per second", "decagram meters per second"; @gram_meter_per_second: prefix!(none) / prefix!(kilo); "g · m/s", "gram meter per second", "gram meters per second"; @decigram_meter_per_second: prefix!(deci) / prefix!(kilo); "dg · m/s", "decigram meter per second", "decigram meters per second"; @centigram_meter_per_second: prefix!(centi) / prefix!(kilo); "cg · m/s", "centigram meter per second", "centigram meters per second"; @milligram_meter_per_second: prefix!(milli) / prefix!(kilo); "mg · m/s", "milligram meter per second", "milligram meters per second"; @microgram_meter_per_second: prefix!(micro) / prefix!(kilo); "µg · m/s", "microgram meter per second", "microgram meters per second"; @nanogram_meter_per_second: prefix!(nano) / prefix!(kilo); "ng · m/s", "nanogram meter per second", "nanogram meters per second"; @picogram_meter_per_second: prefix!(pico) / prefix!(kilo); "pg · m/s", "picogram meter per second", "picogram meters per second"; @femtogram_meter_per_second: prefix!(femto) / prefix!(kilo); "fg · m/s", "femtogram meter per second", "femtogram meters per second"; @attogram_meter_per_second: prefix!(atto) / prefix!(kilo); "ag · m/s", "attogram meter per second", "attogram meters per second"; @zeptogram_meter_per_second: prefix!(zepto) / prefix!(kilo); "zg · m/s", "zeptogram meter per second", "zeptogram meters per second"; @yoctogram_meter_per_second: prefix!(yocto) / prefix!(kilo); "yg · m/s", "yoctogram meter per second", "yoctogram meters per second"; @kilogram_yottameter_per_second: prefix!(yotta); "kg · Ym/s", "kilogram yottameter per second", "kilogram yottameters per second"; @kilogram_zettameter_per_second: prefix!(zetta); "kg · Zm/s", "kilogram zettameter per second", "kilogram zettameters per second"; @kilogram_exameter_per_second: prefix!(exa); "kg · Em/s", "kilogram exameter per second", "kilogram exameters per second"; @kilogram_petameter_per_second: prefix!(peta); "kg · Pm/s", "kilogram petameter per second", "kilogram petameters per second"; @kilogram_terameter_per_second: prefix!(tera); "kg · Tm/s", "kilogram terameter per second", "kilogram terameters per second"; @kilogram_gigameter_per_second: prefix!(giga); "kg · Gm/s", "kilogram gigameter per second", "kilogram gigameters per second"; @kilogram_megameter_per_second: prefix!(mega); "kg · Mm/s", "kilogram megameter per second", "kilogram megameters per second"; @kilogram_kilometer_per_second: prefix!(kilo); "kg · km/s", "kilogram kilometer per second", "kilogram kilometers per second"; @kilogram_hectometer_per_second: prefix!(hecto); "kg · hm/s", "kilogram hectometer per second", "kilogram hectometers per second"; @kilogram_decameter_per_second: prefix!(deca); "kg · dam/s", "kilogram decameter per second", "kilogram decameters per second"; @kilogram_decimeter_per_second: prefix!(deci); "kg · dm/s", "kilogram decimeter per second", "kilogram decimeters per second"; @kilogram_centimeter_per_second: prefix!(centi); "kg · cm/s", "kilogram centimeter per second", "kilogram centimeters per second"; @kilogram_millimeter_per_second: prefix!(milli); "kg · mm/s", "kilogram millimeter per second", "kilogram millimeters per second"; @kilogram_micrometer_per_second: prefix!(micro); "kg · µm/s", "kilogram micrometer per second", "kilogram micrometers per second"; @kilogram_nanometer_per_second: prefix!(nano); "kg · nm/s", "kilogram nanometer per second", "kilogram nanometers per second"; @kilogram_picometer_per_second: prefix!(pico); "kg · pm/s", "kilogram picometer per second", "kilogram picometers per second"; @kilogram_femtometer_per_second: prefix!(femto); "kg · fm/s", "kilogram femtometer per second", "kilogram femtometers per second"; @kilogram_attometer_per_second: prefix!(atto); "kg · am/s", "kilogram attometer per second", "kilogram attometers per second"; @kilogram_zeptometer_per_second: prefix!(zepto); "kg · zm/s", "kilogram zeptometer per second", "kilogram zeptometers per second"; @kilogram_yoctometer_per_second: prefix!(yocto); "kg · ym/s", "kilogram yoctometer per second", "kilogram yoctometers per second"; @ton_meter_per_second: prefix!(mega) / prefix!(kilo); "t · m/s", "ton meter per second", "ton meters per second"; @kilogram_meter_per_minute: 1.666_666_666_666_666_6_E-2; "kg · m/min", "kilogram meter per minute", "kilogram meters per minute"; @kilogram_meter_per_hour: 2.777_777_777_777_777_7_E-4; "kg · m/h", "kilogram meter per hour", "kilogram meters per hour"; @kilogram_meter_per_day: 1.157_407_407_407_407_4_E-5; "kg · m/d", "kilogram meter per day", "kilogram meters per day"; @slug_foot_per_second: 4.448_220_72_E0; "slug · ft/s", "slug foot per second", "slug feet per second"; @slug_inch_per_second: 3.706_850_6_E-1; "slug · in/s", "slug inch per second", "slug inches per second"; @pound_foot_per_second: 1.382_549_635_2_E-1; "lb · ft/s", "pound foot per second", "pound feet per second"; @pound_inch_per_second: 1.152_124_696_E-2; "lb · in/s", "pound inch per second", "pound inches per second"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::length as l; use crate::si::mass as m; use crate::si::momentum as mmm; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: Momentum = Mass::new::(V::one()) * Length::new::(V::one()) / Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test() where M: m::Conversion, L: l::Conversion, T: t::Conversion, R: mmm::Conversion { Test::assert_approx_eq(&Momentum::new::(V::one()), &(Mass::new::(V::one()) * Length::new::(V::one()) / Time::new::(V::one()))); } } } } uom-0.35.0/src/si/power.rs000064400000000000000000000117341046102023000134230ustar 00000000000000//! Power (base unit watt, m² · kg · s⁻³). quantity! { /// Power (base unit watt, m² · kg · s⁻³). quantity: Power; "power"; /// Dimension of power, L²MT⁻³ (base unit watt, m² · kg · s⁻³). dimension: ISQ< P2, // length P1, // mass N3, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottawatt: prefix!(yotta); "YW", "yottawatt", "yottawatts"; @zettawatt: prefix!(zetta); "ZW", "zettawatt", "zettawatts"; @exawatt: prefix!(exa); "EW", "exawatt", "exawatts"; @petawatt: prefix!(peta); "PW", "petawatt", "petawatts"; @terawatt: prefix!(tera); "TW", "terawatt", "terawatts"; @gigawatt: prefix!(giga); "GW", "gigawatt", "gigawatts"; @megawatt: prefix!(mega); "MW", "megawatt", "megawatts"; @kilowatt: prefix!(kilo); "kW", "kilowatt", "kilowatts"; @hectowatt: prefix!(hecto); "hW", "hectowatt", "hectowatts"; @decawatt: prefix!(deca); "daW", "decawatt", "decawatts"; /// Derived unit of power. @watt: prefix!(none); "W", "watt", "watts"; @deciwatt: prefix!(deci); "dW", "deciwatt", "deciwatts"; @centiwatt: prefix!(centi); "cW", "centiwatt", "centiwatts"; @milliwatt: prefix!(milli); "mW", "milliwatt", "milliwatts"; @microwatt: prefix!(micro); "µW", "microwatt", "microwatts"; @nanowatt: prefix!(nano); "nW", "nanowatt", "nanowatts"; @picowatt: prefix!(pico); "pW", "picowatt", "picowatts"; @femtowatt: prefix!(femto); "fW", "femtowatt", "femtowatts"; @attowatt: prefix!(atto); "aW", "attowatt", "attowatts"; @zeptowatt: prefix!(zepto); "zW", "zeptowatt", "zeptowatts"; @yoctowatt: prefix!(yocto); "yW", "yoctowatt", "yoctowatts"; @erg_per_second: 1.0_E-7; "erg/s", "erg per second", "ergs per second"; @foot_pound_per_hour: 3.766_161_111_111_111_E-4; "ft · lbf/h", "foot pound-force per hour", "foot pounds-force per hour"; @foot_pound_per_minute: 2.259_696_666_666_666_6_E-2; "ft · lbf/min", "foot pound-force per minute", "foot pounds-force per minute"; @foot_pound_per_second: 1.355_818; "ft · lbf/s", "foot pound-force per second", "foot pounds-force per second"; @horsepower: 7.456_999_E2; "hp", "horsepower", "horsepower"; @horsepower_boiler: 9.809_50_E3; "hp (S)", "horsepower (boiler)", "horsepower (boiler)"; @horsepower_electric: 7.46_E2; "hp (E)", "horsepower (electric)", "horsepower (electric)"; @horsepower_metric: 7.354_988_E2; "hp (M)", "metric horsepower", "metric horsepower"; @horsepower_imperial: 7.457_0_E2; "hp (I)", "horsepower (Imperial)", "horsepower (Imperial)"; @hydraulic_horsepower: 7.460_43_E2; "hp (hydraulic)", "hydraulic horsepower", "hydraulic horsepower"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::energy as e; use crate::si::power as p; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: Power = Energy::new::(V::one()) / Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, P: p::Conversion>() { Test::assert_approx_eq(&Power::new::

(V::one()), &(Energy::new::(V::one()) / Time::new::(V::one()))); } } } } uom-0.35.0/src/si/power_rate.rs000064400000000000000000000153371046102023000144410ustar 00000000000000//! Power rate (base unit watt per second, m² · kg · s⁻⁴). quantity! { /// Power rate (base unit watt per second, m² · kg · s⁻⁴). quantity: PowerRate; "power rate"; /// Dimension of power rate, L²MT⁻⁴ (base unit watt per second, m² · kg · s⁻⁴). dimension: ISQ< P2, // length P1, // mass N4, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottawatt_per_second: prefix!(yotta); "YW/s", "yottawatt per second", "yottawatts per second"; @zettawatt_per_second: prefix!(zetta); "ZW/s", "zettawatt per second", "zettawatts per second"; @exawatt_per_second: prefix!(exa); "EW/s", "exawatt per second", "exawatts per second"; @petawatt_per_second: prefix!(peta); "PW/s", "petawatt per second", "petawatts per second"; @terawatt_per_second: prefix!(tera); "TW/s", "terawatt per second", "terawatts per second"; @gigawatt_per_second: prefix!(giga); "GW/s", "gigawatt per second", "gigawatts per second"; @megawatt_per_second: prefix!(mega); "MW/s", "megawatt per second", "megawatts per second"; @kilowatt_per_second: prefix!(kilo); "kW/s", "kilowatt per second", "kilowatts per second"; @hectowatt_per_second: prefix!(hecto); "hW/s", "hectowatt per second", "hectowatts per second"; @decawatt_per_second: prefix!(deca); "daW/s", "decawatt per second", "decawatts per second"; /// Derived unit of power rate. @watt_per_second: prefix!(none); "W/s", "watt per second", "watts per second"; @deciwatt_per_second: prefix!(deci); "dW/s", "deciwatt per second", "deciwatts per second"; @centiwatt_per_second: prefix!(centi); "cW/s", "centiwatt per second", "centiwatts per second"; @milliwatt_per_second: prefix!(milli); "mW/s", "milliwatt per second", "milliwatts per second"; @microwatt_per_second: prefix!(micro); "µW/s", "microwatt per second", "microwatts per second"; @nanowatt_per_second: prefix!(nano); "nW/s", "nanowatt per second", "nanowatts per second"; @picowatt_per_second: prefix!(pico); "pW/s", "picowatt per second", "picowatts per second"; @femtowatt_per_second: prefix!(femto); "fW/s", "femtowatt per second", "femtowatts per second"; @attowatt_per_second: prefix!(atto); "aW/s", "attowatt per second", "attowatts per second"; @zeptowatt_per_second: prefix!(zepto); "zW/s", "zeptowatt per second", "zeptowatts per second"; @yoctowatt_per_second: prefix!(yocto); "yW/s", "yoctowatt per second", "yoctowatts per second"; @erg_per_second_squared: 1.0_E-7; "erg/s²", "erg per second squared", "ergs per second squared"; @foot_pound_per_second_squared: 1.355_818; "ft · lbf/s²", "foot pound-force per second squared", "foot pounds-force per second squared"; @horsepower_per_second: 7.456_999_E2; "hp/s", "horsepower per second", "horsepower per second"; @horsepower_per_second_boiler: 9.809_50_E3; "hp/s (S)", "horsepower per second (boiler)", "horsepower per second (boiler)"; @horsepower_per_second_electric: 7.46_E2; "hp/s (E)", "horsepower per second (electric)", "horsepower per second (electric)"; @horsepower_per_second_metric: 7.354_988_E2; "hp/s (M)", "metric horsepower per second", "metric horsepower per second"; @horsepower_per_second_imperial: 7.457_0_E2; "hp/s (I)", "horsepower per second (Imperial)", "horsepower per second (Imperial)"; @hydraulic_horsepower_per_second: 7.460_43_E2; "hp/s (hydraulic)", "hydraulic horsepower per second", "hydraulic horsepower per second"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::power as p; use crate::si::power_rate as r; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: PowerRate = Power::new::(V::one()) / Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, R: r::Conversion>() { Test::assert_approx_eq(&PowerRate::new::(V::one()), &(Power::new::

(V::one()) / Time::new::(V::one()))); } } } } uom-0.35.0/src/si/prefix.rs000064400000000000000000000033441046102023000135620ustar 00000000000000/// Macro to implement the [SI][si] prefixes for [multiples of units][mult], /// [submultiples of units][submult] and [binary multiples of units][bimult]. /// /// Implemented using `macro_rules!` instead of `const` so that type inference at call sites can /// generate the appropriate float type. Using explicit constants would require duplicate /// definitions for `f32` and `f64` or casting from `f64` in `f32` contexts. /// /// [si]: https://jcgm.bipm.org/vim/en/1.16.html /// [mult]: https://jcgm.bipm.org/vim/en/1.17.html /// [submult]: https://jcgm.bipm.org/vim/en/1.18.html /// [bimult]: https://www.iec.ch/si/binary.htm #[rustfmt::skip] #[macro_export] macro_rules! prefix { // SI prefixes. (yotta) => { 1.0_E24 }; (zetta) => { 1.0_E21 }; (exa) => { 1.0_E18 }; (peta) => { 1.0_E15 }; (tera) => { 1.0_E12 }; (giga) => { 1.0_E9 }; (mega) => { 1.0_E6 }; (kilo) => { 1.0_E3 }; (hecto) => { 1.0_E2 }; (deca) => { 1.0_E1 }; (none) => { 1.0_E0 }; (deci) => { 1.0_E-1 }; (centi) => { 1.0_E-2 }; (milli) => { 1.0_E-3 }; (micro) => { 1.0_E-6 }; (nano) => { 1.0_E-9 }; (pico) => { 1.0_E-12 }; (femto) => { 1.0_E-15 }; (atto) => { 1.0_E-18 }; (zepto) => { 1.0_E-21 }; (yocto) => { 1.0_E-24 }; // Binary prefixes. (yobi) => { 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0 }; (zebi) => { 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0 }; (exbi) => { 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0 }; (pebi) => { 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0 }; (tebi) => { 1024.0 * 1024.0 * 1024.0 * 1024.0 }; (gibi) => { 1024.0 * 1024.0 * 1024.0 }; (mebi) => { 1024.0 * 1024.0 }; (kibi) => { 1024.0 }; } uom-0.35.0/src/si/pressure.rs000064400000000000000000000211671046102023000141400ustar 00000000000000//! Pressure (base unit pascal, kg · m⁻¹ · s⁻²). quantity! { /// Pressure (base unit pascal, kg · m⁻¹ · s⁻²). quantity: Pressure; "pressure"; /// Dimension of pressure, L⁻¹MT⁻² (base unit pascal, kg · m⁻¹ · s⁻²). dimension: ISQ< N1, // length P1, // mass N2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottapascal: prefix!(yotta); "YPa", "yottapascal", "yottapascals"; @zettapascal: prefix!(zetta); "ZPa", "zettapascal", "zettapascals"; @exapascal: prefix!(exa); "EPa", "exapascal", "exapascals"; @petapascal: prefix!(peta); "PPa", "petapascal", "petapascals"; @terapascal: prefix!(tera); "TPa", "terapascal", "terapascals"; @gigapascal: prefix!(giga); "GPa", "gigapascal", "gigapascals"; @megapascal: prefix!(mega); "MPa", "megapascal", "megapascals"; @kilopascal: prefix!(kilo); "kPa", "kilopascal", "kilopascals"; @hectopascal: prefix!(hecto); "hPa", "hectopascal", "hectopascals"; @decapascal: prefix!(deca); "daPa", "decapascal", "decapascals"; /// Derived unit of pressure. @pascal: prefix!(none); "Pa", "pascal", "pascals"; @decipascal: prefix!(deci); "dPa", "decipascal", "decipascals"; @centipascal: prefix!(centi); "cPa", "centipascal", "centipascals"; @millipascal: prefix!(milli); "mPa", "millipascal", "millipascals"; @micropascal: prefix!(micro); "µPa", "micropascal", "micropascals"; @nanopascal: prefix!(nano); "nPa", "nanopascal", "nanopascals"; @picopascal: prefix!(pico); "pPa", "picopascal", "picopascals"; @femtopascal: prefix!(femto); "fPa", "femtopascal", "femtopascals"; @attopascal: prefix!(atto); "aPa", "attopascal", "attopascals"; @zeptopascal: prefix!(zepto); "zPa", "zeptopascal", "zeptopascals"; @yoctopascal: prefix!(yocto); "yPa", "yoctopascal", "yoctopascals"; @atmosphere: 1.013_25_E5; "atm", "atmosphere", "atmospheres"; @atmosphere_technical: 9.806_65_E4; "at", "atmosphere (technical)", "atmospheres (technical)"; @bar: 1.0_E5; "bar", "bar", "bar"; @centimeter_of_mercury_0: 1.333_22_E3; "cm Hg (0 °C)", "centimeter of mercury (0 °C)", "centimeters of mercury (0 °C)"; @centimeter_of_mercury: 1.333_224_E3; "cm Hg", "centimeter of mercury", "centimeters of mercury"; @centimeter_of_water_4: 9.806_38_E1; "cm H₂O (4 °C)", "centimeter of water (4 °C)", "centimeters of water (4 °C)"; @centimeter_of_water: 9.806_65_E1; "cm H₂O", "centimeter of water", "centimeters of water"; @dyne_per_square_centimeter: 1.0_E-1; "dyn/cm²", "dyne per square centimeter", "dynes per square centimeter"; @foot_of_mercury: 4.063_666_E4; "ft Hg", "foot of mercury", "feet of mercury"; @foot_of_water_39_2: 2.988_98_E3; "ft H₂O (39.2 °F)", "foot of water (39.2 °F)", "feet of water (39.2 °F)"; @foot_of_water: 2.989_067_E3; "ft H₂O", "foot of water", "feet of water"; @gram_force_per_square_centimeter: 9.806_65_E1; "gf/cm²", "gram-force per square centimeter", "grams-force per square centimeter"; @inch_of_mercury_32: 3.386_38_E3; "in Hg (32 °F)", "inch of mercury (32 °F)", "inches of mercury (32 °F)"; @inch_of_mercury_60: 3.376_85_E3; "in Hg (60 °F)", "inch of mercury (60 °F)", "inches of mercury (60 °F)"; @inch_of_mercury: 3.386_389_E3; "in Hg", "inch of mercury", "inches of mercury"; @inch_of_water_39_2: 2.490_82_E2; "in H₂O (39.2 °F)", "inch of water (39.2 °F)", "inches of water (39.2 °F)"; @inch_of_water_60: 2.488_4_E2; "in H₂O (60 °F)", "inch of water (60 °F)", "inches of water (60 °F)"; @inch_of_water: 2.490_889_E2; "in H₂O", "inch of water", "inches of water"; @newton_per_square_millimeter: 1.0_E6; "N/mm²", "newton per square millimeter", "newtons per square millimeter"; @kilogram_force_per_square_centimeter: 9.806_65_E4; "kgf/cm²", "kilogram-force per square centimeter", "kilograms-force per square centimeter"; @kilogram_force_per_square_meter: 9.806_65_E0; "kgf/m²", "kilogram-force per square meter", "kilograms-force per square meter"; @kilogram_force_per_square_millimeter: 9.806_65_E6; "kgf/mm²", "kilogram-force per square millimeter", "kilograms-force per square millimeter"; @kip_per_square_inch: 6.894_757_889_515_779_E6; "kip/in²", "kip per square inch", "kips per square inch"; @millibar: 1.0_E2; "mbar", "millibar", "millibar"; @millimeter_of_mercury: 1.333_224_E2; "mm Hg", "millimeter of mercury", "millimeters of mercury"; @millimeter_of_water: 9.806_65_E0; "mm H₂O", "millimeter of water", "millimeters of water"; @millitorr: 1.333_224_E-1; "mTorr", "millitorr", "millitorr"; @poundal_per_square_foot: 1.488_164_434_662_202_5_E0; "pdl/ft²", "poundal per square foot", "poundals per square foot"; @pound_force_per_square_foot: 4.788_026_312_163_735_6_E1; "lbf/ft²", "pound-force per square foot", "pounds-force per square foot"; @pound_force_per_square_inch: 6.894_757_889_515_779_E3; "lbf/in²", "pound-force per square inch", "pounds-force per square inch"; @psi: 6.894_757_E3; "psi", "pound-force per square inch", "pounds-force per square inch"; @torr: 1.333_224_E2; "Torr", "torr", "torr"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::area as a; use crate::si::force as f; use crate::si::pressure as p; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: Pressure = Force::new::(V::one()) / Area::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, A: a::Conversion, P: p::Conversion>() { Test::assert_approx_eq(&Pressure::new::

(V::one()), &(Force::new::(V::one()) / Area::new::(V::one()))); } } } } uom-0.35.0/src/si/radiant_exposure.rs000064400000000000000000000264311046102023000156430ustar 00000000000000//! Radiant exposure (base unit joule per square meter, kg · s⁻²). quantity! { /// Radiant exposure (base unit joule per square meter, kg · s⁻²). quantity: RadiantExposure; "radiant exposure"; /// Dimension of radiant exposure, MT⁻² (base unit joule per square meter, kg · s⁻²). dimension: ISQ< Z0, // length P1, // mass N2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { // square meter denominator @yottajoule_per_square_meter: prefix!(yotta); "YJ/m²", "yottajoule per square meter", "yottajoules per square meter"; @zettajoule_per_square_meter: prefix!(zetta); "ZJ/m²", "zettajoule per square meter", "zettajoules per square meter"; @exajoule_per_square_meter: prefix!(exa); "EJ/m²", "exajoule per square meter", "exajoules per square meter"; @petajoule_per_square_meter: prefix!(peta); "PJ/m²", "petajoule per square meter", "petajoules per square meter"; @terajoule_per_square_meter: prefix!(tera); "TJ/m²", "terajoule per square meter", "terajoules per square meter"; @gigajoule_per_square_meter: prefix!(giga); "GJ/m²", "gigajoule per square meter", "gigajoules per square meter"; @megajoule_per_square_meter: prefix!(mega); "MJ/m²", "megajoule per square meter", "megajoules per square meter"; @kilojoule_per_square_meter: prefix!(kilo); "kJ/m²", "kilojoule per square meter", "kilojoules per square meter"; @hectojoule_per_square_meter: prefix!(hecto); "hJ/m²", "hectojoule per square meter", "hectojoules per square meter"; @decajoule_per_square_meter: prefix!(deca); "daJ/m²", "decajoule per square meter", "decajoules per square meter"; /// Derived unit of radiant exposure. @joule_per_square_meter: prefix!(none); "J/m²", "joule per square meter", "joules per square meter"; @decijoule_per_square_meter: prefix!(deci); "dJ/m²", "decijoule per square meter", "decijoules per square meter"; @centijoule_per_square_meter: prefix!(centi); "cJ/m²", "centijoule per square meter", "centijoules per square meter"; @millijoule_per_square_meter: prefix!(milli); "mJ/m²", "millijoule per square meter", "millijoules per square meter"; @microjoule_per_square_meter: prefix!(micro); "µJ/m²", "microjoule per square meter", "microjoules per square meter"; @nanojoule_per_square_meter: prefix!(nano); "nJ/m²", "nanojoule per square meter", "nanojoules per square meter"; @picojoule_per_square_meter: prefix!(pico); "pJ/m²", "picojoule per square meter", "picojoules per square meter"; @femtojoule_per_square_meter: prefix!(femto); "fJ/m²", "femtojoule per square meter", "femtojoules per square meter"; @attojoule_per_square_meter: prefix!(atto); "aJ/m²", "attojoule per square meter", "attojoules per square meter"; @zeptojoule_per_square_meter: prefix!(zepto); "zJ/m²", "zeptojoule per square meter", "zeptojoules per square meter"; @yoctojoule_per_square_meter: prefix!(yocto); "yJ/m²", "yoctojoule per square meter", "yoctojoules per square meter"; // square centimeter denominator @gigajoule_per_square_centimeter: 1.0E13; "GJ/cm²", "gigajoule per square centimeter", "gigajoules per square centimeter"; @megajoule_per_square_centimeter: 1.0E10; "MJ/cm²", "megajoule per square centimeter", "megajoules per square centimeter"; @kilojoule_per_square_centimeter: 1.0E7; "kJ/cm²", "kilojoule per square centimeter", "kilojoules per square centimeter"; @hectojoule_per_square_centimeter: 1.0E6; "hJ/cm²", "hectojoule per square centimeter", "hectojoules per square centimeter"; @decajoule_per_square_centimeter: 1.0E5; "daJ/cm²", "decajoule per square centimeter", "decajoules per square centimeter"; @joule_per_square_centimeter: 1.0E4; "J/cm²", "joule per square centimeter", "joules per square centimeter"; @decijoule_per_square_centimeter: 1.0E3; "dJ/cm²", "decijoule per square centimeter", "decijoules per square centimeter"; @centijoule_per_square_centimeter: 1.0E2; "cJ/cm²", "centijoule per square centimeter", "centijoules per square centimeter"; @millijoule_per_square_centimeter: 1.0E1; "mJ/cm²", "millijoule per square centimeter", "millijoules per square centimeter"; @microjoule_per_square_centimeter: 1.0E-2; "µJ/cm²", "microjoule per square centimeter", "microjoules per square centimeter"; @nanojoule_per_square_centimeter: 1.0E-5; "nJ/cm²", "nanojoule per square centimeter", "nanojoules per square centimeter"; // square millimeter denominator @gigajoule_per_square_millimeter: 1.0E15; "GJ/mm²", "gigajoule per square millimeter", "gigajoules per square millimeter"; @megajoule_per_square_millimeter: 1.0E12; "MJ/mm²", "megajoule per square millimeter", "megajoules per square millimeter"; @kilojoule_per_square_millimeter: 1.0E9; "kJ/mm²", "kilojoule per square millimeter", "kilojoules per square millimeter"; @hectojoule_per_square_millimeter: 1.0E8; "hJ/mm²", "hectojoule per square millimeter", "hectojoules per square millimeter"; @decajoule_per_square_millimeter: 1.0E7; "daJ/mm²", "decajoule per square millimeter", "decajoules per square millimeter"; @joule_per_square_millimeter: 1.0E6; "J/mm²", "joule per square millimeter", "joules per square millimeter"; @decijoule_per_square_millimeter: 1.0E5; "dJ/mm²", "decijoule per square millimeter", "decijoules per square millimeter"; @centijoule_per_square_millimeter: 1.0E4; "cJ/mm²", "centijoule per square millimeter", "centijoules per square millimeter"; @millijoule_per_square_millimeter: 1.0E3; "mJ/mm²", "millijoule per square millimeter", "millijoules per square millimeter"; @microjoule_per_square_millimeter: 1.0E0; "µJ/mm²", "microjoule per square millimeter", "microjoules per square millimeter"; @nanojoule_per_square_millimeter: 1.0E-3; "nJ/mm²", "nanojoule per square millimeter", "nanojoules per square millimeter"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::area as a; use crate::si::energy as e; use crate::si::length as l; use crate::si::quantities::*; use crate::si::radiant_exposure as re; use crate::tests::Test; #[test] fn check_dimension() { let _: RadiantExposure = Energy::new::(V::one()) / (Length::new::(V::one()) * Length::new::(V::one())); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, A: a::Conversion, RE: re::Conversion>() { Test::assert_approx_eq( &RadiantExposure::new::(V::one()), &(Energy::new::(V::one()) / Area::new::(V::one()))); } } } } uom-0.35.0/src/si/radioactivity.rs000064400000000000000000000120761046102023000151420ustar 00000000000000//! Radioactivity (base unit becquerel, s⁻¹). quantity! { /// Radioactivity (base unit becquerel, s⁻¹). quantity: Radioactivity; "radioactivity"; /// Dimension of radioactivity, T⁻¹ (base unit becquerel, s⁻¹). dimension: ISQ< Z0, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @yottabecquerel: prefix!(yotta); "YBq", "yottabecquerel", "yottabecquerels"; @zettabecquerel: prefix!(zetta); "ZBq", "zettabecquerel", "zettabecquerels"; @exabecquerel: prefix!(exa); "EBq", "exabecquerel", "exabecquerels"; @petabecquerel: prefix!(peta); "PBq", "petabecquerel", "petabecquerels"; @terabecquerel: prefix!(tera); "TBq", "terabecquerel", "terabecquerels"; @gigabecquerel: prefix!(giga); "GBq", "gigabecquerel", "gigabecquerels"; @megabecquerel: prefix!(mega); "MBq", "megabecquerel", "megabecquerels"; @kilobecquerel: prefix!(kilo); "kBq", "kilobecquerel", "kilobecquerels"; @hectobecquerel: prefix!(hecto); "hBq", "hectobecquerel", "hectobecquerels"; @decabecquerel: prefix!(deca); "daBq", "decabecquerel", "decabecquerels"; /// The becquerel is one decay per second. @becquerel: prefix!(none); "Bq", "becquerel", "becquerels"; @millibecquerel: prefix!(milli); "mBq", "millibecquerel", "millibecquerels"; @microbecquerel: prefix!(micro); "µBq", "microbecquerel", "microbecquerels"; @nanobecquerel: prefix!(nano); "nBq", "nanobecquerel", "nanobecquerels"; @gigacurie: prefix!(giga) * 3.7_E10; "GCi", "gigacurie", "gigacuries"; @megacurie: prefix!(mega) * 3.7_E10; "MCi", "megacurie", "megacuries"; @kilocurie: prefix!(kilo) * 3.7_E10; "kCi", "kilocurie", "kilocuries"; @curie: 3.7_E10; "Ci", "curie", "curies"; @millicurie: prefix!(milli) * 3.7_E10; "mCi", "millicurie", "millicuries"; @microcurie: prefix!(micro) * 3.7_E10; "µCi", "microcurie", "microcuries"; @nanocurie: prefix!(nano) * 3.7_E10; "nCi", "nanocurie", "nanocuries"; @disintegrations_per_minute: 1.0 / 6.0_E1; "dpm", "disintegration per minute", "disintegrations per minute"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::{FromPrimitive, One}; use crate::si::radioactivity as rad; use crate::si::quantities::*; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: Time = (V::one() / Radioactivity::new::(V::one())).into(); let _: Radioactivity = (V::one() / Time::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, RAD: rad::Conversion>() { Test::assert_approx_eq(&(V::one() / Time::new::(V::one())), &Radioactivity::new::(V::one()).into()); Test::assert_approx_eq(&Time::new::(V::one()), &(V::one() / Radioactivity::new::(V::one())).into()); } } #[test] fn check_curie() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, RadCi: rad::Conversion>() { Test::assert_approx_eq( &(V::one() * V::from_f64(3.7_E10).unwrap() * Radioactivity::new::(V::one())), &Radioactivity::new::(V::one())); } } #[test] fn check_dpm() { test::(); fn test, RadCi: rad::Conversion>() { Test::assert_approx_eq(&(V::one() / V::from_f64(6_E1).unwrap() * Radioactivity::new::(V::one())), &Radioactivity::new::(V::one())); } } } } uom-0.35.0/src/si/ratio.rs000064400000000000000000000251431046102023000134040ustar 00000000000000//! Ratio (dimensionless quantity). #[cfg(feature = "std")] use super::angle::{Angle, radian}; quantity! { /// Ratio (dimensionless quantity). quantity: Ratio; "ratio"; /// Dimension of ratio, 1 (dimensionless). dimension: ISQ< Z0, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @ratio: 1.0; "", "", ""; @part_per_hundred: 1.0_E-2; "parts per hundred", "part per hundred", "parts per hundred"; @percent: 1.0_E-2; "%", "percent", "percent"; @part_per_thousand: 1.0_E-3; "parts per thousand", "part per thousand", "parts per thousand"; @per_mille: 1.0_E-3; "‰", "per mille", "per mille"; @part_per_ten_thousand: 1.0_E-4; "parts per ten thousand", "part per then thousand", "parts per ten thousand"; // ‱, doesn't display properly. @basis_point: 1.0_E-4; "bp", "basis point", "basis points"; @part_per_million: 1.0_E-6; "ppm", "part per million", "parts per million"; @part_per_billion: 1.0_E-9; "ppb", "part per billion", "parts per billion"; @part_per_trillion: 1.0_E-12; "ppt", "part per trillion", "parts per trillion"; @part_per_quadrillion: 1.0_E-15; "ppq", "part per quadrillion", "parts per quadrillion"; } } /// Implementation of various stdlib functions. #[cfg(feature = "std")] impl Ratio where U: crate::si::Units + ?Sized, V: crate::num::Float + crate::Conversion, radian: crate::Conversion, ratio: crate::Conversion, { /// Computes the value of the inverse cosine of the ratio. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn acos(self) -> Angle { Angle::new::(self.value.acos()) } /// Computes the value of the inverse hyperbolic cosine of the ratio. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn acosh(self) -> Angle { Angle::new::(self.value.acosh()) } /// Computes the value of the inverse sine of the ratio. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn asin(self) -> Angle { Angle::new::(self.value.asin()) } /// Computes the value of the inverse hyperbolic sine of the ratio. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn asinh(self) -> Angle { Angle::new::(self.value.asinh()) } /// Computes the value of the inverse tangent of the ratio. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn atan(self) -> Angle { Angle::new::(self.value.atan()) } /// Computes the value of the inverse hyperbolic tangent of the ratio. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn atanh(self) -> Angle { Angle::new::(self.value.atanh()) } /// Returns `e^(self)`, (the exponential function). #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn exp(self) -> Ratio { Ratio::new::(self.value.exp()) } /// Returns 2^(self). #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn exp2(self) -> Ratio { Ratio::new::(self.value.exp2()) } /// Returns the natural logarithm of the number. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn ln(self) -> Ratio { Ratio::new::(self.value.ln()) } /// Returns the logarithm of the number with respect to an arbitrary base. /// /// The result might not be correctly rounded owing to implementation /// details; self.log2() can produce more accurate results for base 2, and /// self.log10() can produce more accurate results for base 10. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn log(self, base: V) -> Ratio { Ratio::new::(self.value.log(base)) } /// Returns the base 2 logarithm of the number. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn log2(self) -> Ratio { Ratio::new::(self.value.log2()) } /// Returns the base 10 logarithm of the number. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn log10(self) -> Ratio { Ratio::new::(self.value.log10()) } /// Returns e^(self) - 1 in a way that is accurate even if the number is close to zero. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn exp_m1(self) -> Ratio { Ratio::new::(self.value.exp_m1()) } /// Returns ln(1+n) (natural logarithm) more accurately than if the /// operations were performed separately. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn ln_1p(self) -> Ratio { Ratio::new::(self.value.ln_1p()) } } mod convert { use super::*; impl From for Ratio where U: crate::si::Units + ?Sized, V: crate::num::Num + crate::Conversion, { fn from(t: V) -> Self { Ratio { dimension: crate::lib::marker::PhantomData, units: crate::lib::marker::PhantomData, value: t, } } } storage_types! { use super::*; impl From> for V where U: crate::si::Units + ?Sized, V: crate::num::Num + crate::Conversion, { fn from(t: Ratio) -> Self { t.value } } } } #[cfg(test)] mod tests { storage_types! { use crate::num::{FromPrimitive, One}; use crate::si::quantities::*; use crate::si::ratio as r; use crate::tests::Test; #[test] fn from() { let r1: Ratio = Ratio::::from(V::one()); let r2: Ratio = V::one().into(); let _: V = V::from(r1); let _: V = r2.into(); } #[test] fn check_units() { Test::assert_eq(&Ratio::new::(V::one() / V::from_f64(1.0_E2).unwrap()), &Ratio::new::(V::one())); Test::assert_eq(&Ratio::new::(V::one() / V::from_f64(1.0_E2).unwrap()), &Ratio::new::(V::one())); Test::assert_eq(&Ratio::new::(V::one() / V::from_f64(1.0_E3).unwrap()), &Ratio::new::(V::one())); Test::assert_eq(&Ratio::new::(V::one() / V::from_f64(1.0_E3).unwrap()), &Ratio::new::(V::one())); Test::assert_eq(&Ratio::new::(V::one() / V::from_f64(1.0_E4).unwrap()), &Ratio::new::(V::one())); Test::assert_eq(&Ratio::new::(V::one() / V::from_f64(1.0_E4).unwrap()), &Ratio::new::(V::one())); Test::assert_eq(&Ratio::new::(V::one() / V::from_f64(1.0_E6).unwrap()), &Ratio::new::(V::one())); Test::assert_eq(&Ratio::new::(V::one() / V::from_f64(1.0_E9).unwrap()), &Ratio::new::(V::one())); Test::assert_eq(&Ratio::new::(V::one() / V::from_f64(1.0_E12).unwrap()), &Ratio::new::(V::one())); Test::assert_eq(&Ratio::new::(V::one() / V::from_f64(1.0_E15).unwrap()), &Ratio::new::(V::one())); } } #[cfg(feature = "std")] mod float { storage_types! { types: Float; use crate::si::angle as a; use crate::si::ratio as r; use crate::si::quantities::*; use crate::tests::Test; quickcheck! { fn acos(x: V) -> bool { Test::eq(&x.acos(), &Ratio::from(x).acos().get::()) } fn acosh(x: V) -> bool { Test::eq(&x.acosh(), &Ratio::from(x).acosh().get::()) } fn asin(x: V) -> bool { Test::eq(&x.asin(), &Ratio::from(x).asin().get::()) } fn asinh(x: V) -> bool { Test::eq(&x.asinh(), &Ratio::from(x).asinh().get::()) } fn atan(x: V) -> bool { Test::eq(&x.atan(), &Ratio::from(x).atan().get::()) } fn atanh(x: V) -> bool { Test::eq(&x.atanh(), &Ratio::from(x).atanh().get::()) } fn exp(x: V) -> bool { Test::eq(&x.exp(), &Ratio::from(x).exp().get::()) } fn exp2(x: V) -> bool { Test::eq(&x.exp2(), &Ratio::from(x).exp2().get::()) } fn ln(x: V) -> bool { Test::eq(&x.ln(), &Ratio::from(x).ln().get::()) } fn log(x: V, y: V) -> bool { Test::eq(&x.log(y), &Ratio::from(x).log(y).get::()) } fn log2(x: V) -> bool { Test::eq(&x.log2(), &Ratio::from(x).log2().get::()) } fn log10(x: V) -> bool { Test::eq(&x.log10(), &Ratio::from(x).log10().get::()) } fn exp_m1(x: V) -> bool { Test::eq(&x.exp_m1(), &Ratio::from(x).exp_m1().get::()) } fn ln_1p(x: V) -> bool { Test::eq(&x.ln_1p(), &Ratio::from(x).ln_1p().get::()) } } } } } uom-0.35.0/src/si/reciprocal_length.rs000064400000000000000000000056211046102023000157510ustar 00000000000000//! Reciprocal length (base unit reciprocal meter, m⁻¹). quantity! { /// Reciprocal length (base unit reciprocal meter, m⁻¹). quantity: ReciprocalLength; "reciprocal length"; /// Dimension of reciprocal length, L⁻¹ (base unit reciprocal meter, m⁻¹). dimension: ISQ< N1, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @reciprocal_kilometer: prefix!(none) / prefix!(kilo); "km⁻¹", "reciprocal kilometer", "reciprocal kilometers"; @reciprocal_meter: prefix!(none); "m⁻¹", "reciprocal meter", "reciprocal meters"; @reciprocal_decimeter: prefix!(none) / prefix!(deci); "dm⁻¹", "reciprocal decimeter", "reciprocal decimeters"; @reciprocal_centimeter: prefix!(none) / prefix!(centi); "cm⁻¹", "reciprocal centimeter", "reciprocal centimeters"; @reciprocal_millimeter: prefix!(none) / prefix!(milli); "mm⁻¹", "reciprocal millimeter", "reciprocal millimeters"; @reciprocal_micrometer: prefix!(none) / prefix!(micro); "µm⁻¹", "reciprocal micrometer", "reciprocal micrometers"; @reciprocal_nanometer: prefix!(none) / prefix!(nano); "nm⁻¹", "reciprocal nanometer", "reciprocal nanometers"; @reciprocal_angstrom: prefix!(none) / 1.0_E-10; "Å⁻¹", "reciprocal ångström", "reciprocal ångströms"; @diopter: prefix!(none); "dpt", "diopter", "diopters"; @rydberg_constant: 10_973_731.568_160; "R∞", "Rydberg constant", "Rydberg constants"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::length as l; use crate::si::reciprocal_length as rl; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: ReciprocalLength = V::one() / Length::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, RL: rl::Conversion>() { Test::assert_approx_eq(&ReciprocalLength::new::(V::one()), &(V::one() / Length::new::(V::one()))); } } } } uom-0.35.0/src/si/solid_angle.rs000064400000000000000000000055631046102023000145520ustar 00000000000000//! Solid angle (dimensionless quantity). quantity! { /// Solid angle (dimensionless quantity). quantity: SolidAngle; "solid angle"; /// Dimension of solid angle, 1 (dimensionless). dimension: ISQ< Z0, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::SolidAngleKind); units { /// SI derived unit of solid angle is steradians. It is the solid angle subtended at the /// center of a unit sphere by a unit area on its surface. @steradian: 1.0_E0; "sr", "steradian", "steradians"; @spat: 1.256_637_061_435_917_3_E1; "sp", "spat", "spats"; @square_degree: 3.046_174_197_867_086_E-4; "°²", "square degree", "square degrees"; @square_minute: 8.461_594_994_075_238_9_E-8; "′²", "square minute", "square minutes"; @square_second: 2.350_443_053_909_788_6_E-11; "″²", "square second", "square seconds"; } } #[cfg(feature = "f32")] impl SolidAngle, f32> { /// The solid angle subtended by a sphere at its center, i.e. with a value 4π as measured in /// steradians. pub const SPHERE: Self = Self { dimension: crate::lib::marker::PhantomData, units: crate::lib::marker::PhantomData, value: 4. * crate::lib::f32::consts::PI, }; } #[cfg(feature = "f64")] impl SolidAngle, f64> { /// The solid angle subtended by a sphere at its center, i.e. with a value 4π as measured in /// steradians. pub const SPHERE: Self = Self { dimension: crate::lib::marker::PhantomData, units: crate::lib::marker::PhantomData, value: 4. * crate::lib::f64::consts::PI, }; } #[cfg(test)] mod tests { storage_types! { use crate::lib::f64::consts::PI; use crate::num::{FromPrimitive, One}; use crate::si::quantities::*; use crate::si::solid_angle as sa; use crate::tests::Test; #[test] fn check_units() { Test::assert_eq(&SolidAngle::new::(V::from_f64(4.0 * PI).unwrap()), &SolidAngle::new::(V::one())); Test::assert_approx_eq( &SolidAngle::new::(V::from_f64(360.0 * 360.0 / PI).unwrap()), &SolidAngle::new::(V::one())); Test::assert_approx_eq( &SolidAngle::new::(V::from_f64(60.0 * 60.0).unwrap()), &SolidAngle::new::(V::one())); Test::assert_approx_eq( &SolidAngle::new::( V::from_f64((60.0 * 60.0) * (60.0 * 60.0)).unwrap()), &SolidAngle::new::(V::one())); } } } uom-0.35.0/src/si/specific_area.rs000064400000000000000000000043321046102023000150400ustar 00000000000000//! Specific area (base unit square meter per kilogram, m² · kg⁻¹). quantity! { /// Specific area (base unit square meter per kilogram, m² · kg⁻¹). quantity: SpecificArea; "specific area"; /// Dimension of specific area, L²M⁻¹ (base unit square meter per kilogram, m² · kg⁻¹). dimension: ISQ< P2, // length N1, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @square_meter_per_kilogram: prefix!(none); "m²/kg", "square meter per kilogram", "square meters per kilogram"; @square_centimeter_per_kilogram: prefix!(centi) * prefix!(centi); "cm²/kg", "square centimeter per kilogram", "square centimeters per kilogram"; @square_meter_per_gram: prefix!(none) / prefix!(milli); "m²/g", "square meter per gram", "square meters per gram"; @square_centimeter_per_gram: prefix!(centi) * prefix!(centi) / prefix!(milli); "cm²/g", "square centimeter per gram", "square centimeters per gram"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::area as a; use crate::si::mass as m; use crate::si::specific_area as sa; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: SpecificArea = Area::new::(V::one()) / Mass::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); fn test, M: m::Conversion, SA: sa::Conversion, >() { Test::assert_eq(&SpecificArea::new::(V::one()), &(Area::new::(V::one()) / Mass::new::(V::one()))); } } } } uom-0.35.0/src/si/specific_heat_capacity.rs000064400000000000000000000343101046102023000167250ustar 00000000000000//! Specific heat capacity (base unit joule per kilogram kelvin, m² · s⁻² · K⁻¹). //! //! This quantity might be used to define the heat capacity of a material. To define heat capacity //! of an object, use [heat capacity][hc]. //! //! Specific heat capacity has the same kind as [temperature interval][ti], as this quantity //! relates to change of temperature. Not of kind `TemperatureKind`, used by [thermodynamic //! temperature][tt]. See [thermodynamic temperature][tt] for a full explanation. //! //! [ti]: ../temperature_interval/index.html //! [tt]: ../thermodynamic_temperature/index.html //! [hc]: ../heat_capacity/index.html quantity! { /// Specific heat capacity (base unit joule per kilogram kelvin, m² · s⁻² · K⁻¹). quantity: SpecificHeatCapacity; "specific heat capacity"; /// Dimension of specific heat capacity, L²T⁻²Th⁻¹ (base unit joule per kilogram kelvin, m² · /// s⁻² · K⁻¹). dimension: ISQ< P2, // length Z0, // mass N2, // time Z0, // electric current N1, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @square_kilometer_per_second_squared_kelvin: prefix!(kilo) * prefix!(kilo); "km²/(s² · K)", "square kilometer per second squared kelvin", "square kilometers per second squared kelvin"; /// The derived unit of specific heat capacity expressed in base units. Equivalent to /// J/(kg · K). @square_meter_per_second_squared_kelvin: prefix!(none); "m²/(s² · K)", "square meter per second squared kelvin", "square meters per second squared kelvin"; @square_centimeter_per_second_squared_kelvin: prefix!(centi) * prefix!(centi); "cm²/(s² · K)", "square centimeter per second squared kelvin", "square centimeters per second squared kelvin"; @square_millimeter_per_second_squared_kelvin: prefix!(milli) * prefix!(milli); "mm²/(s² · K)", "square millimeter per second squared kelvin", "square millimeters per second squared kelvin"; @square_micrometer_per_second_squared_kelvin: prefix!(micro) * prefix!(micro); "µm²/(s² · K)", "square micrometer per second squared kelvin", "square micrometers per second squared kelvin"; // Specific heat capacity is much more commonly expressed in terms of energy / (mass // temperature). @yottajoule_per_kilogram_kelvin: prefix!(yotta); "YJ/(kg · K)", "yottajoule per kilogram kelvin", "yottajoules per kilogram kelvin"; @zettajoule_per_kilogram_kelvin: prefix!(zetta); "ZJ/(kg · K)", "zettajoule per kilogram kelvin", "zettajoules per kilogram kelvin"; @exajoule_per_kilogram_kelvin: prefix!(exa); "EJ/(kg · K)", "exajoule per kilogram kelvin", "exajoules per kilogram kelvin"; @petajoule_per_kilogram_kelvin: prefix!(peta); "PJ/(kg · K)", "petajoule per kilogram kelvin", "petajoules per kilogram kelvin"; @terajoule_per_kilogram_kelvin: prefix!(tera); "TJ/(kg · K)", "terajoule per kilogram kelvin", "terajoules per kilogram kelvin"; @gigajoule_per_kilogram_kelvin: prefix!(giga); "GJ/(kg · K)", "gigajoule per kilogram kelvin", "gigajoules per kilogram kelvin"; @megajoule_per_kilogram_kelvin: prefix!(mega); "MJ/(kg · K)", "megajoule per kilogram kelvin", "megajoules per kilogram kelvin"; @kilojoule_per_kilogram_kelvin: prefix!(kilo); "kJ/(kg · K)", "kilojoule per kilogram kelvin", "kilojoules per kilogram kelvin"; @hectojoule_per_kilogram_kelvin: prefix!(hecto); "hJ/(kg · K)", "hectojoule per kilogram kelvin", "hectojoules per kilogram kelvin"; @decajoule_per_kilogram_kelvin: prefix!(deca); "daJ/(kg · K)", "decajoule per kilogram kelvin", "decajoules per kilogram kelvin"; /// Derived unit of specific heat capacity expressed in derived units. Equivalent to /// m²/(s² · K). @joule_per_kilogram_kelvin: prefix!(none); "J/(kg · K)", "joule per kilogram kelvin", "joules per kilogram kelvin"; @decijoule_per_kilogram_kelvin: prefix!(deci); "dJ/(kg · K)", "decijoule per kilogram kelvin", "decijoules per kilogram kelvin"; @centijoule_per_kilogram_kelvin: prefix!(centi); "cJ/(kg · K)", "centijoule per kilogram kelvin", "centijoules per kilogram kelvin"; @millijoule_per_kilogram_kelvin: prefix!(milli); "mJ/(kg · K)", "millijoule per kilogram kelvin", "millijoules per kilogram kelvin"; @microjoule_per_kilogram_kelvin: prefix!(micro); "µJ/(kg · K)", "microjoule per kilogram kelvin", "microjoules per kilogram kelvin"; @nanojoule_per_kilogram_kelvin: prefix!(nano); "nJ/(kg · K)", "nanojoule per kilogram kelvin", "nanojoules per kilogram kelvin"; @picojoule_per_kilogram_kelvin: prefix!(pico); "pJ/(kg · K)", "picojoule per kilogram kelvin", "picojoules per kilogram kelvin"; @femtojoule_per_kilogram_kelvin: prefix!(femto); "fJ/(kg · K)", "femtojoule per kilogram kelvin", "femtojoules per kilogram kelvin"; @attojoule_per_kilogram_kelvin: prefix!(atto); "aJ/(kg · K)", "attojoule per kilogram kelvin", "attojoules per kilogram kelvin"; @zeptojoule_per_kilogram_kelvin: prefix!(zepto); "zJ/(kg · K)", "zeptojoule per kilogram kelvin", "zeptojoules per kilogram kelvin"; @yoctojoule_per_kilogram_kelvin: prefix!(yocto); "yJ/(kg · K)", "yoctojoule per kilogram kelvin", "yoctojoules per kilogram kelvin"; @kilojoule_per_kilogram_degree_celsius: 1.0_E3; "kJ/(kg · °C)", "kilojoule per kilogram degree celsius", "kilojoules per kilogram degree celsius"; @kilojoule_per_gram_degree_celsius: 1.0_E6; "kJ/(g · °C)", "kilojoule per gram degree celsius", "kilojoules per gram degree celsius"; @joule_per_kilogram_degree_celsius: 1.0_E0; "J/(kg · °C)", "joule per kilogram degree celsius", "joules per kilogram degree celsius"; @joule_per_gram_degree_celsius: 1.0_E3; "J/(g · °C)", "joule per gram degree celsius", "joules per gram degree celsius"; @millijoule_per_kilogram_degree_celsius: 1.0_E-3; "mJ/(kg · °C)", "millijoule per kilogram degree celsius", "millijoules per kilogram degree celsius"; @millijoule_per_gram_degree_celsius: 1.0_E0; "mJ/(g · °C)", "millijoule per gram degree celsius", "millijoules per gram degree celsius"; @btu_per_ounce_degree_fahrenheit: 6.694_399_058_608_398_E4; "Btu/(oz · °F)", "British thermal unit per ounce degree Fahrenheit", "British thermal units per ounce degree Fahrenheit"; @btu_it_per_ounce_degree_fahrenheit: 6.698_881_674_187_076_E4; "Btu (IT)/(oz · °F)", "British thermal unit (IT) per ounce degree Fahrenheit", "British thermal units (IT) per ounce degree Fahrenheit"; @btu_per_pound_degree_fahrenheit: 4.183_998_673_699_118_E3; "Btu/(lb · °F)", "British thermal unit per pound degree Fahrenheit", "British thermal units per pound degree Fahrenheit"; @btu_it_per_pound_degree_fahrenheit: 4.186_800_307_941_667_E3; "Btu (IT)/(lb · °F)", "British thermal unit (IT) per pound degree Fahrenheit", "British thermal units (IT) per pound degree Fahrenheit"; @btu_per_ton_degree_fahrenheit: 1.897_829_999_999_999_999_E0; "Btu/(t · °F)", "British thermal unit per ton degree Fahrenheit", "British thermal units per ton degree Fahrenheit"; @btu_it_per_ton_degree_fahrenheit: 1.899_100_799_999_999_999_E0; "Btu (IT)/(t · °F)", "British thermal unit (IT) per ton degree Fahrenheit", "British thermal units (IT) per ton degree Fahrenheit"; @calorie_per_kilogram_kelvin: 4.184_E0; "cal/(kg · K)", "calorie per kilogram kelvin", "calories per kilogram kelvin"; @calorie_per_gram_kelvin: prefix!(kilo) * 4.184_E0; "cal/(g · K)", "calorie per gram kelvin", "calories per gram kelvin"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::energy as e; use crate::si::length as l; use crate::si::mass as m; use crate::si::quantities::*; use crate::si::specific_heat_capacity as shc; use crate::si::temperature_interval as ti; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: SpecificHeatCapacity = Length::new::(V::one()) * Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * TemperatureInterval::new::(V::one())); } #[test] fn check_base_units() { test::(); test::(); test::(); test::(); test::(); fn test< L: l::Conversion, T: t::Conversion, TI: ti::Conversion, SHC: shc::Conversion>() { Test::assert_approx_eq(&SpecificHeatCapacity::new::(V::one()), &((Length::new::(V::one()) * Length::new::(V::one())) / (Time::new::(V::one()) * Time::new::(V::one()) * TemperatureInterval::new::(V::one())))); } } #[test] fn check_energy_per_mass_ti_shc_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test< E: e::Conversion, M: m::Conversion, TI: ti::Conversion, SHC: shc::Conversion>() { Test::assert_approx_eq(&SpecificHeatCapacity::new::(V::one()), &(Energy::new::(V::one()) / (Mass::new::(V::one()) * TemperatureInterval::new::(V::one())))); } } } } uom-0.35.0/src/si/specific_power.rs000064400000000000000000000205461046102023000152710ustar 00000000000000//! Specific power (base unit watt per kilogram, m² · s⁻³). quantity! { /// Specific power (base unit watt per kilogram, m² · s⁻³). quantity: SpecificPower; "specific power"; /// Dimension of specific power, L²T⁻³ (base unit watt per kilogram, m² · s⁻³). dimension: ISQ< P2, // length Z0, // mass N3, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottawatt_per_kilogram: prefix!(yotta); "YW/kg", "yottawatt per kilogram", "yottawatts per kilogram"; @zettawatt_per_kilogram: prefix!(zetta); "ZW/kg", "zettawatt per kilogram", "zettawatts per kilogram"; @exawatt_per_kilogram: prefix!(exa); "EW/kg", "exawatt per kilogram", "exawatts per kilogram"; @petawatt_per_kilogram: prefix!(peta); "PW/kg", "petawatt per kilogram", "petawatts per kilogram"; @terawatt_per_kilogram: prefix!(tera); "TW/kg", "terawatt per kilogram", "terawatts per kilogram"; @gigawatt_per_kilogram: prefix!(giga); "GW/kg", "gigawatt per kilogram", "gigawatts per kilogram"; @megawatt_per_kilogram: prefix!(mega); "MW/kg", "megawatt per kilogram", "megawatts per kilogram"; @kilowatt_per_kilogram: prefix!(kilo); "kW/kg", "kilowatt per kilogram", "kilowatts per kilogram"; @hectowatt_per_kilogram: prefix!(hecto); "hW/kg", "hectowatt per kilogram", "hectowatts per kilogram"; @decawatt_per_kilogram: prefix!(deca); "daW/kg", "decawatt per kilogram", "decawatts per kilogram"; /// Derived unit of specific power. @watt_per_kilogram: prefix!(none); "W/kg", "watt per kilogram", "watts per kilogram"; @deciwatt_per_kilogram: prefix!(deci); "dW/kg", "deciwatt per kilogram", "deciwatts per kilogram"; @centiwatt_per_kilogram: prefix!(centi); "cW/kg", "centiwatt per kilogram", "centiwatts per kilogram"; @milliwatt_per_kilogram: prefix!(milli); "mW/kg", "milliwatt per kilogram", "milliwatts per kilogram"; @microwatt_per_kilogram: prefix!(micro); "µW/kg", "microwatt per kilogram", "microwatts per kilogram"; @nanowatt_per_kilogram: prefix!(nano); "nW/kg", "nanowatt per kilogram", "nanowatts per kilogram"; @picowatt_per_kilogram: prefix!(pico); "pW/kg", "picowatt per kilogram", "picowatts per kilogram"; @femtowatt_per_kilogram: prefix!(femto); "fW/kg", "femtowatt per kilogram", "femtowatts per kilogram"; @attowatt_per_kilogram: prefix!(atto); "aW/kg", "attowatt per kilogram", "attowatts per kilogram"; @zeptowatt_per_kilogram: prefix!(zepto); "zW/kg", "zeptowatt per kilogram", "zeptowatts per kilogram"; @yoctowatt_per_kilogram: prefix!(yocto); "yW/kg", "yoctowatt per kilogram", "yoctowatts per kilogram"; /// Less commonly used, but more accurate (reduced) derived unit of specific power. @square_meter_per_cubic_second: 1.0_E0; "m² · s⁻³", "square meter per cubic second", "square meters per cubic second"; @erg_per_second_per_kilogram: 1.0_E-7; "(erg/s)/kg", "erg per second per kilogram", "ergs per second per kilogram"; @foot_pound_per_hour_per_pound: 3.766_161_111_111_111_E-4 / 4.535_924_E-1; "(ft · lbf/h)/lb", "foot pound-force per hour per pound", "foot pounds-force per hour per pound"; @foot_pound_per_minute_per_pound: 2.259_696_666_666_666_6_E-2 / 4.535_924_E-1; "(ft · lbf/min)/lb", "foot pound-force per minute per pound", "foot pounds-force per minute per pound"; @foot_pound_per_second_per_pound: 1.355_818 / 4.535_924_E-1; "(ft · lbf/s)/lb", "foot pound-force per second per pound", "foot pounds-force per second per pound"; @horsepower_per_pound: 7.456_999_E2 / 4.535_924_E-1; "hp/lb", "horsepower per pound", "horsepower per pound"; @horsepower_boiler_per_pound: 9.809_50_E3 / 4.535_924_E-1; "(hp (S))/lb", "horsepower (boiler) per pound", "horsepower (boiler) per pound"; @horsepower_electric_per_pound: 7.46_E2 / 4.535_924_E-1; "(hp (E))/lb", "horsepower (electric) per pound", "horsepower (electric) per pound"; @horsepower_metric_per_pound: 7.354_988_E2 / 4.535_924_E-1; "(hp (M))/lb", "metric horsepower per pound", "metric horsepower per pound"; @horsepower_imperial_per_pound: 7.457_0_E2 / 4.535_924_E-1; "(hp (I))/lb", "horsepower (Imperial) per pound", "horsepower (Imperial) per pound"; @hydraulic_horsepower_per_pound: 7.460_43_E2 / 4.535_924_E-1; "(hp (hydraulic))/lb", "hydraulic horsepower per pound", "hydraulic horsepower per pound"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::energy as e; use crate::si::mass as m; use crate::si::power as p; use crate::si::quantities::*; use crate::si::specific_power as sp; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: SpecificPower = Power::new::(V::one()) / Mass::new::(V::one()); } #[test] fn check_units_power() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, M: m::Conversion, SP: sp::Conversion>() { Test::assert_approx_eq(&SpecificPower::new::(V::one()), &(Power::new::

(V::one()) / Mass::new::(V::one()))); } } #[test] fn check_units_energy() { test::(); test::(); test::(); test::(); fn test, T: t::Conversion, M: m::Conversion, SP: sp::Conversion>() { Test::assert_approx_eq(&SpecificPower::new::(V::one()), &((Energy::new::(V::one()) / Time::new::(V::one())) / Mass::new::(V::one()))); } } } } uom-0.35.0/src/si/specific_radioactivity.rs000064400000000000000000000042461046102023000170070ustar 00000000000000//! Specific radioactivity (base unit becquerel per kilogram, kg⁻¹ · s⁻¹). quantity! { /// Specific radioactivity (base unit becquerel per kilogram, kg⁻¹ · s⁻¹). quantity: SpecificRadioactivity; "specific radioactivity"; /// Dimension of specific radioactivity, M⁻¹T⁻¹ (base unit becquerel per kilogram, kg⁻¹ · s⁻¹). dimension: ISQ< Z0, // length N1, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @becquerel_per_kilogram: prefix!(none); "Bq/kg", "becquerel per kilogram", "becquerels per kilogram"; @curie_per_kilogram: 3.7_E10; "Ci/kg", "curie per kilogram", "curie per kilogram"; @disintegrations_per_minute_per_kilogram: 1.0 / 6.0_E1; "dpm/kg", "disintegration per minute per kilogram", "disintegrations per minute per kilogram"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::radioactivity as rad; use crate::si::specific_radioactivity as srad; use crate::si::quantities::*; use crate::si::mass as m; use crate::tests::Test; #[test] fn check_dimension() { let _: SpecificRadioactivity = (Radioactivity::new::(V::one()) / Mass::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); fn test, M: m::Conversion, SRAD: srad::Conversion>() { Test::assert_approx_eq(&SpecificRadioactivity::new::(V::one()), &(Radioactivity::new::(V::one()) / Mass::new::(V::one())).into()); } } } } uom-0.35.0/src/si/specific_volume.rs000064400000000000000000000044231046102023000154400ustar 00000000000000//! Specific volume (base unit cubic meter per kilogram, m³ · kg⁻¹). quantity! { /// Specific volume (base unit cubic meter per kilogram, m³ · kg⁻¹). quantity: SpecificVolume; "specific volume"; /// Dimension of specific volume, L³M⁻¹ (base unit cubic meter per kilogram, m³ · kg⁻¹). dimension: ISQ< P3, // length N1, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @cubic_meter_per_kilogram: prefix!(none); "m³/kg", "cubic meter per kilogram", "cubic meters per kilogram"; @cubic_centimeter_per_kilogram: prefix!(centi) * prefix!(centi) * prefix!(centi); "cm³/kg", "cubic centimeter per kilogram", "cubic centimeters per kilogram"; @cubic_meter_per_gram: prefix!(none) / prefix!(milli); "m³/g", "cubic meter per gram", "cubic meters per gram"; @cubic_centimeter_per_gram: prefix!(centi) * prefix!(centi) * prefix!(centi) / prefix!(milli); "cm³/g", "cubic centimeter per gram", "cubic centimeters per gram"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::volume as a; use crate::si::mass as m; use crate::si::specific_volume as sv; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: SpecificVolume = Volume::new::(V::one()) / Mass::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); fn test, M: m::Conversion, SV: sv::Conversion>() { Test::assert_eq(&SpecificVolume::new::(V::one()), &(Volume::new::(V::one()) / Mass::new::(V::one()))); } } } } uom-0.35.0/src/si/surface_electric_current_density.rs000064400000000000000000000044601046102023000210700ustar 00000000000000//! Surface electric current density (base unit ampere per meter, ). quantity! { /// Surface electric current density (base unit ampere per meter, m⁻¹ · A). quantity: SurfaceElectricCurrentDensity; "surface electric current density"; /// Dimension of surface electric current density, IL⁻¹ (base unit ampere per meter, m⁻¹ · A). dimension: ISQ< N1, // length Z0, // mass Z0, // time P1, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @ampere_per_meter: prefix!(none); "A/m", "ampere per meter", "amperes per meter"; @ampere_per_centimeter: prefix!(none) / prefix!(centi) ; "A/cm", "ampere per centimeter", "amperes per centimeter"; @ampere_per_millimeter: prefix!(none) / prefix!(milli) ; "A/mm", "ampere per millimeter", "amperes per millimeter"; @ampere_per_micrometer: prefix!(none) / prefix!(micro) ; "A/μm", "ampere per micrometer", "amperes per micrometer"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::length as l; use crate::si::electric_current as i; use crate::si::surface_electric_current_density as ecd; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: SurfaceElectricCurrentDensity = (ElectricCurrent::new::(V::one()) / Length::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); fn test, L: l::Conversion, ECD: ecd::Conversion>() { Test::assert_approx_eq(&SurfaceElectricCurrentDensity::new::(V::one()), &(ElectricCurrent::new::(V::one()) / Length::new::(V::one())).into()); } } } } uom-0.35.0/src/si/temperature_coefficient.rs000064400000000000000000000033271046102023000171610ustar 00000000000000//! Temperature coefficient (base unit 1 / kelvin, K⁻¹). quantity! { /// Temperature coefficient (base unit 1 / kelvin, K⁻¹). quantity: TemperatureCoefficient; "temperature coefficient"; /// Dimension of temperature coefficient, Th⁻¹ (base unit 1 / kelvin, K⁻¹). dimension: ISQ< Z0, // length Z0, // mass Z0, // time Z0, // electric current N1, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @per_kelvin: prefix!(none); "K⁻¹", "per kelvin", "per kelvin"; @ppm_per_kelvin: 1E-6; "ppm/K", "ppm per kelvin", "ppm per kelvin"; @ppm_per_degree_celsius: 1E-6; "ppm/°C", "ppm per degree Celsius", "ppm per degree Celsius"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::temperature_interval as ti; use crate::si::temperature_coefficient as tc; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: TemperatureCoefficient = V::one() / TemperatureInterval::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); fn test, TC: tc::Conversion>() { Test::assert_approx_eq(&TemperatureCoefficient::new::(V::one()), &(V::one() / TemperatureInterval::new::(V::one()))); } } } } uom-0.35.0/src/si/temperature_gradient.rs000064400000000000000000000051211046102023000164720ustar 00000000000000//! Temperature gradient (base unit kelvin per meter, m⁻¹ · K). quantity! { /// Temperature gradient (base unit kelvin per meter, m⁻¹ · K). quantity: TemperatureGradient; "temperature gradient"; /// Dimension of temperature gradient, L⁻¹Th (base unit kelvin per meter, K · m⁻¹). dimension: ISQ< N1, // length Z0, // mass Z0, // time Z0, // electric current P1, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @kelvin_per_kilometer: prefix!(none) / prefix!(kilo); "K/km", "kelvin per kilometer", "kelvins per kilometer"; @kelvin_per_hectometer: prefix!(none) / prefix!(hecto); "K/hm", "kelvin per hectometer", "kelvins per hectometer"; @kelvin_per_meter: prefix!(none); "K/m", "kelvin per meter", "kelvins per meter"; @kelvin_per_centimeter: prefix!(none) / prefix!(centi); "K/cm", "kelvin per centimeter", "kelvins per centimeter"; @kelvin_per_millimeter: prefix!(none) / prefix!(milli); "K/mm", "kelvin per millimeter", "kelvins per millimeter"; @kelvin_per_micrometer: prefix!(none) / prefix!(micro); "K/µm", "kelvin per micrometer", "kelvins per micrometer"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::temperature_gradient as tg; use crate::si::temperature_interval as ti; use crate::si::quantities::*; use crate::si::length as l; use crate::tests::Test; #[test] fn check_dimension() { let _: TemperatureGradient = TemperatureInterval::new::(V::one()) / Length::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); fn test, L: l::Conversion, TG: tg::Conversion>() { Test::assert_approx_eq(&TemperatureGradient::new::(V::one()), &(TemperatureInterval::new::(V::one()) / Length::new::(V::one()))); } } } } uom-0.35.0/src/si/temperature_interval.rs000064400000000000000000000113101046102023000165160ustar 00000000000000//! Temperature interval (base unit kelvin, K). //! //! Temperature interval has the same dimensions as [thermodynamic temperature][tt] but is not //! directly comparable. See [thermodynamic temperature][tt] for a full explanation. //! //! [tt]: ../thermodynamic_temperature/index.html use crate::si::thermodynamic_temperature::ThermodynamicTemperature; quantity! { /// Temperature interval (base unit kelvin, K). quantity: TemperatureInterval; "temperature interval"; /// Dimension of temperature interval, Th (base unit kelvin, K). dimension: ISQ< Z0, // length Z0, // mass Z0, // time Z0, // electric current P1, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottakelvin: prefix!(yotta); "YK", "yottakelvin", "yottakelvins"; @zettakelvin: prefix!(zetta); "ZK", "zettakelvin", "zettakelvins"; @exakelvin: prefix!(exa); "EK", "exakelvin", "exakelvins"; @petakelvin: prefix!(peta); "PK", "petakelvin", "petakelvins"; @terakelvin: prefix!(tera); "TK", "terakelvin", "terakelvins"; @gigakelvin: prefix!(giga); "GK", "gigakelvin", "gigakelvins"; @megakelvin: prefix!(mega); "MK", "megakelvin", "megakelvins"; @kilokelvin: prefix!(kilo); "kK", "kilokelvin", "kilokelvins"; @hectokelvin: prefix!(hecto); "hK", "hectokelvin", "hectokelvins"; @decakelvin: prefix!(deca); "daK", "decakelvin", "decakelvins"; /// The kelvin is the SI unit of thermodynamic temperature. It is defined by taking the /// fixed numerical value of the Boltzmann constant *k* to be 1.380 649 × 10⁻²³ when /// expressed in the unit J K⁻¹, which is equal to kg m² s⁻² K⁻¹, where the kilogram, meter, /// and second are defined in terms of *h*, *c*, and ∆*ν*Cs. @kelvin: prefix!(none); "K", "kelvin", "kelvins"; @decikelvin: prefix!(deci); "dK", "decikelvin", "decikelvins"; @centikelvin: prefix!(centi); "cK", "centikelvin", "centikelvins"; @millikelvin: prefix!(milli); "mK", "millikelvin", "millikelvins"; @microkelvin: prefix!(micro); "µK", "microkelvin", "microkelvins"; @nanokelvin: prefix!(nano); "nK", "nanokelvin", "nanokelvins"; @picokelvin: prefix!(pico); "pK", "picokelvin", "picokelvins"; @femtokelvin: prefix!(femto); "fK", "femtokelvin", "femtokelvins"; @attokelvin: prefix!(atto); "aK", "attokelvin", "attokelvins"; @zeptokelvin: prefix!(zepto); "zK", "zeptokelvin", "zeptokelvins"; @yoctokelvin: prefix!(yocto); "yK", "yoctokelvin", "yoctokelvins"; @degree_celsius: 1.0_E0; "°C", "degree Celsius", "degrees Celsius"; @degree_fahrenheit: 5.0_E0 / 9.0_E0; "°F", "degree Fahrenheit", "degrees Fahrenheit"; @degree_rankine: 5.0_E0 / 9.0_E0; "°R", "degree Rankine", "degrees Rankine"; } } #[cfg(feature = "autoconvert")] impl crate::lib::ops::Add> for TemperatureInterval where Ul: super::Units + ?Sized, Ur: super::Units + ?Sized, V: crate::num::Num + crate::Conversion, { type Output = ThermodynamicTemperature; #[inline(always)] fn add(self, rhs: ThermodynamicTemperature) -> Self::Output { super::Quantity { dimension: crate::lib::marker::PhantomData, units: crate::lib::marker::PhantomData, value: self.value + super::change_base::(&rhs.value), } } } #[cfg(not(feature = "autoconvert"))] impl crate::lib::ops::Add> for TemperatureInterval where U: super::Units + ?Sized, V: crate::num::Num + crate::Conversion, { type Output = ThermodynamicTemperature; #[inline(always)] fn add(self, rhs: ThermodynamicTemperature) -> Self::Output { super::Quantity { dimension: crate::lib::marker::PhantomData, units: crate::lib::marker::PhantomData, value: self.value + rhs.value, } } } #[cfg(test)] mod tests { storage_types! { use crate::si::quantities::*; use crate::si::temperature_interval as ti; use crate::si::thermodynamic_temperature as tt; use crate::tests::{A, Test}; quickcheck! { #[allow(trivial_casts)] fn add(l: A, r: A) -> bool { Test::eq(&ThermodynamicTemperature::::new::(&*l + &*r), &(TemperatureInterval::::new::((*l).clone()) + ThermodynamicTemperature::::new::((*r).clone()))) } } } } uom-0.35.0/src/si/thermal_conductance.rs000064400000000000000000000357171046102023000163000ustar 00000000000000//! Thermal conductance (base unit watt per kelvin, kg · m² · s⁻³ · K⁻¹). //! //! Thermal conductance has the same kind as [temperature interval][ti], as this quantity relates //! to change of temperature. Not of kind `TemperatureKind`, used by [thermodynamic //! temperature][tt]. See [thermodynamic temperature][tt] for a full explanation. //! //! [ti]: ../temperature_interval/index.html //! [tt]: ../thermodynamic_temperature/index.html quantity! { /// Thermal conductance (base unit watt per kelvin, kg · m² · s⁻³ · K⁻¹). quantity: ThermalConductance; "thermal conductance"; /// Dimension of thermal conductance, LM²T⁻³Th⁻¹ (base unit watt per kelvin, kg · m² · s⁻³ /// · K⁻¹). dimension: ISQ< P2, // length P1, // mass N3, // time Z0, // electric current N1, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottagram_meter_squared_per_second_cubed_kelvin: prefix!(yotta) / prefix!(kilo); "Yg · m²/(s³ · K)", "yottagram meter squared per second cubed kelvin", "yottagrams meter squared per second cubed kelvin"; @zettagram_meter_squared_per_second_cubed_kelvin: prefix!(zetta) / prefix!(kilo); "Zg · m²/(s³ · K)", "zettagram meter squared per second cubed kelvin", "zettagrams meter squared per second cubed kelvin"; @exagram_meter_squared_per_second_cubed_kelvin: prefix!(exa) / prefix!(kilo); "Eg · m²/(s³ · K)", "exagram meter squared per second cubed kelvin", "exagrams meter squared per second cubed kelvin"; @petagram_meter_squared_per_second_cubed_kelvin: prefix!(peta) / prefix!(kilo); "Pg · m²/(s³ · K)", "petagram meter squared per second cubed kelvin", "petagrams meter squared per second cubed kelvin"; @teragram_meter_squared_per_second_cubed_kelvin: prefix!(tera) / prefix!(kilo); "Tg · m²/(s³ · K)", "teragram meter squared per second cubed kelvin", "teragrams meter squared per second cubed kelvin"; @gigagram_meter_squared_per_second_cubed_kelvin: prefix!(giga) / prefix!(kilo); "Gg · m²/(s³ · K)", "gigagram meter squared per second cubed kelvin", "gigagrams meter squared per second cubed kelvin"; @megagram_meter_squared_per_second_cubed_kelvin: prefix!(mega) / prefix!(kilo); "Mg · m²/(s³ · K)", "megagram meter squared per second cubed kelvin", "megagrams meter squared per second cubed kelvin"; /// Derived unit of thermal conductance in base units. Equivalent to W/K. @kilogram_meter_squared_per_second_cubed_kelvin: prefix!(kilo) / prefix!(kilo); "kg · m²/(s³ · K)", "kilogram meter squared per second cubed kelvin", "kilograms meter squared per second cubed kelvin"; @hectogram_meter_squared_per_second_cubed_kelvin: prefix!(hecto) / prefix!(kilo); "hg · m²/(s³ · K)", "hectogram meter squared per second cubed kelvin", "hectograms meter squared per second cubed kelvin"; @decagram_meter_squared_per_second_cubed_kelvin: prefix!(deca) / prefix!(kilo); "dag · m²/(s³ · K)", "decagram meter squared per second cubed kelvin", "decagrams meter squared per second cubed kelvin"; @gram_meter_squared_per_second_cubed_kelvin: prefix!(none) / prefix!(kilo); "g · m/(s³ · K)", "gram meter squared per second cubed kelvin", "grams meter squared per second cubed kelvin"; @decigram_meter_squared_per_second_cubed_kelvin: prefix!(deci) / prefix!(kilo); "dg · m²/(s³ · K)", "decigram meter squared per second cubed kelvin", "decigrams meter squared per second cubed kelvin"; @centigram_meter_squared_per_second_cubed_kelvin: prefix!(centi) / prefix!(kilo); "cg · m²/(s³ · K)", "centigram meter squared per second cubed kelvin", "centigrams meter squared per second cubed kelvin"; @milligram_meter_squared_per_second_cubed_kelvin: prefix!(milli) / prefix!(kilo); "mg · m²/(s³ · K)", "milligram meter squared per second cubed kelvin", "milligrams meter squared per second cubed kelvin"; @microgram_meter_squared_per_second_cubed_kelvin: prefix!(micro) / prefix!(kilo); "µg · m/(s³ · K)", "microgram meter squared per second cubed kelvin", "micrograms meter squared per second cubed kelvin"; @nanogram_meter_squared_per_second_cubed_kelvin: prefix!(nano) / prefix!(kilo); "ng · m²/(s³ · K)", "nanogram meter squared per second cubed kelvin", "nanograms meter squared per second cubed kelvin"; @picogram_meter_squared_per_second_cubed_kelvin: prefix!(pico) / prefix!(kilo); "pg · m²/(s³ · K)", "picogram meter squared per second cubed kelvin", "picograms meter squared per second cubed kelvin"; @femtogram_meter_squared_per_second_cubed_kelvin: prefix!(femto) / prefix!(kilo); "fg · m²/(s³ · K)", "femtogram meter squared per second cubed kelvin", "femtograms meter squared per second cubed kelvin"; @attogram_meter_squared_per_second_cubed_kelvin: prefix!(atto) / prefix!(kilo); "ag · m²/(s³ · K)", "attogram meter squared per second cubed kelvin", "attograms meter squared per second cubed kelvin"; @zeptogram_meter_squared_per_second_cubed_kelvin: prefix!(zepto) / prefix!(kilo); "zg · m²/(s³ · K)", "zeptogram meter squared per second cubed kelvin", "zeptograms meter squared per second cubed kelvin"; @yoctogram_meter_squared_per_second_cubed_kelvin: prefix!(yocto) / prefix!(kilo); "yg · m²/(s³ · K)", "yoctogram meter squared per second cubed kelvin", "yoctograms meter squared per second cubed kelvin"; // Thermal conductance is much more commonly expressed in terms of power / temperature. @yottawatt_per_kelvin: prefix!(yotta); "YW/K", "yottawatt per kelvin", "yottawatts per kelvin"; @zettawatt_per_kelvin: prefix!(zetta); "ZW/K", "zettawatt per kelvin", "zettawatts per kelvin"; @exawatt_per_kelvin: prefix!(exa); "EW/K", "exawatt per kelvin", "exawatts per kelvin"; @petawatt_per_kelvin: prefix!(peta); "PW/K", "petawatt per kelvin", "petawatts per kelvin"; @terawatt_per_kelvin: prefix!(tera); "TW/K", "terawatt per kelvin", "terawatts per kelvin"; @gigawatt_per_kelvin: prefix!(giga); "GW/K", "gigawatt per kelvin", "gigawatts per kelvin"; @megawatt_per_kelvin: prefix!(mega); "MW/K", "megawatt per kelvin", "megawatts per kelvin"; @kilowatt_per_kelvin: prefix!(kilo); "kW/K", "kilowatt per kelvin", "kilowatts per kelvin"; @hectowatt_per_kelvin: prefix!(hecto); "hW/K", "hectowatt per kelvin", "hectowatts per kelvin"; @decawatt_per_kelvin: prefix!(deca); "daW/K", "decawatt per kelvin", "decawatts per kelvin"; /// Derived unit of thermal conductance in derived units. Equivalent to kg · m²/(s³ · K). @watt_per_kelvin: prefix!(none); "W/K", "watt per kelvin", "watts per kelvin"; @deciwatt_per_kelvin: prefix!(deci); "dW/K", "deciwatt per kelvin", "deciwatts per kelvin"; @centiwatt_per_kelvin: prefix!(centi); "cW/K", "centiwatt per kelvin", "centiwatts per kelvin"; @milliwatt_per_kelvin: prefix!(milli); "mW/K", "milliwatt per kelvin", "milliwatts per kelvin"; @microwatt_per_kelvin: prefix!(micro); "µW/K", "microwatt per kelvin", "microwatts per kelvin"; @nanowatt_per_kelvin: prefix!(nano); "nW/K", "nanowatt per kelvin", "nanowatts per kelvin"; @picowatt_per_kelvin: prefix!(pico); "pW/K", "picowatt per kelvin", "picowatts per kelvin"; @femtowatt_per_kelvin: prefix!(femto); "fW/K", "femtowatt per kelvin", "femtowatts per kelvin"; @attowatt_per_kelvin: prefix!(atto); "aW/K", "attowatt per kelvin", "attowatts per kelvin"; @zeptowatt_per_kelvin: prefix!(zepto); "zW/K", "zeptowatt per kelvin", "zeptowatts per kelvin"; @yoctowatt_per_kelvin: prefix!(yocto); "yW/K", "yoctowatt per kelvin", "yoctowatts per kelvin"; // Celsius for convenience. @kilogram_meter_squared_per_second_cubed_degree_celsius: prefix!(kilo) / prefix!(kilo); "kg · m²/(s³ · °C)", "kilogram meter squared per second cubed degree Celsius", "kilograms meter squared per second cubed degree Celsius"; @kilowatt_per_degree_celsius: prefix!(kilo); "kW/°C", "kilowatt per degree Celsius", "kilowatts per degree Celsius"; /// Derived unit of thermal conductance in derived units. Equivalent to kg · m²/(s³ · K). @watt_per_meter_degree_celsius: prefix!(none); "W/°C", "watt per degree Celsius", "watts per degree Celsius"; @milliwatt_per_degree_celsius: prefix!(milli); "mW/°C", "milliwatt per degree Celsius", "milliwatts per degree Celsius"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::length as l; use crate::si::mass as m; use crate::si::power as p; use crate::si::quantities::*; use crate::si::temperature_interval as ti; use crate::si::thermal_conductance as tc; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: ThermalConductance = Mass::new::(V::one()) * Length::new::(V::one()) * Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * Time::new::(V::one()) * TemperatureInterval::new::(V::one())); } #[test] fn check_base_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test< M: m::Conversion, TI: ti::Conversion, TC: tc::Conversion>() { Test::assert_approx_eq(&ThermalConductance::new::(V::one()), &(Mass::new::(V::one()) * Length::new::(V::one()) * Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * Time::new::(V::one()) * TemperatureInterval::new::(V::one())))); } } #[test] fn check_power_ti_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test< P: p::Conversion, TI: ti::Conversion, TC: tc::Conversion>() { Test::assert_approx_eq(&ThermalConductance::new::(V::one()), &(Power::new::

(V::one()) / TemperatureInterval::new::(V::one()))); } } } } uom-0.35.0/src/si/thermal_conductivity.rs000064400000000000000000000362541046102023000165330ustar 00000000000000//! Thermal conductivity (base unit watt per meter kelvin, kg · m · s⁻³ · K⁻¹). //! //! Thermal conductivity has the same kind as [temperature interval][ti], as this quantity relates //! to change of temperature. Not of kind `TemperatureKind`, used by [thermodynamic //! temperature][tt]. See [thermodynamic temperature][tt] for a full explanation. //! //! [ti]: ../temperature_interval/index.html //! [tt]: ../thermodynamic_temperature/index.html quantity! { /// Thermal conductivity (base unit watt per meter kelvin, kg · m · s⁻³ · K⁻¹). quantity: ThermalConductivity; "thermal conductivity"; /// Dimension of thermal conductivity, LMT⁻³Th⁻¹ (base unit watt per meter kelvin, kg · m · s⁻³ /// · K⁻¹). dimension: ISQ< P1, // length P1, // mass N3, // time Z0, // electric current N1, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottagram_meter_per_second_cubed_kelvin: prefix!(yotta) / prefix!(kilo); "Yg · m/(s³ · K)", "yottagram meter per second cubed kelvin", "yottagrams meter per second cubed kelvin"; @zettagram_meter_per_second_cubed_kelvin: prefix!(zetta) / prefix!(kilo); "Zg · m/(s³ · K)", "zettagram meter per second cubed kelvin", "zettagrams meter per second cubed kelvin"; @exagram_meter_per_second_cubed_kelvin: prefix!(exa) / prefix!(kilo); "Eg · m/(s³ · K)", "exagram meter per second cubed kelvin", "exagrams meter per second cubed kelvin"; @petagram_meter_per_second_cubed_kelvin: prefix!(peta) / prefix!(kilo); "Pg · m/(s³ · K)", "petagram meter per second cubed kelvin", "petagrams meter per second cubed kelvin"; @teragram_meter_per_second_cubed_kelvin: prefix!(tera) / prefix!(kilo); "Tg · m/(s³ · K)", "teragram meter per second cubed kelvin", "teragrams meter per second cubed kelvin"; @gigagram_meter_per_second_cubed_kelvin: prefix!(giga) / prefix!(kilo); "Gg · m/(s³ · K)", "gigagram meter per second cubed kelvin", "gigagrams meter per second cubed kelvin"; @megagram_meter_per_second_cubed_kelvin: prefix!(mega) / prefix!(kilo); "Mg · m/(s³ · K)", "megagram meter per second cubed kelvin", "megagrams meter per second cubed kelvin"; /// Derived unit of thermal conductivity in base units. Equivalent to W/(m · K). @kilogram_meter_per_second_cubed_kelvin: prefix!(kilo) / prefix!(kilo); "kg · m/(s³ · K)", "kilogram meter per second cubed kelvin", "kilograms meter per second cubed kelvin"; @hectogram_meter_per_second_cubed_kelvin: prefix!(hecto) / prefix!(kilo); "hg · m/(s³ · K)", "hectogram meter per second cubed kelvin", "hectograms meter per second cubed kelvin"; @decagram_meter_per_second_cubed_kelvin: prefix!(deca) / prefix!(kilo); "dag · m/(s³ · K)", "decagram meter per second cubed kelvin", "decagrams meter per second cubed kelvin"; @gram_meter_per_second_cubed_kelvin: prefix!(none) / prefix!(kilo); "g · m/(s³ · K)", "gram meter per second cubed kelvin", "grams meter per second cubed kelvin"; @decigram_meter_per_second_cubed_kelvin: prefix!(deci) / prefix!(kilo); "dg · m/(s³ · K)", "decigram meter per second cubed kelvin", "decigrams meter per second cubed kelvin"; @centigram_meter_per_second_cubed_kelvin: prefix!(centi) / prefix!(kilo); "cg · m/(s³ · K)", "centigram meter per second cubed kelvin", "centigrams meter per second cubed kelvin"; @milligram_meter_per_second_cubed_kelvin: prefix!(milli) / prefix!(kilo); "mg · m/(s³ · K)", "milligram meter per second cubed kelvin", "milligrams meter per second cubed kelvin"; @microgram_meter_per_second_cubed_kelvin: prefix!(micro) / prefix!(kilo); "µg · m/(s³ · K)", "microgram meter per second cubed kelvin", "micrograms meter per second cubed kelvin"; @nanogram_meter_per_second_cubed_kelvin: prefix!(nano) / prefix!(kilo); "ng · m/(s³ · K)", "nanogram meter per second cubed kelvin", "nanograms meter per second cubed kelvin"; @picogram_meter_per_second_cubed_kelvin: prefix!(pico) / prefix!(kilo); "pg · m/(s³ · K)", "picogram meter per second cubed kelvin", "picograms meter per second cubed kelvin"; @femtogram_meter_per_second_cubed_kelvin: prefix!(femto) / prefix!(kilo); "fg · m/(s³ · K)", "femtogram meter per second cubed kelvin", "femtograms meter per second cubed kelvin"; @attogram_meter_per_second_cubed_kelvin: prefix!(atto) / prefix!(kilo); "ag · m/(s³ · K)", "attogram meter per second cubed kelvin", "attograms meter per second cubed kelvin"; @zeptogram_meter_per_second_cubed_kelvin: prefix!(zepto) / prefix!(kilo); "zg · m/(s³ · K)", "zeptogram meter per second cubed kelvin", "zeptograms meter per second cubed kelvin"; @yoctogram_meter_per_second_cubed_kelvin: prefix!(yocto) / prefix!(kilo); "yg · m/(s³ · K)", "yoctogram meter per second cubed kelvin", "yoctograms meter per second cubed kelvin"; // Thermal conductivity is much more commonly expressed in terms of // power / (length · temperature). @yottawatt_per_meter_kelvin: prefix!(yotta); "YW/(m · K)", "yottawatt per meter kelvin", "yottawatts per meter kelvin"; @zettawatt_per_meter_kelvin: prefix!(zetta); "ZW/(m · K)", "zettawatt per meter kelvin", "zettawatts per meter kelvin"; @exawatt_per_meter_kelvin: prefix!(exa); "EW/(m · K)", "exawatt per meter kelvin", "exawatts per meter kelvin"; @petawatt_per_meter_kelvin: prefix!(peta); "PW/(m · K)", "petawatt per meter kelvin", "petawatts per meter kelvin"; @terawatt_per_meter_kelvin: prefix!(tera); "TW/(m · K)", "terawatt per meter kelvin", "terawatts per meter kelvin"; @gigawatt_per_meter_kelvin: prefix!(giga); "GW/(m · K)", "gigawatt per meter kelvin", "gigawatts per meter kelvin"; @megawatt_per_meter_kelvin: prefix!(mega); "MW/(m · K)", "megawatt per meter kelvin", "megawatts per meter kelvin"; @kilowatt_per_meter_kelvin: prefix!(kilo); "kW/(m · K)", "kilowatt per meter kelvin", "kilowatts per meter kelvin"; @hectowatt_per_meter_kelvin: prefix!(hecto); "hW/(m · K)", "hectowatt per meter kelvin", "hectowatts per meter kelvin"; @decawatt_per_meter_kelvin: prefix!(deca); "daW/(m · K)", "decawatt per meter kelvin", "decawatts per meter kelvin"; /// Derived unit of thermal conductivity in derived units. Equivalent to kg · m/(s³ · K). @watt_per_meter_kelvin: prefix!(none); "W/(m · K)", "watt per meter kelvin", "watts per meter kelvin"; @deciwatt_per_meter_kelvin: prefix!(deci); "dW/(m · K)", "deciwatt per meter kelvin", "deciwatts per meter kelvin"; @centiwatt_per_meter_kelvin: prefix!(centi); "cW/(m · K)", "centiwatt per meter kelvin", "centiwatts per meter kelvin"; @milliwatt_per_meter_kelvin: prefix!(milli); "mW/(m · K)", "milliwatt per meter kelvin", "milliwatts per meter kelvin"; @microwatt_per_meter_kelvin: prefix!(micro); "µW/(m · K)", "microwatt per meter kelvin", "microwatts per meter kelvin"; @nanowatt_per_meter_kelvin: prefix!(nano); "nW/(m · K)", "nanowatt per meter kelvin", "nanowatts per meter kelvin"; @picowatt_per_meter_kelvin: prefix!(pico); "pW/(m · K)", "picowatt per meter kelvin", "picowatts per meter kelvin"; @femtowatt_per_meter_kelvin: prefix!(femto); "fW/(m · K)", "femtowatt per meter kelvin", "femtowatts per meter kelvin"; @attowatt_per_meter_kelvin: prefix!(atto); "aW/(m · K)", "attowatt per meter kelvin", "attowatts per meter kelvin"; @zeptowatt_per_meter_kelvin: prefix!(zepto); "zW/(m · K)", "zeptowatt per meter kelvin", "zeptowatts per meter kelvin"; @yoctowatt_per_meter_kelvin: prefix!(yocto); "yW/(m · K)", "yoctowatt per meter kelvin", "yoctowatts per meter kelvin"; // Celsius for convenience. @kilogram_meter_per_second_cubed_degree_celsius: prefix!(kilo) / prefix!(kilo); "kg · m/(s³ · °C)", "kilogram meter per second cubed degree celsius", "kilograms meter per second cubed degree celsius"; @kilowatt_per_meter_degree_celsius: prefix!(kilo); "kW/(m · °C)", "kilowatt per meter degree celsius", "kilowatts per meter degree celsius"; /// Derived unit of thermal conductivity in derived units. Equivalent to kg · m/(s³ · K). @watt_per_meter_degree_celsius: prefix!(none); "W/(m · °C)", "watt per meter degree celsius", "watts per meter degree celsius"; @milliwatt_per_meter_degree_celsius: prefix!(milli); "mW/(m · °C)", "milliwatt per meter degree celsius", "milliwatts per meter degree celsius"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::length as l; use crate::si::mass as m; use crate::si::power as p; use crate::si::quantities::*; use crate::si::temperature_interval as ti; use crate::si::thermal_conductivity as tc; use crate::si::time as t; use crate::tests::Test; #[test] fn check_dimension() { let _: ThermalConductivity = Mass::new::(V::one()) * Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * Time::new::(V::one()) * TemperatureInterval::new::(V::one())); } #[test] fn check_base_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test< M: m::Conversion, TI: ti::Conversion, TC: tc::Conversion>() { Test::assert_approx_eq(&ThermalConductivity::new::(V::one()), &(Mass::new::(V::one()) * Length::new::(V::one()) / (Time::new::(V::one()) * Time::new::(V::one()) * Time::new::(V::one()) * TemperatureInterval::new::(V::one())))); } } #[test] fn check_power_per_length_ti_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test< P: p::Conversion, L: l::Conversion, TI: ti::Conversion, TC: tc::Conversion>() { Test::assert_approx_eq(&ThermalConductivity::new::(V::one()), &(Power::new::

(V::one()) / (Length::new::(V::one()) * TemperatureInterval::new::(V::one())))); } } } } uom-0.35.0/src/si/thermodynamic_temperature.rs000064400000000000000000000235301046102023000175440ustar 00000000000000//! Thermodynamic temperature (base unit kelvin, K). //! //! Thermodynamic temperature has the same dimensions as [temperature //! interval](../temperature_interval/index.html) but is not directly comparable. Thermodynamic //! temperature is the absolute measure of temperature and is one of the [base quantities][base] in //! the [ISQ][isq]. Temperature interval is the measure of relative temperature difference between //! thermodynamic temperatures. //! #![cfg_attr(feature = "f32", doc = " ```rust,compile_fail")] #![cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")] //! # use uom::si::{temperature_interval, thermodynamic_temperature}; //! # use uom::si::f32::*; //! let tt = ThermodynamicTemperature::new::(1.0); //! let ti = TemperatureInterval::new::(1.0); //! //! // error[E0308]: mismatched types //! let err = tt == ti; //! ``` //! //! Additionally, addition and subtraction are not implemented for thermodynamic temperature. //! #![cfg_attr(feature = "f32", doc = " ```rust,compile_fail")] #![cfg_attr(not(feature = "f32"), doc = " ```rust,ignore")] //! # use uom::si::{temperature_interval, thermodynamic_temperature}; //! # use uom::si::f32::*; //! let t1 = ThermodynamicTemperature::new::(1.0); //! let t2 = ThermodynamicTemperature::new::(1.0); //! //! // error[E0308]: mismatched types //! let err = t1 + t2; //! ``` //! //! A temperature interval can be added to or subtracted from a thermodynamic temperature. //! #![cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #![cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] //! # use uom::si::{temperature_interval, thermodynamic_temperature}; //! # use uom::si::f32::*; //! let tt = ThermodynamicTemperature::new::(1.0); //! let ti = TemperatureInterval::new::(1.0); //! //! let result = tt + ti; //! ``` //! //! [base]: https://jcgm.bipm.org/vim/en/1.4.html //! [isq]: https://jcgm.bipm.org/vim/en/1.6.html use crate::si::temperature_interval::TemperatureInterval; quantity! { /// Thermodynamic temperature (base unit kelvin, K). quantity: ThermodynamicTemperature; "thermodynamic temperature"; /// Dimension of thermodynamic temperature, Th (base unit kelvin, K). dimension: ISQ< Z0, // length Z0, // mass Z0, // time Z0, // electric current P1, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::TemperatureKind); units { @yottakelvin: prefix!(yotta); "YK", "yottakelvin", "yottakelvins"; @zettakelvin: prefix!(zetta); "ZK", "zettakelvin", "zettakelvins"; @exakelvin: prefix!(exa); "EK", "exakelvin", "exakelvins"; @petakelvin: prefix!(peta); "PK", "petakelvin", "petakelvins"; @terakelvin: prefix!(tera); "TK", "terakelvin", "terakelvins"; @gigakelvin: prefix!(giga); "GK", "gigakelvin", "gigakelvins"; @megakelvin: prefix!(mega); "MK", "megakelvin", "megakelvins"; @kilokelvin: prefix!(kilo); "kK", "kilokelvin", "kilokelvins"; @hectokelvin: prefix!(hecto); "hK", "hectokelvin", "hectokelvins"; @decakelvin: prefix!(deca); "daK", "decakelvin", "decakelvins"; /// The kelvin is the SI unit of thermodynamic temperature. It is defined by taking the /// fixed numerical value of the Boltzmann constant *k* to be 1.380 649 × 10⁻²³ when /// expressed in the unit J K⁻¹, which is equal to kg m² s⁻² K⁻¹, where the kilogram, meter, /// and second are defined in terms of *h*, *c*, and ∆*ν*Cs. @kelvin: prefix!(none); "K", "kelvin", "kelvins"; @decikelvin: prefix!(deci); "dK", "decikelvin", "decikelvins"; @centikelvin: prefix!(centi); "cK", "centikelvin", "centikelvins"; @millikelvin: prefix!(milli); "mK", "millikelvin", "millikelvins"; @microkelvin: prefix!(micro); "µK", "microkelvin", "microkelvins"; @nanokelvin: prefix!(nano); "nK", "nanokelvin", "nanokelvins"; @picokelvin: prefix!(pico); "pK", "picokelvin", "picokelvins"; @femtokelvin: prefix!(femto); "fK", "femtokelvin", "femtokelvins"; @attokelvin: prefix!(atto); "aK", "attokelvin", "attokelvins"; @zeptokelvin: prefix!(zepto); "zK", "zeptokelvin", "zeptokelvins"; @yoctokelvin: prefix!(yocto); "yK", "yoctokelvin", "yoctokelvins"; @degree_celsius: 1.0_E0, 273.15_E0; "°C", "degree Celsius", "degrees Celsius"; @degree_fahrenheit: 5.0_E0 / 9.0_E0, 459.67_E0; "°F", "degree Fahrenheit", "degrees Fahrenheit"; @degree_rankine: 5.0_E0 / 9.0_E0; "°R", "degree Rankine", "degrees Rankine"; } } #[doc(hidden)] macro_rules! impl_ops { ( $AddSubTrait:ident, $addsub_fun:ident, $addsub_op:tt, $AddSubAssignTrait:ident, $addsubassign_fun:ident, $addsubassign_op:tt, $AddSubAlias:ident ) => { #[cfg(feature = "autoconvert")] impl $crate::lib::ops::$AddSubTrait> for ThermodynamicTemperature where Ul: super::Units + ?Sized, Ur: super::Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { type Output = ThermodynamicTemperature; #[inline(always)] fn $addsub_fun(self, rhs: TemperatureInterval) -> Self::Output { super::Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value $addsub_op super::change_base::(&rhs.value), } } } #[cfg(not(feature = "autoconvert"))] impl $crate::lib::ops::$AddSubTrait> for ThermodynamicTemperature where U: super::Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { type Output = ThermodynamicTemperature; #[inline(always)] fn $addsub_fun(self, rhs: TemperatureInterval) -> Self::Output { super::Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value $addsub_op rhs.value, } } } #[cfg(feature = "autoconvert")] impl $crate::lib::ops::$AddSubAssignTrait> for ThermodynamicTemperature where Ul: super::Units + ?Sized, Ur: super::Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::ops::$AddSubAssignTrait, { #[inline(always)] fn $addsubassign_fun(&mut self, rhs: TemperatureInterval) { self.value $addsubassign_op super::change_base::(&rhs.value); } } #[cfg(not(feature = "autoconvert"))] impl $crate::lib::ops::$AddSubAssignTrait> for ThermodynamicTemperature where U: super::Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::ops::$AddSubAssignTrait, { #[inline(always)] fn $addsubassign_fun(&mut self, rhs: TemperatureInterval) { self.value $addsubassign_op rhs.value; } } }; } impl_ops!(Add, add, +, AddAssign, add_assign, +=, Sum); impl_ops!(Sub, sub, -, SubAssign, sub_assign, -=, Diff); #[cfg(test)] mod tests { use crate::si::quantities::*; use crate::si::temperature_interval as ti; use crate::si::thermodynamic_temperature as tt; storage_types! { use crate::tests::*; use super::*; quickcheck! { #[allow(trivial_casts)] fn add(l: A, r: A) -> bool { Test::eq(&ThermodynamicTemperature::::new::(&*l + &*r), &(ThermodynamicTemperature::::new::((*l).clone()) + TemperatureInterval::::new::((*r).clone()))) } #[allow(trivial_casts)] fn sub(l: A, r: A) -> bool { Test::eq(&ThermodynamicTemperature::::new::(&*l - &*r), &(ThermodynamicTemperature::::new::((*l).clone()) - TemperatureInterval::::new::((*r).clone()))) } } } mod non_big { storage_types! { types: PrimInt, Rational, Rational32, Rational64, Float; use crate::tests::*; use super::super::*; quickcheck! { #[allow(trivial_casts)] fn add_assign(l: A, r: A) -> bool { let mut f = *l; let mut v = ThermodynamicTemperature::::new::(*l); f += *r; v += TemperatureInterval::::new::(*r); Test::approx_eq(&ThermodynamicTemperature::::new::(f), &v) } #[allow(trivial_casts)] fn sub_assign(l: A, r: A) -> bool { let mut f = *l; let mut v = ThermodynamicTemperature::::new::(*l); f -= *r; v -= TemperatureInterval::::new::(*r); Test::approx_eq(&ThermodynamicTemperature::::new::(f), &v) } } } } } uom-0.35.0/src/si/time.rs000064400000000000000000000202431046102023000132200ustar 00000000000000//! Time (base unit second, s). use crate::lib::time::Duration; use crate::num::{FromPrimitive, ToPrimitive, Zero}; quantity! { /// Time (base unit second, s). quantity: Time; "time"; /// Dimension of time, T (base unit second, s). dimension: ISQ< Z0, // length Z0, // mass P1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottasecond: prefix!(yotta); "Ys", "yottasecond", "yottaseconds"; @zettasecond: prefix!(zetta); "Zs", "zettasecond", "zettaseconds"; @exasecond: prefix!(exa); "Es", "exasecond", "exaseconds"; @petasecond: prefix!(peta); "Ps", "petasecond", "petaseconds"; @terasecond: prefix!(tera); "Ts", "terasecond", "teraseconds"; @gigasecond: prefix!(giga); "Gs", "gigasecond", "gigaseconds"; @megasecond: prefix!(mega); "Ms", "megasecond", "megaseconds"; @kilosecond: prefix!(kilo); "ks", "kilosecond", "kiloseconds"; @hectosecond: prefix!(hecto); "hs", "hectosecond", "hectoseconds"; @decasecond: prefix!(deca); "das", "decasecond", "decaseconds"; /// The second is the SI unit of time. It is defined by taking the fixed numerical value of /// the caesium frequency ∆*ν*Cs, the unperturbed ground-state hyperfine /// transition frequency of the caesium 133 atom, to be 9 192 631 770 when expressed in the /// unit Hz, which is equal to s⁻¹. @second: prefix!(none); "s", "second", "seconds"; @decisecond: prefix!(deci); "ds", "decisecond", "deciseconds"; @centisecond: prefix!(centi); "cs", "centisecond", "centiseconds"; @millisecond: prefix!(milli); "ms", "millisecond", "milliseconds"; @microsecond: prefix!(micro); "µs", "microsecond", "microseconds"; @nanosecond: prefix!(nano); "ns", "nanosecond", "nanoseconds"; @picosecond: prefix!(pico); "ps", "picosecond", "picoseconds"; @femtosecond: prefix!(femto); "fs", "femtosecond", "femtoseconds"; @attosecond: prefix!(atto); "as", "attosecond", "attoseconds"; @zeptosecond: prefix!(zepto); "zs", "zeptosecond", "zeptoseconds"; @yoctosecond: prefix!(yocto); "ys", "yoctosecond", "yoctoseconds"; @second_sidereal: 9.972_696_E-1; "s (sidereal)", "second (sidereal)", "seconds (sidereal)"; @day: 8.64_E4; "d", "day", "days"; @day_sidereal: 8.616_409_E4; "d (sidereal)", "day (sidereal)", "days (sidereal)"; @hour: 3.6_E3; "h", "hour", "hours"; @hour_sidereal: 3.590_170_E3; "h (sidereal)", "hour (sidereal)", "hours (sidereal)"; @minute: 6.0_E1; "min", "minute", "minutes"; @shake: 1.0_E-8; "10.0 ns", "shake", "shakes"; @year: 3.1536_E7; "a", "year", "years"; @year_sidereal: 3.155_815_E7; "a (sidereal)", "year (sidereal)", "years (sidereal)"; @year_tropical: 3.155_693_E7; "a (tropical)", "year (tropical)", "years (tropical)"; } } /// An error encountered converting between `Time` and `Duration`. #[derive(Debug, Clone, Copy)] pub enum TryFromError { /// The given time interval was negative, making conversion to a duration nonsensical. /// /// To convert a negative time interval to a duration, first use `abs` to make it positive. NegativeDuration, /// The given time interval exceeded the maximum size of a `Duration`. Overflow, } /// Attempt to convert the given `Time` to a `Duration`. /// /// For possible failure modes see [`TryFromError`][TryFromError]. /// /// ## Notes /// /// The `Duration` to `Time` conversion is tested to be accurate to within 1 nanosecond (to allow /// for floating point rounding error). If greater precision is needed, consider using a different /// underlying storage type or avoiding the conversion altogether. /// /// [TryFromError]: enum.TryFromError.html impl crate::lib::convert::TryFrom> for Duration where U: crate::si::Units + ?Sized, V: crate::num::Num + crate::Conversion + PartialOrd + ToPrimitive, second: crate::Conversion, nanosecond: crate::Conversion, { type Error = TryFromError; fn try_from(time: Time) -> Result { if time < Time::::zero() { return Err(TryFromError::NegativeDuration); } let secs = time.get::().to_u64(); let nanos = (time % Time::::new::(V::one())).get::().to_u32(); match (secs, nanos) { (Some(secs), Some(nanos)) => Ok(Duration::new(secs, nanos)), _ => Err(TryFromError::Overflow), } } } /// Attempt to convert the given `Duration` to a `Time`. /// /// For possible failure modes, see [`TryFromError`][TryFromError]. /// /// ## Notes /// /// The `Duration` to `Time` conversion is tested to be accurate to within 100 nanoseconds (to /// allow for floating point rounding error). If greater precision is needed, consider using a /// different underlying storage type or avoiding the conversion altogether. /// /// [TryFromError]: enum.TryFromError.html impl crate::lib::convert::TryFrom for Time where U: crate::si::Units + ?Sized, V: crate::num::Num + crate::Conversion + FromPrimitive, second: crate::Conversion, nanosecond: crate::Conversion, { type Error = TryFromError; fn try_from(duration: Duration) -> Result { let secs = V::from_u64(duration.as_secs()); let nanos = V::from_u32(duration.subsec_nanos()); match (secs, nanos) { (Some(secs), Some(nanos)) => { Ok(Time::::new::(secs) + Time::::new::(nanos)) } _ => Err(TryFromError::Overflow), } } } #[cfg(test)] mod tests { storage_types! { types: PrimInt, BigInt, BigUint, Float; use crate::ConversionFactor; use crate::lib::convert::TryFrom; use crate::lib::time::Duration; use crate::num::{FromPrimitive, ToPrimitive, One, Zero}; use crate::si::quantities::*; use crate::si::time::{TryFromError, second, nanosecond}; use crate::tests::*; use quickcheck::TestResult; quickcheck! { fn duration_try_from(v: A) -> bool { let ns: V = >::coefficient().value(); let t = Time::new::((*v).clone()); let d = Duration::try_from(t); let r = (*v).clone() % V::one(); let s = ((*v).clone() - r.clone()).to_u64(); let n = (r * (V::one() / &ns)).to_u32(); match (d, s, n) { (Ok(d), Some(s), Some(n)) => d.as_secs() == s && d.subsec_nanos() == n, (Err(TryFromError::NegativeDuration), _, _) if *v < V::zero() => true, (Err(TryFromError::Overflow), None, _) => true, (Err(TryFromError::Overflow), _, None) => true, _ => false, } } fn time_try_from(v: A) -> TestResult { if *v < V::zero() { return TestResult::discard(); } let ns: V = >::coefficient().value(); let r = (*v).clone() % V::one(); let s = ((*v).clone() - r.clone()).to_u64(); let n = (r * (V::one() / &ns)).to_u32(); return match (s, n) { (Some(s), Some(n)) => TestResult::from_bool( match (Time::try_from(Duration::new(s, n)), V::from_u64(s), V::from_u32(n)) { (Ok(t), Some(s), Some(n)) => t == Time::new::(s) + Time::new::(n), (Err(TryFromError::Overflow), None, _) => true, (Err(TryFromError::Overflow), _, None) => true, _ => false, }), _ => TestResult::discard(), } } } } } uom-0.35.0/src/si/torque.rs000064400000000000000000000223441046102023000136050ustar 00000000000000//! Torque (aka moment of force) (base unit newton meter, kg · m² · s⁻²). quantity! { /// Torque (aka moment of force) (base unit newton meter, kg · m² · s⁻²). /// /// Torque is a moment, the product of distance and force. Moments are inherently dependent on /// the distance from a fixed reference point. This library does not capture this dependency. /// As a consequence, there are *no compile time guarantees that only moments of the same frame /// can be combined*. quantity: Torque; "torque"; /// Dimension of torque, L²MT⁻² (base unit newton meter, kg · m² · s⁻²). dimension: ISQ< P2, // length P1, // mass N2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::AngleKind); units { @yottanewton_meter: prefix!(yotta); "YN · m", "yottanewton meter", "yottanewton meters"; @zettanewton_meter: prefix!(zetta); "ZN · m", "zettanewton meter", "zettanewton meters"; @exanewton_meter: prefix!(exa); "EN · m", "exanewton meter", "exanewton meters"; @petanewton_meter: prefix!(peta); "PN · m", "petanewton meter", "petanewton meters"; @teranewton_meter: prefix!(tera); "TN · m", "teranewton meter", "teranewton meters"; @giganewton_meter: prefix!(giga); "GN · m", "giganewton meter", "giganewton meters"; @meganewton_meter: prefix!(mega); "MN · m", "meganewton meter", "meganewton meters"; @kilonewton_meter: prefix!(kilo); "kN · m", "kilonewton meter", "kilonewton meters"; @hectonewton_meter: prefix!(hecto); "hN · m", "hectonewton meter", "hectonewton meters"; @decanewton_meter: prefix!(deca); "daN · m", "decanewton meter", "decanewton meters"; /// Derived unit of torque. @newton_meter: prefix!(none); "N · m", "newton meter", "newton meters"; @decinewton_meter: prefix!(deci); "dN · m", "decinewton meter", "decinewton meters"; @centinewton_meter: prefix!(centi); "cN · m", "centinewton meter", "centinewton meters"; @millinewton_meter: prefix!(milli); "mN · m", "millinewton meter", "millinewton meters"; @micronewton_meter: prefix!(micro); "µN · m", "micronewton meter", "micronewton meters"; @nanonewton_meter: prefix!(nano); "nN · m", "nanonewton meter", "nanonewton meters"; @piconewton_meter: prefix!(pico); "pN · m", "piconewton meter", "piconewton meters"; @femtonewton_meter: prefix!(femto); "fN · m", "femtonewton meter", "femtonewton meters"; @attonewton_meter: prefix!(atto); "aN · m", "attonewton meter", "attonewton meters"; @zeptonewton_meter: prefix!(zepto); "zN · m", "zeptonewton meter", "zeptonewton meters"; @yoctonewton_meter: prefix!(yocto); "yN · m", "yoctonewton meter", "yoctonewton meters"; @newton_yottameter: prefix!(yotta); "N · Ym", "newton yottameter", "newton yottameters"; @newton_zettameter: prefix!(zetta); "N · Zm", "newton zettameter", "newton zettameters"; @newton_exameter: prefix!(exa); "N · Em", "newton exameter", "newton exameters"; @newton_petameter: prefix!(peta); "N · Pm", "newton petameter", "newton petameters"; @newton_terameter: prefix!(tera); "N · Tm", "newton terameter", "newton terameters"; @newton_gigameter: prefix!(giga); "N · Gm", "newton gigameter", "newton gigameters"; @newton_megameter: prefix!(mega); "N · Mm", "newton megameter", "newton megameters"; @newton_kilometer: prefix!(kilo); "N · km", "newton kilometer", "newton kilometers"; @newton_hectometer: prefix!(hecto); "N · hm", "newton hectometer", "newton hectometers"; @newton_decameter: prefix!(deca); "N · dam", "newton decameter", "newton decameters"; @newton_decimeter: prefix!(deci); "N · dm", "newton decimeter", "newton decimeters"; @newton_centimeter: prefix!(centi); "N · cm", "newton centimeter", "newton centimeters"; @newton_millimeter: prefix!(milli); "N · mm", "newton millimeter", "newton millimeters"; @newton_micrometer: prefix!(micro); "N · µm", "newton micrometer", "newton micrometers"; @newton_nanometer: prefix!(nano); "N · nm", "newton nanometer", "newton nanometers"; @newton_picometer: prefix!(pico); "N · pm", "newton picometer", "newton picometers"; @newton_femtometer: prefix!(femto); "N · fm", "newton femtometer", "newton femtometers"; @newton_attometer: prefix!(atto); "N · am", "newton attometer", "newton attometers"; @newton_zeptometer: prefix!(zepto); "N · zm", "newton zeptometer", "newton zeptometers"; @newton_yoctometer: prefix!(yocto); "N · ym", "newton yoctometer", "newton yoctometers"; @dyne_meter: 1.0_E-5; "dyn · m", "dyne meter", "dyne meters"; @dyne_centimeter: 1.0_E-7; "dyn · cm", "dyne centimeter", "dyne centimeters"; @kilogram_force_meter: 9.806_65_E0; "kgf · m", "kilogram-force meter", "kilogram-force meters"; @ounce_force_inch: 7.061_553_06_E-3; "ozf · in", "ounce-force inch", "ounces-force inches"; @pound_force_foot: 1.355_818_065_6_E0; "lbf · ft", "pound-force foot", "pounds-force feet"; @pound_force_inch: 1.129_848_388_E-1; "lbf · in", "pound-force inch", "pounds-force inches"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::force as f; use crate::si::length as l; use crate::si::quantities::*; use crate::si::torque as t; use crate::tests::Test; #[test] fn check_dimension() { let _: Torque = (Force::new::(V::one()) * Length::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, L: l::Conversion, T: t::Conversion>() { Test::assert_approx_eq(&Torque::new::(V::one()), &(Force::new::(V::one()) * Length::new::(V::one())).into()); } } } } uom-0.35.0/src/si/velocity.rs000064400000000000000000000162461046102023000141300ustar 00000000000000//! Velocity (base unit meter per second, m · s⁻¹). quantity! { /// Velocity (base unit meter per second, m · s⁻¹). quantity: Velocity; "velocity"; /// Dimension of velocity, LT⁻¹ (base unit meter per second, m · s⁻¹). dimension: ISQ< P1, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @yottameter_per_second: prefix!(yotta); "Ym/s", "yottameter per second", "yottameters per second"; @zettameter_per_second: prefix!(zetta); "Zm/s", "zettameter per second", "zettameters per second"; @exameter_per_second: prefix!(exa); "Em/s", "exameter per second", "exameters per second"; @petameter_per_second: prefix!(peta); "Pm/s", "petameter per second", "petameters per second"; @terameter_per_second: prefix!(tera); "Tm/s", "terameter per second", "terameters per second"; @gigameter_per_second: prefix!(giga); "Gm/s", "gigameter per second", "gigameters per second"; @megameter_per_second: prefix!(mega); "Mm/s", "megameter per second", "megameters per second"; @kilometer_per_second: prefix!(kilo); "km/s", "kilometer per second", "kilometers per second"; @hectometer_per_second: prefix!(hecto); "hm/s", "hectometer per second", "hectometers per second"; @decameter_per_second: prefix!(deca); "dam/s", "decameter per second", "decameters per second"; @meter_per_second: prefix!(none); "m/s", "meter per second", "meters per second"; @decimeter_per_second: prefix!(deci); "dm/s", "decimeter per second", "decimeters per second"; @centimeter_per_second: prefix!(centi); "cm/s", "centimeter per second", "centimeters per second"; @millimeter_per_second: prefix!(milli); "mm/s", "millimeter per second", "millimeters per second"; @micrometer_per_second: prefix!(micro); "µm/s", "micrometer per second", "micrometers per second"; @nanometer_per_second: prefix!(nano); "nm/s", "nanometer per second", "nanometers per second"; @picometer_per_second: prefix!(pico); "pm/s", "picometer per second", "picometers per second"; @femtometer_per_second: prefix!(femto); "fm/s", "femtometer per second", "femtometers per second"; @attometer_per_second: prefix!(atto); "am/s", "attometer per second", "attometers per second"; @zeptometer_per_second: prefix!(zepto); "zm/s", "zeptometer per second", "zeptometers per second"; @yoctometer_per_second: prefix!(yocto); "ym/s", "yoctometer per second", "yoctometers per second"; @foot_per_hour: 8.466_666_666_666_667_E-5; "ft/h", "foot per hour", "feet per hour"; @foot_per_minute: 5.08_E-3; "ft/min", "foot per minute", "feet per minute"; @foot_per_second: 3.048_E-1; "ft/s", "foot per second", "feet per second"; @inch_per_second: 2.54_E-2; "in/s", "inch per second", "inches per second"; @kilometer_per_hour: 2.777_777_777_777_778_E-1; "km/h", "kilometer per hour", "kilometers per hour"; @knot: 5.144_444_444_444_445_E-1; "kn", "knot", "knots"; @mile_per_hour: 4.470_4_E-1; "mi/h", "mile per hour", "miles per hour"; @mile_per_minute: 2.682_24_E1; "mi/min", "mile per minute", "miles per minute"; @mile_per_second: 1.609_344_E3; "mi/s", "mile per second", "miles per second"; @millimeter_per_minute: 1.666_666_666_666_666_667_E-5; "mm/min", "millimeter per minute", "millimeters per minute"; /// Hartree atomic unit of velocity a₀ · Eₕ/ħ, where a₀ is Bohr radius, Eₕ is Hartree energy, /// and ħ is reduced Planck constant @atomic_unit_of_velocity: 2.187_691_263_64_E6; "a₀ · Eₕ/ħ", "atomic unit of velocity", "atomic units of velocity"; /// Speed of light in vacuum, CODATA 2018 @natural_unit_of_velocity: 299_792_458.0; "c", "natural unit of velocity", "natural units of velocity"; /// Speed of light in vacuum, CODATA 2018 @speed_of_light_in_vacuum: 299_792_458.0; "c", "speed of light in vacuum", "speeds of light in vacuum"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::length as l; use crate::si::quantities::*; use crate::si::time as t; use crate::si::velocity as v; use crate::tests::Test; #[test] fn check_dimension() { let _: Velocity = Length::new::(V::one()) / Time::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, E: v::Conversion>() { Test::assert_eq(&Velocity::new::(V::one()), &(Length::new::(V::one()) / Time::new::(V::one()))); } } } } uom-0.35.0/src/si/volume.rs000064400000000000000000000263701046102023000136000ustar 00000000000000//! Volume (base unit cubic meter, m³). quantity! { /// Volume (base unit cubic meter, m³). quantity: Volume; "volume"; /// Dimension of volume, L³ (base unit cubic meter, m³). dimension: ISQ< P3, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @cubic_yottameter: prefix!(yotta) * prefix!(yotta) * prefix!(yotta); "Ym³", "cubic yottameter", "cubic yottameters"; @cubic_zettameter: prefix!(zetta) * prefix!(zetta) * prefix!(zetta); "Zm³", "cubic zettameter", "cubic zettameters"; @cubic_exameter: prefix!(exa) * prefix!(exa) * prefix!(exa); "Em³", "cubic exameter", "cubic exameters"; @cubic_petameter: prefix!(peta) * prefix!(peta) * prefix!(peta); "Pm³", "cubic petameter", "cubic petameters"; @cubic_terameter: prefix!(tera) * prefix!(tera) * prefix!(tera); "Tm³", "cubic terameter", "cubic terameters"; @cubic_gigameter: prefix!(giga) * prefix!(giga) * prefix!(giga); "Gm³", "cubic gigameter", "cubic gigameters"; @cubic_megameter: prefix!(mega) * prefix!(mega) * prefix!(mega); "Mm³", "cubic megameter", "cubic megameters"; @cubic_kilometer: prefix!(kilo) * prefix!(kilo) * prefix!(kilo); "km³", "cubic kilometer", "cubic kilometers"; @cubic_hectometer: prefix!(hecto) * prefix!(hecto) * prefix!(hecto); "hm³", "cubic hectometer", "cubic hectometers"; @cubic_decameter: prefix!(deca) * prefix!(deca) * prefix!(deca); "dam³", "cubic decameter", "cubic decameters"; @cubic_meter: prefix!(none); "m³", "cubic meter", "cubic meters"; @cubic_decimeter: prefix!(deci) * prefix!(deci) * prefix!(deci); "dm³", "cubic decimeter", "cubic decimeters"; @cubic_centimeter: prefix!(centi) * prefix!(centi) * prefix!(centi); "cm³", "cubic centimeter", "cubic centimeters"; @cubic_millimeter: prefix!(milli) * prefix!(milli) * prefix!(milli); "mm³", "cubic millimeter", "cubic millimeters"; @cubic_micrometer: prefix!(micro) * prefix!(micro) * prefix!(micro); "µm³", "cubic micrometer", "cubic micrometers"; @cubic_nanometer: prefix!(nano) * prefix!(nano) * prefix!(nano); "nm³", "cubic nanometer", "cubic nanometers"; @cubic_picometer: prefix!(pico) * prefix!(pico) * prefix!(pico); "pm³", "cubic picometer", "cubic picometers"; @cubic_femtometer: prefix!(femto) * prefix!(femto) * prefix!(femto); "fm³", "cubic femtometer", "cubic femtometers"; @cubic_attometer: prefix!(atto) * prefix!(atto) * prefix!(atto); "am³", "cubic attometer", "cubic attometers"; @cubic_zeptometer: prefix!(zepto) * prefix!(zepto) * prefix!(zepto); "zm³", "cubic zeptometer", "cubic zeptometers"; @cubic_yoctometer: prefix!(yocto) * prefix!(yocto) * prefix!(yocto); "ym³", "cubic yoctometer", "cubic yoctometers"; @acre_foot: 1.233_489_E3; "ac · ft", "acre-foot", "acre-feet"; @barrel: 1.589_873_E-1; "bbl", "barrel", "barrels"; @bushel: 3.523_907_E-2; "bu", "bushel", "bushels"; @cord: 3.624_556_E0; "cords", "cord", "cords"; @cubic_foot: 2.831_685_E-2; "ft³", "cubic foot", "cubic feet"; @cubic_inch: 1.638_706_E-5; "in³", "cubic inch", "cubic inches"; @cubic_mile: 4.168_182_E9; "mi³", "cubic mile", "cubic miles"; @cubic_yard: 7.645_549_E-1; "yd³", "cubic yard", "cubic yards"; @cup: 2.365_882_E-4; "cup", "cup", "cups"; @fluid_ounce: 2.957_353_E-5; "fl oz", "fluid ounce", "fluid ounces"; @fluid_ounce_imperial: 2.841_306_E-5; "fl oz (UK)", "Imperial fluid ounce", "Imperial fluid ounces"; @gallon_imperial: 4.546_09_E-3; "gal (UK)", "Imperial gallon", "Imperial gallons"; @gallon: 3.785_412_E-3; "gal", "gallon", "gallons"; @gill_imperial: 1.420_653_E-4; "gi (UK)", "Imperial gill", "Imperial gills"; @gill: 1.182_941_E-4; "gi", "gill", "gills"; @yottaliter: prefix!(milli) * prefix!(yotta); "YL", "yottaliter", "yottaliters"; @zettaliter: prefix!(milli) * prefix!(zetta); "ZL", "zettaliter", "zettaliters"; @exaliter: prefix!(milli) * prefix!(exa); "EL", "exaliter", "exaliters"; @petaliter: prefix!(milli) * prefix!(peta); "PL", "petaliter", "petaliters"; @teraliter: prefix!(milli) * prefix!(tera); "TL", "teraliter", "teraliters"; @gigaliter: prefix!(milli) * prefix!(giga); "GL", "gigaliter", "gigaliters"; @megaliter: prefix!(milli) * prefix!(mega); "ML", "megaliter", "megaliters"; @kiloliter: prefix!(milli) * prefix!(kilo); "kL", "kiloliter", "kiloliters"; @hectoliter: prefix!(milli) * prefix!(hecto); "hL", "hectoliter", "hectoliters"; @decaliter: prefix!(milli) * prefix!(deca); "daL", "decaliter", "decaliters"; @liter: prefix!(milli); "L", "liter", "liters"; @deciliter: prefix!(milli) * prefix!(deci); "dL", "deciliter", "deciliters"; @centiliter: prefix!(milli) * prefix!(centi); "cL", "centiliter", "centiliters"; @milliliter: prefix!(milli) * prefix!(milli); "mL", "milliliter", "milliliters"; @microliter: prefix!(milli) * prefix!(micro); "µL", "microliter", "microliters"; @nanoliter: prefix!(milli) * prefix!(nano); "nL", "nanoliter", "nanoliters"; @picoliter: prefix!(milli) * prefix!(pico); "pL", "picoliter", "picoliters"; @femtoliter: prefix!(milli) * prefix!(femto); "fL", "femtoliter", "femtoliters"; @attoliter: prefix!(milli) * prefix!(atto); "aL", "attoliter", "attoliters"; @zeptoliter: prefix!(milli) * prefix!(zepto); "zL", "zeptoliter", "zeptoliters"; @yoctoliter: prefix!(milli) * prefix!(yocto); "yL", "yoctoliter", "yoctoliters"; @peck: 8.809_768_E-3; "pk", "peck", "pecks"; @pint_dry: 5.506_105_E-4; "dry pt", "dry pint", "dry pints"; @pint_liquid: 4.731_765_E-4; "liq pt", "liquid pint", "liquid pints"; @quart_dry: 1.101_221_E-3; "dry qt", "dry quart", "dry quarts"; @quart_liquid: 9.463_529_E-4; "liq qt", "liquid quart", "liquid quarts"; @stere: 1.0_E0; "st", "stere", "steres"; @tablespoon: 1.478_676_E-5; "tbsp", "tablespoon", "tablespoons"; @teaspoon: 4.928_922_E-6; "tsp", "teaspoon", "teaspoons"; @register_ton: 2.831_685_E0; "RT", "register ton", "register tons"; } } #[cfg(test)] mod tests { storage_types! { use crate::lib::any::TypeId; use crate::num::{FromPrimitive, One}; use crate::si::area as a; use crate::si::length as l; use crate::si::quantities::*; use crate::si::volume as v; use crate::tests::Test; #[test] fn check_dimension() { let _: Volume = Length::new::(V::one()) * Length::new::(V::one()) * Length::new::(V::one()); let _: Volume = Length::new::(V::one()) * Area::new::(V::one()); } #[test] fn check_liters() { // Test liter base relative to cubic meter base to verify a baseline test::(V::from_f64(prefix!(milli)).unwrap()); // Test relative to liter to make sure prefixes are good // This transitively verifies the other relations test::(V::from_f64(prefix!(yotta)).unwrap()); test::(V::from_f64(prefix!(zetta)).unwrap()); test::(V::from_f64(prefix!(exa)).unwrap()); test::(V::from_f64(prefix!(peta)).unwrap()); test::(V::from_f64(prefix!(tera)).unwrap()); test::(V::from_f64(prefix!(giga)).unwrap()); test::(V::from_f64(prefix!(mega)).unwrap()); test::(V::from_f64(prefix!(kilo)).unwrap()); test::(V::from_f64(prefix!(hecto)).unwrap()); test::(V::from_f64(prefix!(deca)).unwrap()); test::(V::one()); test::(V::from_f64(prefix!(deci)).unwrap()); test::(V::from_f64(prefix!(centi)).unwrap()); test::(V::from_f64(prefix!(milli)).unwrap()); test::(V::from_f64(prefix!(micro)).unwrap()); test::(V::from_f64(prefix!(nano)).unwrap()); test::(V::from_f64(prefix!(pico)).unwrap()); test::(V::from_f64(prefix!(femto)).unwrap()); test::(V::from_f64(prefix!(atto)).unwrap()); test::(V::from_f64(prefix!(zepto)).unwrap()); test::(V::from_f64(prefix!(yocto)).unwrap()); fn test, U: v::Conversion>(ratio: V) { Test::assert_eq(&Volume::new::(V::one()), &Volume::new::(ratio)) } } #[test] // #392: Disable tests on ARM until issues with floating point behavior can be resolved. #[cfg(not(target_arch = "arm"))] fn check_units() { // Values too large for f32. if TypeId::of::() == TypeId::of::() { test::(); test::(); test::(); test::(); } test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); // Values too small for f32. if TypeId::of::() == TypeId::of::() { test::(); test::(); test::(); } fn test, O: v::Conversion>() { Test::assert_eq(&Volume::new::(V::one()), &(Length::new::(V::one()) * Length::new::(V::one()) * Length::new::(V::one()))); } } } } uom-0.35.0/src/si/volume_rate.rs000064400000000000000000000413661046102023000146150ustar 00000000000000//! Volume rate (base unit cubic meter per second, m³ · s⁻¹). quantity! { /// Volume rate (base unit cubic meter per second, m³ · s⁻¹). quantity: VolumeRate; "volume rate"; /// Dimension of volume rate, L³T⁻¹ (base unit cubic meter per second, m³ · s⁻¹). dimension: ISQ< P3, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @cubic_yottameter_per_second: prefix!(yotta) * prefix!(yotta) * prefix!(yotta); "Ym³/s", "cubic yottameter per second", "cubic yottameters per second"; @cubic_zettameter_per_second: prefix!(zetta) * prefix!(zetta) * prefix!(zetta); "Zm³/s", "cubic zettameter per second", "cubic zettameters per second"; @cubic_exameter_per_second: prefix!(exa) * prefix!(exa) * prefix!(exa); "Em³/s", "cubic exameter per second", "cubic exameters per second"; @cubic_petameter_per_second: prefix!(peta) * prefix!(peta) * prefix!(peta); "Pm³/s", "cubic petameter per second", "cubic petameters per second"; @cubic_terameter_per_second: prefix!(tera) * prefix!(tera) * prefix!(tera); "Tm³/s", "cubic terameter per second", "cubic terameters per second"; @cubic_gigameter_per_second: prefix!(giga) * prefix!(giga) * prefix!(giga); "Gm³/s", "cubic gigameter per second", "cubic gigameters per second"; @cubic_megameter_per_second: prefix!(mega) * prefix!(mega) * prefix!(mega); "Mm³/s", "cubic megameter per second", "cubic megameters per second"; @cubic_kilometer_per_second: prefix!(kilo) * prefix!(kilo) * prefix!(kilo); "km³/s", "cubic kilometer per second", "cubic kilometers per second"; @cubic_hectometer_per_second: prefix!(hecto) * prefix!(hecto) * prefix!(hecto); "hm³/s", "cubic hectometer per second", "cubic hectometers per second"; @cubic_decameter_per_second: prefix!(deca) * prefix!(deca) * prefix!(deca); "dam³/s", "cubic decameter per second", "cubic decameters per second"; @cubic_meter_per_second: prefix!(none); "m³/s", "cubic meter per second", "cubic meters per second"; @cubic_meter_per_minute: 1.0_E0 / 6.0_E1; "m³/min", "cubic meter per minute", "cubic meters per minute"; @cubic_meter_per_hour: 1.0_E0 / 3.6_E3; "m³/h", "cubic meter per hour", "cubic meters per hour"; @cubic_decimeter_per_second: prefix!(deci) * prefix!(deci) * prefix!(deci); "dm³/s", "cubic decimeter per second", "cubic decimeters per second"; @cubic_centimeter_per_second: prefix!(centi) * prefix!(centi) * prefix!(centi); "cm³/s", "cubic centimeter per second", "cubic centimeters per second"; @cubic_millimeter_per_second: prefix!(milli) * prefix!(milli) * prefix!(milli); "mm³/s", "cubic millimeter per second", "cubic millimeters per second"; @cubic_micrometer_per_second: prefix!(micro) * prefix!(micro) * prefix!(micro); "µm³/s", "cubic micrometer per second", "cubic micrometers per second"; @cubic_nanometer_per_second: prefix!(nano) * prefix!(nano) * prefix!(nano); "nm³/s", "cubic nanometer per second", "cubic nanometers per second"; @cubic_picometer_per_second: prefix!(pico) * prefix!(pico) * prefix!(pico); "pm³/s", "cubic picometer per second", "cubic picometers per second"; @cubic_femtometer_per_second: prefix!(femto) * prefix!(femto) * prefix!(femto); "fm³/s", "cubic femtometer per second", "cubic femtometers per second"; @cubic_attometer_per_second: prefix!(atto) * prefix!(atto) * prefix!(atto); "am³/s", "cubic attometer per second", "cubic attometers per second"; @cubic_zeptometer_per_second: prefix!(zepto) * prefix!(zepto) * prefix!(zepto); "zm³/s", "cubic zeptometer per second", "cubic zeptometers per second"; @cubic_yoctometer_per_second: prefix!(yocto) * prefix!(yocto) * prefix!(yocto); "ym³/s", "cubic yoctometer per second", "cubic yoctometers per second"; @yottaliter_per_second: prefix!(milli) * prefix!(yotta); "YL/s", "yottaliter per second", "yottaliters per second"; @zettaliter_per_second: prefix!(milli) * prefix!(zetta); "ZL/s", "zettaliter per second", "zettaliters per second"; @exaliter_per_second: prefix!(milli) * prefix!(exa); "EL/s", "exaliter per second", "exaliters per second"; @petaliter_per_second: prefix!(milli) * prefix!(peta); "PL/s", "petaliter per second", "petaliters per second"; @teraliter_per_second: prefix!(milli) * prefix!(tera); "TL/s", "teraliter per second", "teraliters per second"; @gigaliter_per_second: prefix!(milli) * prefix!(giga); "GL/s", "gigaliter per second", "gigaliters per second"; @megaliter_per_second: prefix!(milli) * prefix!(mega); "ML/s", "megaliter per second", "megaliters per second"; @kiloliter_per_second: prefix!(milli) * prefix!(kilo); "kL/s", "kiloliter per second", "kiloliters per second"; @hectoliter_per_second: prefix!(milli) * prefix!(hecto); "hL/s", "hectoliter per second", "hectoliters per second"; @decaliter_per_second: prefix!(milli) * prefix!(deca); "daL/s", "decaliter per second", "decaliters per second"; @liter_per_second: prefix!(milli); "L/s", "liter per second", "liters per second"; @deciliter_per_second: prefix!(milli) * prefix!(deci); "dL/s", "deciliter per second", "deciliters per second"; @centiliter_per_second: prefix!(milli) * prefix!(centi); "cL/s", "centiliter per second", "centiliters per second"; @milliliter_per_second: prefix!(milli) * prefix!(milli); "mL/s", "milliliter per second", "milliliters per second"; @microliter_per_second: prefix!(milli) * prefix!(micro); "µL/s", "microliter per second", "microliters per second"; @nanoliter_per_second: prefix!(milli) * prefix!(nano); "nL/s", "nanoliter per second", "nanoliters per second"; @picoliter_per_second: prefix!(milli) * prefix!(pico); "pL/s", "picoliter per second", "picoliters per second"; @femtoliter_per_second: prefix!(milli) * prefix!(femto); "fL/s", "femtoliter per second", "femtoliters per second"; @attoliter_per_second: prefix!(milli) * prefix!(atto); "aL/s", "attoliter per second", "attoliters per second"; @zeptoliter_per_second: prefix!(milli) * prefix!(zepto); "zL/s", "zeptoliter per second", "zeptoliters per second"; @yoctoliter_per_second: prefix!(milli) * prefix!(yocto); "yL/s", "yoctoliter per second", "yoctoliters per second"; @liter_per_minute: prefix!(milli) / 6.0_E1; "L/min", "liter per minute", "liters per minute"; @acre_foot_per_second: 1.233_489_E3; "ac · ft/s", "acre-foot per second", "acre-feet per second"; @barrel_per_second: 1.589_873_E-1; "bbl/s", "barrel per second", "barrels per second"; @bushel_per_second: 3.523_907_E-2; "bu/s", "bushel per second", "bushels per second"; @cord_per_second: 3.624_556_E0; "cords/s", "cord per second", "cords per second"; @cubic_foot_per_second: 2.831_685_E-2; "ft³/s", "cubic foot per second", "cubic feet per second"; @cubic_foot_per_minute: 2.831_685_E-2 / 6.0_E1; "ft³/min", "cubic foot per minute", "cubic feet per minute"; @cubic_inch_per_second: 1.638_706_E-5; "in³/s", "cubic inch per second", "cubic inches per second"; @cubic_inch_per_minute: 1.638_706_E-5 / 6.0_E1; "in³/min", "cubic inch per minute", "cubic inches per minute"; @cubic_mile_per_second: 4.168_182_E9; "mi³/s", "cubic mile per second", "cubic miles per second"; @cubic_yard_per_second: 7.645_549_E-1; "yd³/s", "cubic yard per second", "cubic yards per second"; @cubic_yard_per_minute: 7.645_549_E-1 / 6.0_E1; "yd³/min", "cubic yard per minute", "cubic yards per minute"; @cup_per_second: 2.365_882_E-4; "cup/s", "cup per second", "cups per second"; @fluid_ounce_per_second: 2.957_353_E-5; "fl oz/s", "fluid ounce per second", "fluid ounces per second"; @fluid_ounce_imperial_per_second: 2.841_306_E-5; "fl oz (UK)/s", "Imperial fluid ounce per second", "Imperial fluid ounces per second"; @gallon_imperial_per_second: 4.546_09_E-3; "gal (UK)/s", "Imperial gallon per second", "Imperial gallons per second"; @gallon_per_second: 3.785_412_E-3; "gal/s", "gallon per second", "gallons per second"; @gallon_per_minute: 3.785_412_E-3 / 6.0_E1; "gal/min", "gallon per minute", "gallons per minute"; @gallon_per_day: 3.785_412_E-3 / 8.64_E4; "gal/d", "gallon per day", "gallons per day"; @gill_imperial_per_second: 1.420_653_E-4; "gi (UK)/s", "Imperial gill per second", "Imperial gills per second"; @gill_per_second: 1.182_941_E-4; "gi/s", "gill per second", "gills per second"; @peck_per_second: 8.809_768_E-3; "pk/s", "peck per second", "pecks per second"; @pint_dry_per_second: 5.506_105_E-4; "dry pt/s", "dry pint per second", "dry pints per second"; @pint_liquid_per_second: 4.731_765_E-4; "liq pt/s", "liquid pint per second", "liquid pints per second"; @quart_dry_per_second: 1.101_221_E-3; "dry qt/s", "dry quart per second", "dry quarts per second"; @quart_liquid_per_second: 9.463_529_E-4; "liq qt/s", "liquid quart per second", "liquid quarts per second"; @stere_per_second: 1.0_E0; "st/s", "stere per second", "steres per second"; @tablespoon_per_second: 1.478_676_E-5; "tbsp/s", "tablespoon per second", "tablespoons per second"; @teaspoon_per_second: 4.928_922_E-6; "tsp/s", "teaspoon per second", "teaspoons per second"; @register_ton_per_second: 2.831_685_E0; "RT/s", "register ton per second", "register tons per second"; } } #[cfg(test)] mod tests { storage_types! { use crate::lib::any::TypeId; use crate::num::One; use crate::si::quantities::*; use crate::si::time as t; use crate::si::volume as v; use crate::si::volume_rate as r; use crate::tests::Test; #[test] fn check_dimension() { let _: VolumeRate = Volume::new::(V::one()) / Time::new::(V::one()); } #[test] fn check_units() { // Values too large for f32. if TypeId::of::() == TypeId::of::() { test::(); test::(); test::(); test::(); } test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); // Values too small for f32. if TypeId::of::() == TypeId::of::() { test::(); test::(); test::(); } test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, T: t::Conversion, R: r::Conversion>() { Test::assert_eq(&VolumeRate::new::(V::one()), &(Volume::new::(V::one()) / Time::new::(V::one()))); } } } } uom-0.35.0/src/si/volumetric_density_of_states.rs000064400000000000000000000050751046102023000202670ustar 00000000000000//! Volumetric density of states (base unit 1 / cubic meter joule, kg⁻¹ · m⁻⁵ · s²). quantity! { /// Volumetric density of states (base unit 1 / cubic meter joule, kg⁻¹ · m⁻⁵ · s²). quantity: VolumetricDensityOfStates; "volumetric density of states"; /// Dimension of volumetric density of states, L⁻⁵M⁻¹T² (base unit 1 / cubic meter joule, /// kg⁻¹ · m⁻⁵ · s²). dimension: ISQ< N5, // length N1, // mass P2, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @state_per_cubic_meter_joule: prefix!(none); "1/(m³ · J)", "state per cubic meter joule", "states per cubic meter joule"; @state_per_cubic_centimeter_joule: prefix!(none) / prefix!(centi) / prefix!(centi) / prefix!(centi); "1/(cm³ · J)", "state per cubic centimeter joule", "states per cubic centimeter joule"; @state_per_cubic_centimeter_electronvolt: prefix!(none) / prefix!(centi) / prefix!(centi) / prefix!(centi) / 1.602_176_634_E-19; "1/(cm³ · eV)", "state per cubic centimeter electronvolt", "states per cubic centimeter electronvolt"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::volumetric_density_of_states as vdos; use crate::si::energy as e; use crate::si::quantities::*; use crate::si::volume as v; use crate::tests::Test; #[test] fn check_dimension() { let _: VolumetricDensityOfStates = (V::one() / Energy::new::(V::one()) / Volume::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); fn test, E: e::Conversion, VDOS: vdos::Conversion>() { Test::assert_approx_eq(&VolumetricDensityOfStates::new::(V::one()), &(V::one() / Energy::new::(V::one()) / Volume::new::(V::one())).into()); } } } } uom-0.35.0/src/si/volumetric_heat_capacity.rs000064400000000000000000000041031046102023000173260ustar 00000000000000//! Volumetric heat capacity (base unit joule per cubic meter kelvin, m⁻¹ · kg · s⁻² · K⁻¹). quantity! { /// Volumetric heat capacity (base unit joule per cubic meter kelvin, m⁻¹ · kg · s⁻² · K⁻¹). quantity: VolumetricHeatCapacity; "volumetric heat capacity"; /// Dimension of volumetric heat capacity, L⁻¹MT⁻²Th⁻¹(base unit joule per cubic meter kelvin, /// m⁻¹ · kg · s⁻² · K⁻¹). dimension: ISQ< N1, // length P1, // mass N2, // time Z0, // electric current N1, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @joule_per_cubic_meter_kelvin: prefix!(none); "J/(m³ · K)", "joule per cubic meter kelvin", "joules per cubic meter kelvin"; @calorie_per_cubic_meter_kelvin: 4.184_E0; "cal/(m³ · K)", "calorie per cubic meter kelvin", "calories per cubic meter kelvin"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::heat_capacity as hc; use crate::si::volume as vol; use crate::si::quantities::*; use crate::si::volumetric_heat_capacity as vhc; use crate::tests::Test; #[test] fn check_dimension() { let _: VolumetricHeatCapacity = HeatCapacity::new::(V::one()) / Volume::new::(V::one()); } #[test] fn check_heat_capacity_volume_units() { test::(); test::(); fn test, VOL: vol::Conversion, VHC: vhc::Conversion>() { Test::assert_approx_eq(&VolumetricHeatCapacity::new::(V::one()), &(HeatCapacity::new::(V::one()) / (Volume::new::(V::one()))) ); } } } } uom-0.35.0/src/si/volumetric_number_density.rs000064400000000000000000000106531046102023000175660ustar 00000000000000//! Volumetric number density (base unit 1 per cubic meter, m⁻³). quantity! { /// Volumetric number density (base unit 1 per cubic meter, m⁻³). quantity: VolumetricNumberDensity; "volumetric number density"; /// Dimension of volumetric number density, L⁻³ (base unit 1 per cubic meter, m⁻³). dimension: ISQ< N3, // length Z0, // mass Z0, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @per_cubic_kilometer: prefix!(none) / prefix!(kilo) / prefix!(kilo) / prefix!(kilo); "km⁻³", "per cubic kilometer", "per cubic kilometer"; @per_cubic_meter: prefix!(none); "m⁻³", "per cubic meter", "per cubic meter"; @per_cubic_decimeter: prefix!(none) / prefix!(deci) / prefix!(deci) / prefix!(deci); "dm⁻³", "per cubic decimeter", "per cubic decimeter"; @per_cubic_centimeter: prefix!(none) / prefix!(centi) / prefix!(centi) / prefix!(centi); "cm⁻³", "per cubic centimeter", "per cubic centimeter"; @per_cubic_millimeter: prefix!(none) / prefix!(milli) / prefix!(milli) / prefix!(milli); "mm⁻³", "per cubic millimeter", "per cubic millimeter"; @per_cubic_foot: prefix!(none) / 2.831_685_E-2; "ft⁻³", "per cubic foot", "per cubic foot"; @per_cubic_inch: prefix!(none) / 1.638_706_E-5; "in⁻³", "per cubic inch", "per cubic inch"; @per_cubic_mile: prefix!(none) / 4.168_182_E9; "mi⁻³", "per cubic mile", "per cubic mile"; @per_cubic_yard: prefix!(none) / 7.645_549_E-1; "yd⁻³", "per cubic yard", "per cubic yard"; @per_fluid_ounce: prefix!(none) / 2.957_353_E-5; "per fl oz", "per fluid ounce", "per fluid ounce"; @per_fluid_ounce_imperial: prefix!(none) / 2.841_306_E-5; "per fl oz (UK)", "per Imperial fluid ounce", "per Imperial fluid ounce"; @per_gallon_imperial: prefix!(none) / 4.546_09_E-3; "per gal (UK)", "per Imperial gallon", "per Imperial gallon"; @per_gallon: prefix!(none) / 3.785_412_E-3; "per gal", "per gallon", "per gallon"; @per_liter: prefix!(none) / prefix!(milli); "L⁻¹", "per liter", "per liter"; @per_deciliter: prefix!(none) / prefix!(milli) / prefix!(deci); "dL⁻¹", "per deciliter", "per deciliter"; @per_centiliter: prefix!(none) / prefix!(milli) / prefix!(centi); "cL⁻¹", "per centiliter", "per centiliter"; @per_milliliter: prefix!(none) / prefix!(milli) / prefix!(milli); "mL⁻¹", "per milliliter", "per milliliter"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::volume as v; use crate::si::volumetric_number_density as n; use crate::si::quantities::*; use crate::tests::Test; #[test] fn check_dimension() { let _: VolumetricNumberDensity = (V::one() / Volume::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, U: v::Conversion>() { Test::assert_approx_eq(&VolumetricNumberDensity::new::(V::one()), &(V::one() / Volume::new::(V::one())).into()); } } } } uom-0.35.0/src/si/volumetric_number_rate.rs000064400000000000000000000133751046102023000170460ustar 00000000000000//! Volumetric number rate (base unit 1 per cubic meter second, m⁻³ · s⁻¹). quantity! { /// Volumetric number rate (base unit 1 per cubic meter second, m⁻³ · s⁻¹). quantity: VolumetricNumberRate; "volumetric number rate"; /// Dimension of volumetric number rate, L⁻³T⁻¹ (base unit 1 per cubic meter second, m⁻³ · s⁻¹). dimension: ISQ< N3, // length Z0, // mass N1, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity kind: dyn (crate::si::marker::ConstituentConcentrationKind); units { @per_cubic_meter_second: prefix!(none); "m⁻³ · s⁻¹", "per cubic meter second", "per cubic meter second"; @per_cubic_centimeter_second: prefix!(none) / prefix!(centi) / prefix!(centi) / prefix!(centi); "cm⁻³ · s⁻¹", "per cubic centimeter second", "per cubic centimeter second"; @per_cubic_millimeter_second: prefix!(none) / prefix!(milli) / prefix!(milli) / prefix!(milli); "mm⁻³ · s⁻¹", "per cubic millimeter second", "per cubic millimeter second"; @per_cubic_foot_second: prefix!(none) / 2.831_685_E-2; "ft⁻³ · s⁻¹", "per cubic foot second", "per cubic foot second"; @per_cubic_inch_second: prefix!(none) / 1.638_706_E-5; "in⁻³ · s⁻¹", "per cubic inch second", "per cubic inch second"; @per_cubic_mile_second: prefix!(none) / 4.168_182_E9; "mi⁻³ · s⁻¹", "per cubic mile second", "per cubic mile second"; @per_cubic_yard_second: prefix!(none) / 7.645_549_E-1; "yd⁻³ · s⁻¹", "per cubic yard second", "per cubic yard second"; @per_fluid_ounce_second: prefix!(none) / 2.957_353_E-5; "fl oz⁻¹ · s⁻¹", "per fluid ounce second", "per fluid ounce second"; @per_fluid_ounce_imperial_second: prefix!(none) / 2.841_306_E-5; "fl oz⁻¹ (UK) · s⁻¹", "per Imperial fluid ounce second", "per Imperial fluid ounce second"; @per_gallon_imperial_second: prefix!(none) / 4.546_09_E-3; "gal⁻¹ (UK) · s⁻¹", "per Imperial gallon second", "per Imperial gallon second"; @per_gallon_second: prefix!(none) / 3.785_412_E-3; "gal⁻¹ · s⁻¹", "per gallon second", "per gallon second"; @per_liter_second: prefix!(none) / prefix!(milli); "L⁻¹ · s⁻¹", "per liter second", "per liter second"; @per_milliliter_second: prefix!(none) / prefix!(milli) / prefix!(milli); "mL⁻¹ · s⁻¹", "per milliliter second", "per milliliter second"; @becquerel_per_cubic_meter: prefix!(none); "Bq/m³", "becquerel per cubic meter", "becquerels per cubic meter"; @curie_per_cubic_meter: 3.7_E10; "Ci/m³", "curie per cubic meter", "curies per cubic meter"; @disintegrations_per_minute_per_cubic_meter: 1.0 / 6.0_E1; "dpm/m³", "disintegration per minute per cubic meter", "disintegrations per minute per cubic meter"; } } #[cfg(test)] mod test { storage_types! { use crate::num::One; use crate::si::volumetric_number_rate as vnr; use crate::si::radioactivity as rad; use crate::si::quantities::*; use crate::si::time as t; use crate::si::volume as vol; use crate::tests::Test; #[test] fn check_dimension() { let _: VolumetricNumberRate = (V::one() / Time::new::(V::one()) / Volume::new::(V::one())).into(); } #[test] fn check_units() { test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); test::(); fn test, VOL: vol::Conversion, T: t::Conversion>() { Test::assert_approx_eq(&VolumetricNumberRate::new::(V::one()), &(V::one() / Time::new::(V::one()) / Volume::new::(V::one())).into()); } } #[test] fn check_units_volumetric_radioactivity() { test::(); test::(); test::(); fn test, VOL: vol::Conversion, VNR: vnr::Conversion>() { Test::assert_approx_eq(&VolumetricNumberRate::new::(V::one()), &(Radioactivity::new::(V::one()) / Volume::new::(V::one())).into()); } } } } uom-0.35.0/src/si/volumetric_power_density.rs000064400000000000000000000042401046102023000174250ustar 00000000000000//! Volumetric power density (base unit watt per cubic meter, m⁻¹ · kg · s⁻³). quantity! { /// Volumetric power density (base unit watt per cubic meter, m⁻¹ · kg · s⁻³). quantity: VolumetricPowerDensity; "volumetric power density"; /// Dimension of volumetric power density, L⁻¹MT⁻³ (base unit watt per cubic meter, /// m⁻¹ · kg · s⁻³). dimension: ISQ< N1, // length P1, // mass N3, // time Z0, // electric current Z0, // thermodynamic temperature Z0, // amount of substance Z0>; // luminous intensity units { @watt_per_cubic_meter: prefix!(none); "W/m³", "watt per cubic meter", "watts per cubic meter"; @watt_per_cubic_centimeter: prefix!(none) / prefix!(centi) / prefix!(centi) / prefix!(centi); "W/cm³", "watt per cubic centimeter", "watts per cubic centimeter"; @watt_per_cubic_millimeter: prefix!(none) / prefix!(milli) / prefix!(milli) / prefix!(milli); "W/mm³", "watt per cubic millimeter", "watts per cubic millimeter"; } } #[cfg(test)] mod tests { storage_types! { use crate::num::One; use crate::si::power as p; use crate::si::quantities::*; use crate::si::volumetric_power_density as vpd; use crate::si::volume as v; use crate::tests::Test; #[test] fn check_dimension() { let _: VolumetricPowerDensity = Power::new::(V::one()) / Volume::new::(V::one()); } #[test] fn check_units() { test::(); test::(); test::(); fn test, U: v::Conversion, VPD: vpd::Conversion>() { Test::assert_approx_eq(&VolumetricPowerDensity::new::(V::one()), &(Power::new::

(V::one()) / Volume::new::(V::one()))); } } } } uom-0.35.0/src/storage_types.rs000064400000000000000000000300641046102023000145410ustar 00000000000000/// Macro to duplicate code on a per-storage type basis. The given code is duplicated in new /// modules named for each storage type. A type alias, `V`, is generated that code can use for the /// type. `@...` match arms are considered private. /// /// * `$attr`: Module attributes. Generally used to set documentation comments for storage type /// modules generated by the macro. /// * `$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`, /// `Complex32`, `Complex64`, `f32`, and `f64`. /// * `PrimInt`: `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, `isize`, `i8`, `i16`, `i32`, `i64`, /// and `i128`. /// * `Ratio`: `Rational`, `Rational32`, `Rational64`, and `BigRational`. /// * `Float`: `f32` and `f64`. /// * `Signed`: `isize`, `i8`, `i16`, `i32`, `i64`, `i128`, `BigInt`, `Rational`, `Rational32`, /// `Rational64`, `BigRational`, `f32`, and `f64`. /// * `Unsigned`: `usize`, `u8`, `u16`, `u32`, `u64`, `u128`, and `BigUint`. /// * `Complex`: `Complex32` and `Complex64`. /// * `$tt`: Code to place into each storage type module. /// #[cfg_attr(all(feature = "f32", feature = "f64"), doc = " ```rust")] #[cfg_attr(not(all(feature = "f32", feature = "f64")), doc = " ```rust,ignore")] /// #[macro_use] /// extern crate uom; /// /// fn main() { /// f32::do_work(1.234_f32); /// f64::do_work(1.234_f64); /// } /// /// storage_types! { /// /// Type modules. /// pub types: Float; /// /// pub fn do_work(_v: V) {} /// } /// ``` #[macro_export] macro_rules! storage_types { ($(#[$attr:meta])* types: $($T:ident),+; $($tt:tt)*) => { storage_types!(@types ($(#[$attr])*) @mod $($T),+; ($($tt)*)); }; ($(#[$attr:meta])* pub types: $($T:ident),+; $($tt:tt)*) => { storage_types!(@types ($(#[$attr])*) @pub_mod $($T),+; ($($tt)*)); }; (@types $attr:tt @$M:ident $($T:ident),+; $tt:tt) => { $(storage_types!(@type $attr @$M $T $tt);)+ }; (@type ($(#[$attr:meta])*) @$M:ident usize ($($tt:tt)*)) => { storage_type_usize!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident u8 ($($tt:tt)*)) => { storage_type_u8!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident u16 ($($tt:tt)*)) => { storage_type_u16!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident u32 ($($tt:tt)*)) => { storage_type_u32!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident u64 ($($tt:tt)*)) => { storage_type_u64!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident u128 ($($tt:tt)*)) => { storage_type_u128!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident isize ($($tt:tt)*)) => { storage_type_isize!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident i8 ($($tt:tt)*)) => { storage_type_i8!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident i16 ($($tt:tt)*)) => { storage_type_i16!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident i32 ($($tt:tt)*)) => { storage_type_i32!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident i64 ($($tt:tt)*)) => { storage_type_i64!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident i128 ($($tt:tt)*)) => { storage_type_i128!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident BigInt ($($tt:tt)*)) => { storage_type_bigint!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident BigUint ($($tt:tt)*)) => { storage_type_biguint!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident Rational ($($tt:tt)*)) => { storage_type_rational!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident Rational32 ($($tt:tt)*)) => { storage_type_rational32!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident Rational64 ($($tt:tt)*)) => { storage_type_rational64!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident BigRational ($($tt:tt)*)) => { storage_type_bigrational!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident Complex32 ($($tt:tt)*)) => { storage_type_complex32!(($(#[$attr])*) @$M ( /// Inner storage type. #[allow(dead_code)] pub type VV = f32; $($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident Complex64 ($($tt:tt)*)) => { storage_type_complex64!(($(#[$attr])*) @$M ( /// Inner storage type. #[allow(dead_code)] pub type VV = f64; $($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident f32 ($($tt:tt)*)) => { storage_type_f32!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident f64 ($($tt:tt)*)) => { storage_type_f64!(($(#[$attr])*) @$M ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident All ($($tt:tt)*)) => { storage_types!(@type ($(#[$attr])*) @$M usize ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u8 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u16 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u64 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u128 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M isize ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i8 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i16 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i64 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i128 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M BigInt ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M BigUint ($($tt)*)); 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 BigRational ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M Complex32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M Complex64 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M f32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M f64 ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident PrimInt ($($tt:tt)*)) => { storage_types!(@type ($(#[$attr])*) @$M usize ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u8 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u16 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u64 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u128 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M isize ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i8 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i16 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i64 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i128 ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident Ratio ($($tt:tt)*)) => { 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 BigRational ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident Float ($($tt:tt)*)) => { storage_types!(@type ($(#[$attr])*) @$M f32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M f64 ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident Signed ($($tt:tt)*)) => { storage_types!(@type ($(#[$attr])*) @$M isize ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i8 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i16 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i64 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M i128 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M BigInt ($($tt)*)); 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 BigRational ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M f32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M f64 ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident Unsigned ($($tt:tt)*)) => { storage_types!(@type ($(#[$attr])*) @$M usize ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u8 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u16 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u64 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M u128 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M BigUint ($($tt)*)); }; (@type ($(#[$attr:meta])*) @$M:ident Complex ($($tt:tt)*)) => { storage_types!(@type ($(#[$attr])*) @$M Complex32 ($($tt)*)); storage_types!(@type ($(#[$attr])*) @$M Complex64 ($($tt)*)); }; (@mod ($(#[$attr:meta])*) $M:ident, $V:ty; ($($tt:tt)*)) => { $(#[$attr])* mod $M { /// Storage type. #[allow(dead_code)] pub type V = $V; $($tt)* } }; (@pub_mod ($(#[$attr:meta])*) $M:ident, $V:ty; ($($tt:tt)*)) => { $(#[$attr])* pub mod $M { /// Storage type. #[allow(dead_code)] pub type V = $V; $($tt)* } }; ($($tt:tt)*) => { storage_types! { types: All; $($tt)* } }; } macro_rules! storage_type_types { ($($macro_name:ident!($feature:tt, $name:ident, $($type:tt)+);)+) => { $(#[macro_export] #[doc(hidden)] #[cfg(feature = $feature)] macro_rules! $macro_name { ($attr:tt @$M:ident $tt:tt) => { storage_types!(@$M $attr $name, $($type)+; $tt); }; } #[macro_export] #[doc(hidden)] #[cfg(not(feature = $feature))] macro_rules! $macro_name { ($attr:tt @$M:ident $tt:tt) => { }; })+ }; } storage_type_types! { storage_type_usize!("usize", usize, usize); storage_type_u8!("u8", u8, u8); storage_type_u16!("u16", u16, u16); storage_type_u32!("u32", u32, u32); storage_type_u64!("u64", u64, u64); storage_type_u128!("u128", u128, u128); storage_type_isize!("isize", isize, isize); storage_type_i8!("i8", i8, i8); storage_type_i16!("i16", i16, i16); storage_type_i32!("i32", i32, i32); storage_type_i64!("i64", i64, i64); storage_type_i128!("i128", i128, i128); storage_type_bigint!("bigint", bigint, $crate::num::BigInt); storage_type_biguint!("biguint", biguint, $crate::num::BigUint); 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_bigrational!("bigrational", bigrational, $crate::num::BigRational); storage_type_complex32!("complex32", complex32, $crate::num::complex::Complex32); storage_type_complex64!("complex64", complex64, $crate::num::complex::Complex64); storage_type_f32!("f32", f32, f32); storage_type_f64!("f64", f64, f64); } uom-0.35.0/src/system.rs000064400000000000000000002063731046102023000132050ustar 00000000000000/// Macro to implement a [system of quantities](https://jcgm.bipm.org/vim/en/1.3.html). `@...` match /// arms are considered private. /// /// * `$quantities_attr`: System of quantities attributes. Generally used to set documentation /// comments for the system of quantities. /// * `$quantities`: Name of the system of quantities (e.g. `ISQ`). /// * `$name_attr`: Base quantity attributes. Generally used to set documentation comments for base /// units. /// * `$name`: Name of the base quantities for the system of quantities (e.g. `length`, `mass`, /// ...). Note that this name must match the module name of the quantity. /// * `$unit`: Base unit of the quantity (e.g. `meter`, `kilogram`). /// * `$symbol`: Dimension symbol of the quantity. /// * `$units_attr`: System of units attributes. Generally used to set documentation comments for /// the system of units. /// * `$units`: Name of the system of units (e.g. `SI`). /// * `$module`: Module name of the quantity. When prefixed by the `mod` keyword the module must /// already be defined with the `#[macro_use]` attribute. A `#[macro_use] pub mod $module;` /// statement is generated if this variable is not prefixed by the `mod` keyword. /// * `$quantity`: Quantity name (e.g. `Length`, `Mass`, ...). /// /// An example invocation is given below for a meter-kilogram-second system. The `#[macro_use]` /// attribute must be used when including the `uom` crate to make the `system!` macro available. /// /// ``` /// #[macro_use] /// extern crate uom; /// /// # fn main() { } /// # mod mks { /// # #[macro_use] /// # mod length { /// # quantity! { /// # /// Length (base unit meter, m). /// # quantity: Length; "length"; /// # /// Length dimension, m. /// # dimension: Q; /// # units { /// # @meter: 1.0E0; "m", "meter", "meters"; /// # @foot: 3.048E-1; "ft", "foot", "feet"; /// # } /// # } /// # } /// # #[macro_use] /// # mod mass { /// # quantity! { /// # /// Mass (base unit kilogram, kg). /// # quantity: Mass; "mass"; /// # /// Mass dimension, kg. /// # dimension: Q; /// # units { /// # @kilogram: 1.0; "kg", "kilogram", "kilograms"; /// # } /// # } /// # } /// # #[macro_use] /// # mod time { /// # quantity! { /// # /// Time (base unit second, s). /// # quantity: Time; "time"; /// # /// Time dimension, s. /// # dimension: Q; /// # units { /// # @second: 1.0; "s", "second", "seconds"; /// # } /// # } /// # } /// system! { /// /// System of quantities, Q. /// quantities: Q { /// length: meter, L; /// mass: kilogram, M; /// time: second, T; /// } /// /// System of units, U. /// units: U { /// mod length::Length, /// mod mass::Mass, /// mod time::Time, /// } /// } /// # mod f32 { /// # Q!(crate::mks, f32/*, (centimeter, gram, second)*/); /// # } /// # } /// ``` #[macro_export] macro_rules! system { ( $(#[$quantities_attr:meta])* quantities: $quantities:ident { $($(#[$name_attr:meta])* $name:ident: $unit:ident, $symbol:ident;)+ } $(#[$units_attr:meta])* units: $units:ident { $($module:ident::$quantity:ident,)+ } ) => { $(#[macro_use] pub mod $module;)+ system! { $(#[$quantities_attr])* quantities: $quantities { $($(#[$name_attr])* $name: $unit, $symbol;)+ } $(#[$units_attr])* units: $units { $(mod $module::$quantity,)+ } } }; ( $(#[$quantities_attr:meta])* quantities: $quantities:ident { $($(#[$name_attr:meta])* $name:ident: $unit:ident, $symbol:ident;)+ } $(#[$units_attr:meta])* units: $units:ident { $(mod $module:ident::$quantity:ident,)+ } ) => { /// Marker trait to express the dependence of a [quantity][quantity] on the /// [base quantities][base] of a [system of quantities][quantities] as a product of powers /// of factors corresponding to the base quantities, omitting any numerical factor. /// /// * /// /// [quantity]: https://jcgm.bipm.org/vim/en/1.1.html /// [base]: https://jcgm.bipm.org/vim/en/1.4.html /// [quantities]: https://jcgm.bipm.org/vim/en/1.3.html pub trait Dimension: Send + Sync + Unpin + $crate::lib::panic::RefUnwindSafe + $crate::lib::panic::UnwindSafe { $($(#[$name_attr])* /// /// Quantity dimension. type $symbol: $crate::typenum::Integer;)+ /// [Kind](https://jcgm.bipm.org/vim/en/1.2.html) of the quantity. Quantities of the /// same dimension but differing kinds are not comparable. type Kind: ?Sized; } /// Marker trait to identify a [system of units][units] based on a set of [base units][base] /// of a [system of quantities][quantities]. /// /// ## Generic Parameters /// * `V`: Underlying storage type trait is implemented for. /// /// [units]: https://jcgm.bipm.org/vim/en/1.13.html /// [base]: https://jcgm.bipm.org/vim/en/1.10.html /// [quantities]: https://jcgm.bipm.org/vim/en/1.3.html pub trait Units: Send + Sync + Unpin + $crate::lib::panic::RefUnwindSafe + $crate::lib::panic::UnwindSafe where V: $crate::Conversion, { $($(#[$name_attr])* /// /// Base unit. #[allow(non_camel_case_types)] type $name: Unit + $crate::Conversion;)+ } /// Trait to identify [measurement units][measurement] of individual /// [quantities][quantity]. /// /// [measurement]: https://jcgm.bipm.org/vim/en/1.9.html /// [quantity]: https://jcgm.bipm.org/vim/en/1.1.html pub trait Unit: Copy { /// Unit abbreviation. #[must_use = "method returns a static value"] fn abbreviation() -> &'static str; /// Unit singular description. #[must_use = "method returns a static value"] fn singular() -> &'static str; /// Unit plural description. #[must_use = "method returns a static value"] fn plural() -> &'static str; } /// Property of a phenomenon, body or substance, where the property has a magnitude that /// can be expressed as a number and a reference. /// /// The preferred method of creating a `Quantity` instance is to use the `new` constructor /// which is generic over the input unit and accepts the input value as it's only /// parameter. /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::length::meter; /// // Create a length of 1 meter. /// let l = Length::new::(1.0); /// ``` /// /// `Quantity` fields are public to allow for the creation of `const` values and instances /// of non-named `Quantity`s. This functionality will be deprecated and subsequently removed /// once the [`const fn`](https://github.com/rust-lang/rust/issues/24111) feature is /// stabilized. /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::{Quantity, ISQ, SI}; /// # use uom::si::f32::*; /// # use uom::lib::marker::PhantomData; /// # use uom::typenum::{P2, Z0}; /// // Create a `const` length of 1 meter. /// const L: Length = Length { dimension: PhantomData, units: PhantomData, value: 1.0, }; /// // Create a `const` area of 1 square meter explicitly without using the `Area` alias. /// const A: Quantity, SI, f32> = /// Quantity { dimension: PhantomData, units: PhantomData, value: 1.0, }; /// ``` /// /// Using units for the wrong quantity will cause a compile error: /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust,compile_fail")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::time::second; /// // error[E0277]: the trait bound `second: length::Unit` is not satisfied /// let l = Length::new::(1.0); /// ``` /// /// Mixing quantities will also cause a compile error: /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust,compile_fail")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::length::meter; /// # use uom::si::time::second; /// // error[E0308]: mismatched types /// let r = Length::new::(1.0) + Time::new::(1.0); /// ``` /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust,compile_fail")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::length::meter; /// # use uom::si::time::second; /// // error[E0308]: mismatched types /// let v: Velocity = Length::new::(1.0) * Time::new::(1.0); /// ``` /// /// * /// /// ## Generic Parameters /// * `D`: Quantity dimension. See [`Dimension`](./trait.Dimension.html). /// * `U`: Quantity base units. See [`Units`](./trait.Units.html). /// * `V`: Quantity value underlying storage type. #[repr(transparent)] pub struct Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { /// Quantity dimension. See [`Dimension`](./trait.Dimension.html). pub dimension: $crate::lib::marker::PhantomData, /// Quantity base units. See [`Units`](./trait.Units.html). pub units: $crate::lib::marker::PhantomData, /// Quantity value stored in the base units for the quantity. pub value: V, } // Type alias for dimensions where all exponents of the factors are the given value. type DN = dyn Dimension<$($symbol = system!(@replace $symbol N),)+ Kind = dyn $crate::Kind>; /// Type alias for [dimension one][one] for which all the exponents of the factors /// corresponding to the [base quantities][base] are zero. /// /// [one]: https://jcgm.bipm.org/vim/en/1.8.html /// [base]: https://jcgm.bipm.org/vim/en/1.4.html #[allow(dead_code)] pub type DimensionOne = DN<$crate::typenum::Z0>; $(#[$quantities_attr])* pub type $quantities<$($symbol,)+ K = dyn $crate::Kind> = dyn Dimension<$($symbol = $symbol,)+ Kind = K>; $(#[$units_attr])* /// /// ## Generic Parameters /// * `V`: Underlying storage type. #[allow(unused_qualifications)] pub type $units = dyn Units; /// Convert a value from base units to the given unit. /// /// ## Generic Parameters /// * `D`: Dimension. /// * `U`: Base units. /// * `V`: Value underlying storage type. /// * `N`: Unit. #[inline(always)] fn from_base(v: &V) -> V where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::Conversion, N: $crate::Conversion, { use $crate::typenum::Integer; use $crate::{Conversion, ConversionFactor}; let v = v.conversion(); let n_coef = N::coefficient(); let f = V::coefficient() $(* U::$name::coefficient().powi(D::$symbol::to_i32()))+; let n_cons = N::constant($crate::ConstantOp::Sub); if n_coef < f { (v * (f / n_coef) - n_cons).value() } else { (v / (n_coef / f) - n_cons).value() } } /// Convert a value from the given unit to base units. /// /// ## Generic Parameters /// * `D`: Dimension. /// * `U`: Base units. /// * `V`: Value underlying storage type. /// * `N`: Unit. #[inline(always)] fn to_base(v: &V) -> V where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::Conversion, N: $crate::Conversion, { use $crate::typenum::Integer; use $crate::{Conversion, ConversionFactor}; let v = v.conversion(); let n_coef = N::coefficient(); let f = V::coefficient() $(* U::$name::coefficient().powi(D::$symbol::to_i32()))+; let n_cons = N::constant($crate::ConstantOp::Add); if n_coef >= f { ((v + n_cons) * (n_coef / f)).value() } else { (((v + n_cons) * n_coef) / f).value() } } autoconvert_test! { /// Convert a value from one set of base units to a second. /// /// ## Generic Parameters /// * `D`: Dimension. /// * `Ul`: Base units for left quantity. /// * `Ur`: Base units for right quantity. /// * `V`: Value underlying storage type. #[allow(dead_code)] #[inline(always)] fn change_base(v: &V) -> V where D: Dimension + ?Sized, Ul: Units + ?Sized, Ur: Units + ?Sized, V: $crate::Conversion + $crate::lib::ops::Mul, { use $crate::typenum::Integer; use $crate::{Conversion, ConversionFactor}; (v.conversion() $(* Ur::$name::coefficient().powi(D::$symbol::to_i32()) / Ul::$name::coefficient().powi(D::$symbol::to_i32()))+) .value() }} #[doc(hidden)] macro_rules! impl_ops { ( $AddSubTrait:ident, $addsub_fun:ident, $addsub_op:tt, $AddSubAssignTrait:ident, $addsubassign_fun:ident, $addsubassign_op:tt, $AddSubAlias:ident, $MulDivTrait:ident, $muldiv_fun:ident, $muldiv_op:tt, $MulDivAssignTrait:ident, $muldivassign_fun:ident, $muldivassign_op:tt, $Mod:ident ) => { autoconvert! { impl $crate::lib::ops::$AddSubTrait> for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::$AddSubTrait, Ul: Units + ?Sized, Ur: Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { type Output = Quantity; #[inline(always)] fn $addsub_fun(self, rhs: Quantity) -> Self::Output { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value $addsub_op change_base::(&rhs.value), } } }} not_autoconvert! { impl $crate::lib::ops::$AddSubTrait for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::$AddSubTrait, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { type Output = Self; #[inline(always)] fn $addsub_fun(self, rhs: Self) -> Self::Output { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value $addsub_op rhs.value, } } }} autoconvert! { impl $crate::lib::ops::$AddSubAssignTrait> for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::$AddSubAssignTrait, Ul: Units + ?Sized, Ur: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::ops::$AddSubAssignTrait, { #[inline(always)] fn $addsubassign_fun(&mut self, rhs: Quantity) { self.value $addsubassign_op change_base::(&rhs.value); } }} not_autoconvert! { impl $crate::lib::ops::$AddSubAssignTrait for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::$AddSubAssignTrait, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::ops::$AddSubAssignTrait, { #[inline(always)] fn $addsubassign_fun(&mut self, rhs: Self) { self.value $addsubassign_op rhs.value; } }} autoconvert! { impl $crate::lib::ops::$MulDivTrait> for Quantity where Dl: Dimension + ?Sized, $(Dl::$symbol: $crate::lib::ops::$AddSubTrait, >::Output: $crate::typenum::Integer,)+ Dl::Kind: $crate::marker::$MulDivTrait, Dr: Dimension + ?Sized, Dr::Kind: $crate::marker::$MulDivTrait, Ul: Units + ?Sized, Ur: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::ops::$MulDivTrait, { type Output = Quantity< $quantities<$($crate::typenum::$AddSubAlias,)+>, Ul, V>; #[inline(always)] fn $muldiv_fun(self, rhs: Quantity) -> Self::Output { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value $muldiv_op change_base::(&rhs.value), } } }} not_autoconvert! { impl $crate::lib::ops::$MulDivTrait> for Quantity where Dl: Dimension + ?Sized, $(Dl::$symbol: $crate::lib::ops::$AddSubTrait, >::Output: $crate::typenum::Integer,)+ Dl::Kind: $crate::marker::$MulDivTrait, Dr: Dimension + ?Sized, Dr::Kind: $crate::marker::$MulDivTrait, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::ops::$MulDivTrait, { type Output = Quantity< $quantities<$($crate::typenum::$AddSubAlias,)+>, U, V>; #[inline(always)] fn $muldiv_fun(self, rhs: Quantity) -> Self::Output { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value $muldiv_op rhs.value, } } }} impl $crate::lib::ops::$MulDivTrait for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::$MulDivTrait, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { type Output = Quantity; #[inline(always)] fn $muldiv_fun(self, rhs: V) -> Self::Output { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value $muldiv_op rhs, } } } impl $crate::lib::ops::$MulDivAssignTrait for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::$MulDivAssignTrait, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::ops::$MulDivAssignTrait, { #[inline(always)] fn $muldivassign_fun(&mut self, rhs: V) { self.value $muldivassign_op rhs; } } #[doc(hidden)] mod $Mod { storage_types! { use super::super::*; impl $crate::lib::ops::$MulDivTrait> for V where D: Dimension + ?Sized, D::Kind: $crate::marker::$MulDivTrait, U: Units + ?Sized, $($crate::typenum::Z0: $crate::lib::ops::$AddSubTrait, <$crate::typenum::Z0 as $crate::lib::ops::$AddSubTrait>::Output: $crate::typenum::Integer,)+ { type Output = Quantity< $quantities< $($crate::typenum::$AddSubAlias< $crate::typenum::Z0, D::$symbol>,)+ D::Kind>, U, V>; #[inline(always)] fn $muldiv_fun(self, rhs: Quantity) -> Self::Output { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self $muldiv_op rhs.value, } } } } } }; } impl_ops!(Add, add, +, AddAssign, add_assign, +=, Sum, Mul, mul, *, MulAssign, mul_assign, *=, add_mul); impl_ops!(Sub, sub, -, SubAssign, sub_assign, -=, Diff, Div, div, /, DivAssign, div_assign, /=, sub_div); impl Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { /// Returns the floating point category of the number. If only one property is /// going to be tested, it is generally faster to use the specific predicate /// instead. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn classify(self) -> $crate::lib::num::FpCategory where V: $crate::num::Float, { self.value.classify() } std! { autoconvert! { /// Calculates the length of the hypotenuse of a right-angle triangle given the legs. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn hypot(self, other: Quantity) -> Self where V: $crate::num::Float, Ur: Units + ?Sized, { Self { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.hypot(change_base::(&other.value)), } }} not_autoconvert! { /// Calculates the length of the hypotenuse of a right-angle triangle given the legs. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn hypot(self, other: Self) -> Self where V: $crate::num::Float, { Self { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.hypot(other.value), } }}} /// Computes the absolute value of `self`. Returns `NAN` if the quantity is /// `NAN`. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn abs(self) -> Self where V: $crate::num::Signed, { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.abs(), } } /// Returns a quantity that represents the sign of `self`. /// /// * `1.0` of the base unit if the number is positive, `+0.0`, or `INFINITY`. /// * `-1.0` of the base unit if the number is negative, `-0.0`, or /// `NEG_INFINITY`. /// * `NAN` if the number is `NAN`. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn signum(self) -> Self where V: $crate::num::Signed, { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.signum(), } } /// Returns `true` if `self`'s sign bit is positive, including `+0.0` and /// `INFINITY`. #[cfg_attr(feature = "cargo-clippy", allow(clippy::wrong_self_convention))] #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn is_sign_positive(self) -> bool where V: $crate::num::Float, { self.value.is_sign_positive() } /// Returns `true` if `self`'s sign is negative, including `-0.0` and /// `NEG_INFINITY`. #[cfg_attr(feature = "cargo-clippy", allow(clippy::wrong_self_convention))] #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn is_sign_negative(self) -> bool where V: $crate::num::Float, { self.value.is_sign_negative() } /// Takes the reciprocal (inverse) of a number, `1/x`. /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::time::second; /// let f: Frequency = Time::new::(1.0).recip(); /// ``` #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn recip( self ) -> Quantity<$quantities<$($crate::typenum::Negate),+>, U, V> where $(D::$symbol: $crate::lib::ops::Neg, ::Output: $crate::typenum::Integer,)+ D::Kind: $crate::marker::Div, V: $crate::num::Float, { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.recip(), } } /// Returns the maximum of the two quantities. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn max(self, other: Self) -> Self where V: $crate::num::Float, { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.max(other.value), } } /// Returns the minimum of the two quantities. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn min(self, other: Self) -> Self where V: $crate::num::Float, { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.min(other.value), } } } // Explicitly definte floating point methods for float and complex storage types. // `Complex` doesn't implement `Float`/`FloatCore`, but it does implement these methods // when the underlying type, `T`, implements `FloatCore`. mod float { storage_types! { types: Float, Complex; use super::super::*; impl Quantity where D: Dimension + ?Sized, U: Units + ?Sized, { /// Returns `true` if this value is `NAN` and `false` otherwise. #[cfg_attr(feature = "cargo-clippy", allow(clippy::wrong_self_convention))] #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn is_nan(self) -> bool { self.value.is_nan() } /// Returns `true` if this value is positive infinity or negative infinity and /// `false` otherwise. #[cfg_attr(feature = "cargo-clippy", allow(clippy::wrong_self_convention))] #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn is_infinite(self) -> bool { self.value.is_infinite() } /// Returns `true` if this number is neither infinite nor `NAN`. #[cfg_attr(feature = "cargo-clippy", allow(clippy::wrong_self_convention))] #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn is_finite(self) -> bool { self.value.is_finite() } /// Returns `true` if the number is neither zero, infinite, subnormal, or `NAN`. #[cfg_attr(feature = "cargo-clippy", allow(clippy::wrong_self_convention))] #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn is_normal(self) -> bool { self.value.is_normal() } std! { /// Takes the cubic root of a number. /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::volume::cubic_meter; /// let l: Length = Volume::new::(8.0).cbrt(); /// ``` /// /// The input type must have dimensions divisible by three: /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust,compile_fail")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::area::square_meter; /// // error[E0271]: type mismatch resolving ... /// let r = Area::new::(8.0).cbrt(); /// ``` #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn cbrt( self ) -> Quantity< $quantities<$($crate::typenum::PartialQuot),+>, U, V> where $(D::$symbol: $crate::lib::ops::PartialDiv<$crate::typenum::P3>, >::Output: $crate::typenum::Integer,)+ D::Kind: $crate::marker::Div, { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.cbrt(), } } /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. /// This produces a more accurate result with better performance than a separate /// multiplication operation followed by an add. /// /// ## Generic Parameters /// * `Da`: Dimension for parameter `a`. /// * `Ua`: Base units for parameter `a`. /// * `Ub`: Base units for parameter `b`. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn mul_add( self, a: Quantity, b: Quantity<$quantities<$($crate::typenum::Sum),+>, Ub, V>, ) -> Quantity<$quantities<$($crate::typenum::Sum),+>, U, V> where $(D::$symbol: $crate::lib::ops::Add, >::Output: $crate::typenum::Integer,)+ D::Kind: $crate::marker::Mul, Da: Dimension + ?Sized, Da::Kind: $crate::marker::Mul, Ua: Units + ?Sized, Ub: Units + ?Sized, { #[allow(unused_imports)] use $crate::num_traits::MulAdd; // (self * a) + b Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.mul_add(a.value, b.value), } } /// Raises a quantity to an integer power. /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::length::meter; /// use uom::typenum::P2; /// /// let a: Area = Length::new::(3.0).powi(P2::new()); /// ``` /// /// ## Generic Parameters /// * `E`: `typenum::Integer` power. #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn powi( self, _e: E ) -> Quantity<$quantities<$($crate::typenum::Prod),+>, U, V> where $(D::$symbol: $crate::lib::ops::Mul, >::Output: $crate::typenum::Integer,)+ D::Kind: $crate::marker::Mul, E: $crate::typenum::Integer, { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.powi(E::to_i32()), } } /// Takes the square root of a number. Returns `NAN` if `self` is a negative /// number. /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::area::square_meter; /// let l: Length = Area::new::(4.0).sqrt(); /// ``` /// /// The input type must have dimensions divisible by two: /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust,compile_fail")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::length::meter; /// // error[E0271]: type mismatch resolving ... /// let r = Length::new::(4.0).sqrt(); /// ``` #[must_use = "method returns a new number and does not mutate the original value"] #[inline(always)] pub fn sqrt( self ) -> Quantity< $quantities<$($crate::typenum::PartialQuot),+>, U, V> where $(D::$symbol: $crate::typenum::PartialDiv<$crate::typenum::P2>, >::Output: $crate::typenum::Integer,)+ D::Kind: $crate::marker::Div, { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.sqrt(), } }} } } } impl $crate::lib::clone::Clone for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::clone::Clone, { #[inline(always)] fn clone(&self) -> Self { match *self { Quantity { ref value, .. } => { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: $crate::lib::clone::Clone::clone(&(*value)), } } } } } impl $crate::lib::marker::Copy for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::marker::Copy, { } #[allow(non_camel_case_types)] impl $crate::lib::fmt::Debug for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::fmt::Debug, { fn fmt(&self, f: &mut $crate::lib::fmt::Formatter) -> $crate::lib::fmt::Result { self.value.fmt(f) $(.and_then(|_| { let d = ::to_i32(); if 0 != d { write!(f, " {}^{}", U::$name::abbreviation(), d) } else { Ok(()) } }))+ } } impl $crate::lib::default::Default for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::default::Default, { fn default() -> Self { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: V::default(), } } } impl $crate::lib::cmp::Eq for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::cmp::Eq, { } impl $crate::lib::hash::Hash for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::hash::Hash, { fn hash(&self, state: &mut H) { self.value.hash(state); } } impl $crate::lib::ops::Neg for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::Neg, U: Units + ?Sized, V: $crate::num::Signed + $crate::Conversion, { type Output = Quantity; #[inline(always)] fn neg(self) -> Self::Output { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: -self.value, } } } impl $crate::lib::cmp::Ord for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::cmp::Ord, { #[inline(always)] fn cmp(&self, other: &Self) -> $crate::lib::cmp::Ordering { self.value.cmp(&other.value) } #[inline(always)] fn max(self, other: Self) -> Self { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.max(other.value), } } #[inline(always)] fn min(self, other: Self) -> Self { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value.min(other.value), } } } autoconvert! { impl $crate::lib::cmp::PartialEq> for Quantity where D: Dimension + ?Sized, Ul: Units + ?Sized, Ur: Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { #[inline(always)] fn eq(&self, other: &Quantity) -> bool { self.value == change_base::(&other.value) } }} not_autoconvert! { impl $crate::lib::cmp::PartialEq for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { #[inline(always)] fn eq(&self, other: &Self) -> bool { self.value == other.value } }} autoconvert! { impl $crate::lib::cmp::PartialOrd> for Quantity where D: Dimension + ?Sized, Ul: Units + ?Sized, Ur: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::cmp::PartialOrd, { #[inline(always)] fn partial_cmp( &self, other: &Quantity ) -> Option<$crate::lib::cmp::Ordering> { self.value.partial_cmp(&change_base::(&other.value)) } #[inline(always)] fn lt(&self, other: &Quantity) -> bool { self.value.lt(&change_base::(&other.value)) } #[inline(always)] fn le(&self, other: &Quantity) -> bool { self.value.le(&change_base::(&other.value)) } #[inline(always)] fn gt(&self, other: &Quantity) -> bool { self.value.gt(&change_base::(&other.value)) } #[inline(always)] fn ge(&self, other: &Quantity) -> bool { self.value.ge(&change_base::(&other.value)) } }} not_autoconvert! { impl $crate::lib::cmp::PartialOrd for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::cmp::PartialOrd, { #[inline(always)] fn partial_cmp(&self, other: &Self) -> Option<$crate::lib::cmp::Ordering> { self.value.partial_cmp(&other.value) } #[inline(always)] fn lt(&self, other: &Self) -> bool { self.value.lt(&other.value) } #[inline(always)] fn le(&self, other: &Self) -> bool { self.value.le(&other.value) } #[inline(always)] fn gt(&self, other: &Self) -> bool { self.value.gt(&other.value) } #[inline(always)] fn ge(&self, other: &Self) -> bool { self.value.ge(&other.value) } }} autoconvert! { impl $crate::lib::ops::Rem> for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::Rem, Ul: Units + ?Sized, Ur: Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { type Output = Quantity; #[inline(always)] fn rem(self, rhs: Quantity) -> Self::Output { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value % change_base::(&rhs.value) } } }} not_autoconvert! { impl $crate::lib::ops::Rem for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::Rem, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { type Output = Self; #[inline(always)] fn rem(self, rhs: Self) -> Self::Output { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: self.value % rhs.value } } }} autoconvert! { impl $crate::lib::ops::RemAssign> for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::RemAssign, Ul: Units + ?Sized, Ur: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::ops::RemAssign, { #[inline(always)] fn rem_assign(&mut self, rhs: Quantity) { self.value %= change_base::(&rhs.value) } }} not_autoconvert! { impl $crate::lib::ops::RemAssign for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::RemAssign, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::ops::RemAssign, { #[inline(always)] fn rem_assign(&mut self, rhs: Self) { self.value %= rhs.value } }} impl $crate::num::Saturating for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::Saturating, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::num::Saturating, { fn saturating_add(self, v: Self) -> Self { Quantity { value: self.value.saturating_add(v.value), ..self } } fn saturating_sub(self, v: Self) -> Self { Quantity { value: self.value.saturating_sub(v.value), ..self } } } impl $crate::lib::iter::Sum for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::Add, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::iter::Sum, { fn sum(iter: I) -> Self where I: Iterator, { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: iter.map(|v| { v.value }).sum(), } } } test! { impl $crate::tests::Test for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::tests::Test, { fn assert_eq(lhs: &Self, rhs: &Self) { $crate::tests::Test::assert_eq(&lhs.value, &rhs.value); } fn assert_approx_eq(lhs: &Self, rhs: &Self) { $crate::tests::Test::assert_approx_eq(&lhs.value, &rhs.value); } fn eq(lhs: &Self, rhs: &Self) -> bool { $crate::tests::Test::eq(&lhs.value, &rhs.value) } fn approx_eq(lhs: &Self, rhs: &Self) -> bool { $crate::tests::Test::approx_eq(&lhs.value, &rhs.value) } }} impl $crate::num::Zero for Quantity where D: Dimension + ?Sized, D::Kind: $crate::marker::Add, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion, { fn zero() -> Self { Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: V::zero(), } } fn is_zero(&self) -> bool { self.value.is_zero() } } impl $crate::ConstZero for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::ConstZero, { const ZERO: Self = Self { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value: V::ZERO, }; } serde! { impl $crate::serde::Serialize for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::serde::Serialize, { fn serialize(&self, serializer: S) -> Result where S: $crate::serde::Serializer { self.value.serialize(serializer) } } impl<'de, D, U, V> $crate::serde::Deserialize<'de> for Quantity where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::serde::Deserialize<'de>, { fn deserialize(deserializer: De) -> Result where De: $crate::serde::Deserializer<'de>, { let value: V = $crate::serde::Deserialize::deserialize(deserializer)?; Ok(Quantity { dimension: $crate::lib::marker::PhantomData, units: $crate::lib::marker::PhantomData, value, }) } }} /// Utilities for formatting and printing quantities. pub mod fmt { use $crate::lib::fmt; use super::{Dimension, Quantity, Unit, Units, from_base}; use $crate::num::Num; use $crate::Conversion; use $crate::fmt::DisplayStyle; /// A struct to specify a display style and unit. /// /// # Usage /// ## Indirect style #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::length::{centimeter, meter}; /// # use uom::si::fmt::Arguments; /// # use uom::fmt::DisplayStyle::*; /// let l = Length::new::(1.0); /// let a = Length::format_args(centimeter, Description); /// /// assert_eq!("100 centimeters", format!("{}", a.with(l))); /// ``` /// /// ## Direct style #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::length::{centimeter, meter}; /// # use uom::si::fmt::Arguments; /// # use uom::fmt::DisplayStyle::*; /// let l = Length::new::(1.0); /// let a = l.into_format_args(centimeter, Description); /// /// assert_eq!("100 centimeters", format!("{}", a)); /// ``` /// /// ## Generic Parameters /// * `D`: Dimension. /// * `N`: Unit. #[allow(missing_debug_implementations)] // Prevent accidental direct use. pub struct Arguments where D: Dimension + ?Sized, N: Unit, { pub(super) dimension: $crate::lib::marker::PhantomData, pub(super) unit: N, pub(super) style: DisplayStyle, } /// A struct to specify a display style and unit for a given quantity. /// #[cfg_attr(all(feature = "si", feature = "f32"), doc = " ```rust")] #[cfg_attr(not(all(feature = "si", feature = "f32")), doc = " ```rust,ignore")] /// # use uom::si::f32::*; /// # use uom::si::length::{centimeter, meter}; /// # use uom::si::fmt::Arguments; /// # use uom::fmt::DisplayStyle::*; /// let l = Length::new::(1.0); /// let a = l.into_format_args(centimeter, Description); /// /// assert_eq!("100 centimeters", format!("{}", a)); /// ``` /// /// ## Generic Parameters /// * `D`: Dimension. /// * `U`: Base units. /// * `V`: Value underlying storage type. /// * `N`: Unit. pub struct QuantityArguments where D: Dimension + ?Sized, U: Units + ?Sized, V: Num + Conversion, N: Unit, { pub(super) arguments: Arguments, pub(super) quantity: Quantity, } impl $crate::lib::clone::Clone for Arguments where D: Dimension + ?Sized, N: Unit, { fn clone(&self) -> Self { Self { dimension: $crate::lib::marker::PhantomData, unit: self.unit.clone(), style: self.style.clone(), } } } impl $crate::lib::marker::Copy for Arguments where D: Dimension + ?Sized, N: Unit, { } impl $crate::lib::clone::Clone for QuantityArguments where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::clone::Clone, N: Unit, { fn clone(&self) -> Self { Self { arguments: self.arguments.clone(), quantity: self.quantity.clone(), } } } impl $crate::lib::marker::Copy for QuantityArguments where D: Dimension + ?Sized, U: Units + ?Sized, V: $crate::num::Num + $crate::Conversion + $crate::lib::marker::Copy, N: Unit, { } macro_rules! format_arguments { ($style:ident) => { impl fmt::$style for QuantityArguments where D: Dimension + ?Sized, U: Units + ?Sized, V: Num + Conversion + fmt::$style, N: Unit + Conversion, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let value = from_base::(&self.quantity.value); value.fmt(f)?; write!(f, " {}", match self.arguments.style { DisplayStyle::Abbreviation => N::abbreviation(), DisplayStyle::Description => { if value.is_one() { N::singular() } else { N::plural() } }, }) } } }; } format_arguments!(Binary); format_arguments!(Debug); format_arguments!(Display); format_arguments!(LowerExp); format_arguments!(LowerHex); format_arguments!(Octal); format_arguments!(UpperExp); format_arguments!(UpperHex); } /// Macro to implement [`quantity`](si/struct.Quantity.html) type aliases for a specific /// [system of units][units] and value storage type. /// /// * `$system`: Path to the module where the [`system!`](macro.system.html) macro was run /// (e.g. `uom::si`). /// * `$V`: Underlying value storage type (e.g. `f32`). /// * `$U`: Optional. Base units. Pass as a tuple with the desired units: (e.g. `(meter, /// kilogram, second, ampere, kelvin, mole, candela)`). The system's base units will be /// used if no value is provided. When a value is provided a new trait type alias, /// `Units`, is defined. Note that a unit with a non-zero constant factor is not /// currently supported as a base unit. /// /// An example invocation is given below for a meter-kilogram-second system setup in the /// module `mks` with a system of quantities name `Q`. The `#[macro_use]` attribute must be /// used when including the `uom` crate to make macros for predefined systems available. /// The optional units parameter to change the base units is included commented out. /// /// ``` /// #[macro_use] /// extern crate uom; /// /// # fn main() { } /// # mod mks { /// # #[macro_use] /// # mod length { /// # quantity! { /// # /// Length (base unit meter, m). /// # quantity: Length; "length"; /// # /// Length dimension, m. /// # dimension: Q; /// # units { /// # @meter: 1.0E0; "m", "meter", "meters"; /// # @foot: 3.048E-1; "ft", "foot", "feet"; /// # } /// # } /// # } /// # #[macro_use] /// # mod mass { /// # quantity! { /// # /// Mass (base unit kilogram, kg). /// # quantity: Mass; "mass"; /// # /// Mass dimension, kg. /// # dimension: Q; /// # units { /// # @kilogram: 1.0; "kg", "kilogram", "kilograms"; /// # } /// # } /// # } /// # #[macro_use] /// # mod time { /// # quantity! { /// # /// Time (base unit second, s). /// # quantity: Time; "time"; /// # /// Time dimension, s. /// # dimension: Q; /// # units { /// # @second: 1.0; "s", "second", "seconds"; /// # } /// # } /// # } /// # system! { /// # /// System of quantities, Q. /// # quantities: Q { /// # length: meter, L; /// # mass: kilogram, M; /// # time: second, T; /// # } /// # /// System of units, U. /// # units: U { /// # mod length::Length, /// # mod mass::Mass, /// # mod time::Time, /// # } /// # } /// mod f32 { /// Q!(crate::mks, f32/*, (centimeter, gram, second)*/); /// } /// # } /// ``` /// /// [units]: https://jcgm.bipm.org/vim/en/1.13.html #[macro_export] macro_rules! $quantities { ($path:path) => { use $path as __system; $(/// [`Quantity`](struct.Quantity.html) type alias using the default base units /// parameterized on the underlying storage type. /// /// ## Generic Parameters /// * `V`: Underlying storage type. #[allow(dead_code)] #[allow(unused_qualifications)] pub type $quantity = __system::$module::$quantity<__system::$units, V>;)+ }; ($path:path, $V:ty) => { use $path as __system; $(/// [`Quantity`](struct.Quantity.html) type alias using the default base units. #[allow(dead_code)] #[allow(unused_qualifications)] pub type $quantity = __system::$module::$quantity<__system::$units<$V>, $V>;)+ }; ($path:path, $V:ty, $U:tt) => { system!(@quantities $path, $V; $($name),+; $U; $($module::$quantity),+); }; } }; ( @quantities $path:path, $V:ty; $($name:ident),+; ($($U:ident),+); $($module:ident::$quantity:ident),+ ) => { use $path as __system; /// `Units` trait type alias to identify a [system of units][units] based on the set of /// given [base units][base] of a [system of quantities][quantities]. /// /// [units]: https://jcgm.bipm.org/vim/en/1.13.html /// [base]: https://jcgm.bipm.org/vim/en/1.10.html /// [quantities]: https://jcgm.bipm.org/vim/en/1.3.html pub type Units = dyn __system::Units<$V, $($name = __system::$name::$U,)+>; $(/// [`Quantity`](struct.Quantity.html) type alias using the given base units. #[allow(dead_code)] #[allow(unused_qualifications)] pub type $quantity = __system::$module::$quantity;)+ }; (@replace $_t:tt $sub:ty) => { $sub }; } uom-0.35.0/src/tests/asserts.rs000064400000000000000000000151671046102023000145060ustar 00000000000000//! Static assertions. use crate::lib::fmt::{Binary, Debug, Display, LowerExp, LowerHex, Octal, UpperExp, UpperHex}; use crate::lib::hash::Hash; use crate::lib::marker::Unpin; #[cfg(feature = "std")] use crate::lib::panic::{RefUnwindSafe, UnwindSafe}; use crate::tests::*; assert_impl_all!(Arguments, meter>: Clone, Copy, Send, Sync, Unpin); #[cfg(feature = "std")] assert_impl_all!(Arguments, meter>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(Arguments, meter>: Binary, Debug, Display, Eq, Hash, LowerExp, LowerHex, Octal, Ord, PartialEq, PartialOrd, UpperExp, UpperHex); #[rustfmt::skip] assert_impl_all!(DisplayStyle: Clone, Copy, Debug, Send, Sync, Unpin); #[cfg(feature = "std")] #[rustfmt::skip] assert_impl_all!(DisplayStyle: RefUnwindSafe, UnwindSafe); #[rustfmt::skip] assert_not_impl_any!(DisplayStyle: Binary, Display, Eq, Hash, LowerExp, LowerHex, Ord, Octal, PartialEq, PartialOrd, UpperExp, UpperHex); #[rustfmt::skip] assert_impl_all!(ParseQuantityError: Clone, Debug, Display, Eq, PartialEq, Send, Sync, Unpin); #[cfg(feature = "std")] #[rustfmt::skip] assert_impl_all!(ParseQuantityError: RefUnwindSafe, UnwindSafe); #[rustfmt::skip] assert_not_impl_any!(ParseQuantityError: Binary, Copy, Hash, LowerExp, LowerHex, Ord, Octal, PartialOrd, UpperExp, UpperHex); storage_types! { types: Float; use super::*; assert_impl_all!(Quantity, U, V>: Clone, Copy, Debug, PartialEq, PartialOrd, Send, Sync, Unpin); #[cfg(feature = "std")] assert_impl_all!(Quantity, U, V>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(Quantity, U, V>: Binary, Display, Eq, Hash, LowerExp, LowerHex, Octal, Ord, UpperExp, UpperHex); assert_impl_all!(QuantityArguments, U, V, meter>: Clone, Copy, Debug, Display, LowerExp, Send, Sync, Unpin, UpperExp); #[cfg(feature = "std")] assert_impl_all!(QuantityArguments, U, V, meter>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(QuantityArguments, U, V, meter>: Binary, Eq, Hash, LowerHex, Octal, Ord, PartialEq, PartialOrd, UpperHex); } storage_types! { types: PrimInt; use super::*; assert_impl_all!(Quantity, U, V>: Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Send, Sync, Unpin); #[cfg(feature = "std")] assert_impl_all!(Quantity, U, V>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(Quantity, U, V>: Binary, Display, LowerExp, LowerHex, Octal, UpperExp, UpperHex); assert_impl_all!(QuantityArguments, U, V, meter>: Binary, Clone, Copy, Debug, Display, LowerExp, LowerHex, Octal, Send, Sync, Unpin, UpperExp, UpperHex); #[cfg(feature = "std")] assert_impl_all!(QuantityArguments, U, V, meter>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(QuantityArguments, U, V, meter>: Eq, Hash, Ord, PartialEq, PartialOrd); } storage_types! { types: Rational, Rational32, Rational64; use super::*; assert_impl_all!(Quantity, U, V>: Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Send, Sync, Unpin); #[cfg(feature = "std")] assert_impl_all!(Quantity, U, V>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(Quantity, U, V>: Binary, Display, LowerExp, LowerHex, Octal, UpperExp, UpperHex); assert_impl_all!(QuantityArguments, U, V, meter>: Binary, Clone, Copy, Debug, Display, LowerExp, LowerHex, Octal, Send, Sync, Unpin, UpperExp, UpperHex); #[cfg(feature = "std")] assert_impl_all!(QuantityArguments, U, V, meter>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(QuantityArguments, U, V, meter>: Eq, Hash, Ord, PartialEq, PartialOrd); } storage_types! { types: BigInt, BigUint; use super::*; assert_impl_all!(Quantity, U, V>: Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Send, Sync, Unpin); #[cfg(feature = "std")] assert_impl_all!(Quantity, U, V>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(Quantity, U, V>: Binary, Copy, Display, LowerExp, LowerHex, Octal, UpperExp, UpperHex); assert_impl_all!(QuantityArguments, U, V, meter>: Binary, Clone, Debug, Display, LowerHex, Octal, Send, Sync, Unpin, UpperHex); #[cfg(feature = "std")] assert_impl_all!(QuantityArguments, U, V, meter>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(QuantityArguments, U, V, meter>: Copy, Eq, Hash, LowerExp, Ord, PartialEq, PartialOrd, UpperExp); } storage_types! { types: BigRational; use super::*; assert_impl_all!(Quantity, U, V>: Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Send, Sync, Unpin); #[cfg(feature = "std")] assert_impl_all!(Quantity, U, V>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(Quantity, U, V>: Binary, Copy, Display, LowerExp, LowerHex, Octal, UpperExp, UpperHex); assert_impl_all!(QuantityArguments, U, V, meter>: Binary, Clone, Debug, Display, LowerHex, Octal, Send, Sync, Unpin, UpperHex); #[cfg(feature = "std")] assert_impl_all!(QuantityArguments, U, V, meter>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(QuantityArguments, U, V, meter>: Copy, Eq, Hash, LowerExp, Ord, PartialEq, PartialOrd, UpperExp); } storage_types! { types: Complex; use super::*; assert_impl_all!(Quantity, U, V>: Clone, Copy, Debug, PartialEq, Send, Sync, Unpin); #[cfg(feature = "std")] assert_impl_all!(Quantity, U, V>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(Quantity, U, V>: Binary, Display, Eq, Hash, LowerExp, LowerHex, Octal, Ord, PartialOrd, UpperExp, UpperHex); assert_impl_all!(QuantityArguments, U, V, meter>: Clone, Copy, Debug, Display, LowerExp, Send, Sync, Unpin, UpperExp); #[cfg(feature = "std")] assert_impl_all!(QuantityArguments, U, V, meter>: RefUnwindSafe, UnwindSafe); assert_not_impl_any!(QuantityArguments, U, V, meter>: Binary, Eq, Hash, LowerHex, Octal, Ord, PartialEq, PartialOrd, UpperHex); } uom-0.35.0/src/tests/mod.rs000064400000000000000000000173401046102023000135740ustar 00000000000000//! Tests for `uom` macros. #[allow(unused_imports)] use self::fmt::{Arguments, QuantityArguments}; use self::length::{kilometer, meter}; use self::mass::kilogram; use self::thermodynamic_temperature::{degree_fahrenheit, kelvin}; use crate::fmt::DisplayStyle; use crate::lib::fmt::Debug; use crate::lib::marker::PhantomData; #[allow(unused_imports)] use crate::num::{Float, FromPrimitive, One, Saturating, Signed, Zero}; use crate::str::ParseQuantityError; use crate::{ConstantOp, Conversion, ConversionFactor}; use quickcheck::TestResult; #[allow(unused_imports)] use typenum::{N1, P1, P2, P3, Z0}; #[macro_use] mod length { quantity! { quantity: Length; "length"; dimension: Q; units { @kilometer: 1.0_E3; "km", "kilometer", "kilometers"; @meter: 1.0_E0; "m", "meter", "meters"; } } } #[macro_use] mod mass { quantity! { quantity: Mass; "mass"; dimension: Q; units { @kilogram: 1.0_E0; "kg", "kilogram", "kilograms"; } } } #[macro_use] mod thermodynamic_temperature { quantity! { quantity: ThermodynamicTemperature; "thermodynamic temperature"; dimension: Q; units { @kelvin: 1.0_E0; "K", "kelvin", "kelvins"; @degree_fahrenheit: 5.0_E0 / 9.0_E0, 459.67_E0; "°F", "degree Fahrenheit", "degrees Fahrenheit"; } } } system! { quantities: Q { length: meter, L; mass: kilogram, M; thermodynamic_temperature: kelvin, Th; } units: U { mod length::Length, mod mass::Mass, mod thermodynamic_temperature::ThermodynamicTemperature, } } /// Test trait to allow tests to perform storage-type sensitive comparisons. #[rustfmt::skip] pub trait Test: Debug + Sized + PartialEq { /// Assert that `lhs` and `rhs` are exactly equal. fn assert_eq(lhs: &Self, rhs: &Self) { assert_eq!(lhs, rhs); } /// Assert that `lhs` and `rhs` are approximately equal for floating point types or exactly /// equal for other types. fn assert_approx_eq(lhs: &Self, rhs: &Self) { Test::assert_eq(lhs, rhs); } /// Exactly compare `lhs` and `rhs` and return the result. fn eq(lhs: &Self, rhs: &Self) -> bool { lhs == rhs } /// Approximately compare `lhs` and `rhs` for floating point types or exactly compare for other /// types and return the result. fn approx_eq(lhs: &Self, rhs: &Self) -> bool { Test::eq(lhs, rhs) } } mod test_trait { storage_types! { types: Float; use crate::num::Float; // const EPSILON: V = 64.0 * V::epsilon(); //error[E0015]; calls in constants are limited... const EPS_FACTOR: V = 0.5; const ULPS: u32 = 3; impl super::super::Test for V { /// Assert that `lhs` and `rhs` are exactly equal. fn assert_eq(lhs: &Self, rhs: &Self) { match (lhs.is_nan(), rhs.is_nan()) { (true, true) => {} _ => { assert_eq!(lhs, rhs); } } } /// Assert that `lhs` and `rhs` are approximately equal for floating point types or /// exactly equal for other types. fn assert_approx_eq(lhs: &Self, rhs: &Self) { match (lhs.is_nan(), rhs.is_nan()) { (true, true) => {} _ => { assert_ulps_eq!(lhs, rhs, epsilon = EPS_FACTOR * V::epsilon(), max_ulps = ULPS); } } } /// Exactly compare `lhs` and `rhs` and return the result. fn eq(lhs: &Self, rhs: &Self) -> bool { (lhs.is_nan() && rhs.is_nan()) || lhs == rhs } /// Approximately compare `lhs` and `rhs` for floating point types or exactly compare /// for other types and return the result. fn approx_eq(lhs: &Self, rhs: &Self) -> bool { (lhs.is_nan() && rhs.is_nan()) || ulps_eq!(lhs, rhs, epsilon = EPS_FACTOR * V::epsilon(), max_ulps = ULPS) } } } storage_types! { types: PrimInt, BigInt, BigUint, Ratio; impl super::super::Test for V {} } storage_types! { types: Complex; use crate::num::Float; // const EPSILON: VV = 64.0 * VV::epsilon(); //error[E0015]; calls in constants are limited... const EPS_FACTOR: VV = 0.5; const ULPS: u32 = 3; impl super::super::Test for V { /// Assert that `lhs` and `rhs` are exactly equal. fn assert_eq(lhs: &Self, rhs: &Self) { match (lhs.is_nan(), rhs.is_nan()) { (true, true) => {} _ => { assert_eq!(lhs, rhs); } } } /// Assert that `lhs` and `rhs` are approximately equal for floating point types or /// exactly equal for other types. fn assert_approx_eq(lhs: &Self, rhs: &Self) { match (lhs.is_nan(), rhs.is_nan()) { (true, true) => {} _ => { assert_ulps_eq!(lhs.re, rhs.re, epsilon = EPS_FACTOR * VV::epsilon(), max_ulps = ULPS); assert_ulps_eq!(lhs.im, rhs.im, epsilon = EPS_FACTOR * VV::epsilon(), max_ulps = ULPS); } } } /// Exactly compare `lhs` and `rhs` and return the result. fn eq(lhs: &Self, rhs: &Self) -> bool { (lhs.is_nan() && rhs.is_nan()) || lhs == rhs } /// Approximately compare `lhs` and `rhs` for floating point types or exactly compare /// for other types and return the result. fn approx_eq(lhs: &Self, rhs: &Self) -> bool { (lhs.is_nan() && rhs.is_nan()) || ulps_eq!(lhs.re, rhs.re, epsilon = EPS_FACTOR * VV::epsilon(), max_ulps = ULPS) || ulps_eq!(lhs.im, rhs.im, epsilon = EPS_FACTOR * VV::epsilon(), max_ulps = ULPS) } } } } #[derive(Clone, Debug)] pub struct A { v: V, } impl crate::lib::ops::Deref for A { type Target = V; fn deref(&self) -> &Self::Target { &self.v } } mod a_struct { storage_types! { types: Float, PrimInt; use super::super::A; impl quickcheck::Arbitrary for A { fn arbitrary(g: &mut quickcheck::Gen) -> Self { A { v: V::arbitrary(g), } } } } storage_types! { types: BigInt, BigUint, Ratio; use crate::num::FromPrimitive; use super::super::A; impl quickcheck::Arbitrary for A { fn arbitrary(g: &mut quickcheck::Gen) -> Self { A { v: loop { let v = V::from_f64(::arbitrary(g)); if let Some(a) = v { break a; } }, } } } } storage_types! { types: Complex; use super::super::A; impl quickcheck::Arbitrary for A { fn arbitrary(g: &mut quickcheck::Gen) -> Self { A { v: V::new( ::arbitrary(g), ::arbitrary(g)), } } } } } mod asserts; mod quantities; mod quantity; mod system; uom-0.35.0/src/tests/quantities.rs000064400000000000000000000240271046102023000152030ustar 00000000000000//! Tests for the `$quantities!` macro created by the `system!` macro. use crate::tests::*; // Module level constant to verify that creation is possible. #[allow(dead_code)] #[allow(trivial_numeric_casts)] #[cfg(feature = "f32")] const LENGTH: length::Length, f32> = Quantity { dimension: PhantomData, units: PhantomData, value: 1.0 }; #[test] fn description() { assert_eq!("length", length::description()); assert_eq!("mass", mass::description()); } #[test] fn abbreviation() { assert_eq!("km", kilometer::abbreviation()); assert_eq!("m", meter::abbreviation()); assert_eq!("kg", kilogram::abbreviation()); } #[test] fn singular() { assert_eq!("kilometer", kilometer::singular()); assert_eq!("meter", meter::singular()); assert_eq!("kilogram", kilogram::singular()); } #[test] fn plural() { assert_eq!("kilometers", kilometer::plural()); assert_eq!("meters", meter::plural()); assert_eq!("kilograms", kilogram::plural()); } #[test] fn units_abbreviation() { assert_eq!("km", length::Units::kilometer(kilometer).abbreviation()); assert_eq!("m", length::Units::meter(meter).abbreviation()); assert_eq!("kg", mass::Units::kilogram(kilogram).abbreviation()); } #[test] fn units_singular() { assert_eq!("kilometer", length::Units::kilometer(kilometer).singular()); assert_eq!("meter", length::Units::meter(meter).singular()); assert_eq!("kilogram", mass::Units::kilogram(kilogram).singular()); } #[test] fn units_plural() { assert_eq!("kilometers", length::Units::kilometer(kilometer).plural()); assert_eq!("meters", length::Units::meter(meter).plural()); assert_eq!("kilograms", mass::Units::kilogram(kilogram).plural()); } #[test] fn units() { let mut units_iter = length::units(); assert_eq!("km", units_iter.next().unwrap().abbreviation()); assert_eq!(1, units_iter.count()); } storage_types! { use crate::tests::*; Q!(crate::tests, V); #[test] fn struct_literal() { let l = Length { dimension: PhantomData, units: PhantomData, value: V::one(), }; let m = Mass { dimension: PhantomData, units: PhantomData, value: V::one(), }; Test::assert_eq(&V::one(), &l.value); Test::assert_eq(&V::one(), &m.value); } #[test] fn new() { let l1 = Length::new::(V::one()); let l2 = Length::new::(V::one()); let m1 = Mass::new::(V::one()); Test::assert_eq(&V::from_f64(1000.0).unwrap(), &l1.value); Test::assert_eq(&V::one(), &l2.value); Test::assert_eq(&V::one(), &m1.value); } #[test] fn get() { let l1 = Length::new::(V::one()); let l2 = Length::new::(V::one()); let m1 = Mass::new::(V::one()); Test::assert_eq(&V::from_f64(1000.0).unwrap(), &l1.get::()); Test::assert_eq(&V::one(), &l2.get::()); Test::assert_eq(&V::one(), &l1.get::()); Test::assert_eq(&V::from_f64(0.001).unwrap(), &l2.get::()); Test::assert_eq(&V::one(), &m1.get::()); } #[test] fn coefficient() { Test::assert_eq(&V::from_f64(1000.0).unwrap(), &>::coefficient().value()); Test::assert_eq(&V::one(), &>::coefficient().value()); Test::assert_eq(&V::one(), &>::coefficient().value()); Test::assert_eq(&V::from_f64(5.0 / 9.0).unwrap(), &>::coefficient().value()); } #[test] fn constant() { Test::assert_eq(&V::zero(), &>::constant(ConstantOp::Add).value()); Test::assert_eq(&V::from_f64(459.67).unwrap(), &>::constant(ConstantOp::Add).value()); } #[cfg(feature = "std")] #[test] fn debug_fmt() { assert_eq!( format!("{:?} m^1", V::one()), format!("{:?}", Length::new::(V::one()))); assert_eq!( format!("{:?} m^-1", V::one()), format!("{:?}", V::one() / Length::new::(V::one()))); assert_eq!( format!("{:.2?} m^1", V::one()), format!("{:.2?}", Length::new::(V::one()))); assert_eq!( format!("{:?} m^1 kg^1", V::from_f64(1.23).unwrap()), format!("{:?}", Length::new::(V::from_f64(1.23).unwrap()) * Mass::new::(V::one()))); } } mod float { storage_types! { types: Float; use crate::tests::*; Q!(crate::tests, V); #[test] fn floor() { let l1 = Length::new::(3.9999); let l2 = Length::new::(3.0001); let l3 = Length::new::(3.9999); let l4 = Length::new::(3.0001); let m1 = Mass::new::(3.9999); let m2 = Mass::new::(3.0001); Test::assert_eq(&3.0, &l1.floor::().get::()); Test::assert_eq(&3999.0, &l1.floor::().get::()); Test::assert_eq(&3.0, &l2.floor::().get::()); Test::assert_eq(&3000.0, &l2.floor::().get::()); Test::assert_eq(&0.0, &l3.floor::().get::()); Test::assert_eq(&3.0, &l3.floor::().get::()); Test::assert_eq(&0.0, &l4.floor::().get::()); Test::assert_eq(&3.0, &l4.floor::().get::()); Test::assert_eq(&3.0, &m1.floor::().get::()); Test::assert_eq(&3.0, &m2.floor::().get::()); } #[test] fn ceil() { let l1 = Length::new::(3.9999); let l2 = Length::new::(3.0001); let l3 = Length::new::(3.9999); let l4 = Length::new::(3.0001); let m1 = Mass::new::(3.9999); let m2 = Mass::new::(3.0001); Test::assert_eq(&4.0, &l1.ceil::().get::()); Test::assert_eq(&4000.0, &l1.ceil::().get::()); Test::assert_eq(&4.0, &l2.ceil::().get::()); Test::assert_eq(&3001.0, &l2.ceil::().get::()); Test::assert_eq(&1.0, &l3.ceil::().get::()); Test::assert_eq(&4.0, &l3.ceil::().get::()); Test::assert_eq(&1.0, &l4.ceil::().get::()); Test::assert_eq(&4.0, &l4.ceil::().get::()); Test::assert_eq(&4.0, &m1.ceil::().get::()); Test::assert_eq(&4.0, &m2.ceil::().get::()); } #[test] fn round() { let l1 = Length::new::(3.3); let l2 = Length::new::(3.5); let l3 = Length::new::(3.3); let l4 = Length::new::(3.5); let m1 = Mass::new::(3.3); let m2 = Mass::new::(3.5); Test::assert_eq(&3.0, &l1.round::().get::()); Test::assert_eq(&3300.0, &l1.round::().get::()); Test::assert_eq(&4.0, &l2.round::().get::()); Test::assert_eq(&3500.0, &l2.round::().get::()); Test::assert_eq(&0.0, &l3.round::().get::()); Test::assert_eq(&3.0, &l3.round::().get::()); Test::assert_eq(&0.0, &l4.round::().get::()); Test::assert_eq(&4.0, &l4.round::().get::()); Test::assert_eq(&3.0, &m1.round::().get::()); Test::assert_eq(&4.0, &m2.round::().get::()); } #[test] fn trunc() { let l1 = Length::new::(3.3); let l2 = Length::new::(3.5); let l3 = Length::new::(3.3); let l4 = Length::new::(3.5); let m1 = Mass::new::(3.3); let m2 = Mass::new::(3.5); Test::assert_eq(&3.0, &l1.trunc::().get::()); Test::assert_eq(&3300.0, &l1.trunc::().get::()); Test::assert_eq(&3.0, &l2.trunc::().get::()); Test::assert_eq(&3500.0, &l2.trunc::().get::()); Test::assert_eq(&0.0, &l3.trunc::().get::()); Test::assert_eq(&3.0, &l3.trunc::().get::()); Test::assert_eq(&0.0, &l4.trunc::().get::()); Test::assert_eq(&3.0, &l4.trunc::().get::()); Test::assert_eq(&3.0, &m1.trunc::().get::()); Test::assert_eq(&3.0, &m2.trunc::().get::()); } #[test] fn fract() { let l1 = Length::new::(3.3); let l2 = Length::new::(3.3); let m1 = Mass::new::(3.3); Test::assert_eq(&3.3.fract(), &l1.fract::().get::()); Test::assert_eq(&(3.3.fract() * 1000.0), &l1.fract::().get::()); Test::assert_eq(&((3.3 * 1000.0).fract() / 1000.0), &l1.fract::().get::()); Test::assert_eq(&(3.3 * 1000.0).fract(), &l1.fract::().get::()); Test::assert_eq(&(3.3 / 1000.0).fract(), &l2.fract::().get::()); Test::assert_eq(&((3.3 / 1000.0).fract() * 1000.0), &l2.fract::().get::()); Test::assert_eq(&(3.3.fract() / 1000.0), &l2.fract::().get::()); Test::assert_eq(&3.3.fract(), &l2.fract::().get::()); Test::assert_eq(&3.3.fract(), &m1.fract::().get::()); } } } uom-0.35.0/src/tests/quantity.rs000064400000000000000000000545651046102023000147050ustar 00000000000000//! Tests for the `quantity!` macro. storage_types! { use crate::tests::*; mod f { Q!(crate::tests, super::V); } mod k { Q!(crate::tests, super::V, (kilometer, kilogram, kelvin)); } #[test] fn new() { let l1 = k::Length::new::(V::one()); let l2 = k::Length::new::(V::one()); let m1 = k::Mass::new::(V::one()); Test::assert_eq(&V::one(), &l1.value); Test::assert_eq(&V::from_f64(1.0_E-3).unwrap(), &l2.value); Test::assert_eq(&V::one(), &m1.value); } #[test] fn get() { let l1 = k::Length::new::(V::one()); let l2 = k::Length::new::(V::one()); let m1 = k::Mass::new::(V::one()); Test::assert_eq(&V::from_f64(1000.0).unwrap(), &l1.get::()); Test::assert_eq(&V::one(), &l2.get::()); Test::assert_eq(&V::one(), &l1.get::()); Test::assert_eq(&V::from_f64(0.001).unwrap(), &l2.get::()); Test::assert_eq(&V::one(), &m1.get::()); } #[test] fn from_str() { let l1 = k::Length::new::(V::one()); let l2 = k::Length::new::(V::one()); let m1 = k::Mass::new::(V::from_f64(1.0E3).unwrap()); let m2 = k::Mass::new::(V::from_f64(1.0E-3).unwrap()); Test::assert_eq(&"1 m".parse::().unwrap(), &l1); Test::assert_eq(&"1 meter".parse::().unwrap(), &l1); Test::assert_eq(&"1 meters".parse::().unwrap(), &l1); Test::assert_eq(&"1.0 km".parse::().unwrap(), &l2); Test::assert_eq(&"1000 kg".parse::().unwrap(), &m1); Test::assert_eq(&"1.0E-3 kg".parse::().unwrap(), &m2); assert_eq!(&"1m".parse::(), &Err(ParseQuantityError::NoSeparator)); assert_eq!(&"10k m".parse::(), &Err(ParseQuantityError::ValueParseError)); assert_eq!(&"1,000 km".parse::(), &Err(ParseQuantityError::ValueParseError)); assert_eq!(&"10 s".parse::(), &Err(ParseQuantityError::UnknownUnit)); assert_eq!(&"10 kg //10,000 g".parse::(), &Err(ParseQuantityError::UnknownUnit)); } #[cfg(feature = "autoconvert")] quickcheck! { #[allow(trivial_casts)] fn add(l: A, r: A) -> TestResult { let km: V = >::coefficient().value(); let f = (&*l + &*r) / &km; let i = (&*l / &km) + (&*r / &km); if !Test::approx_eq(&i, &f) { return TestResult::discard(); } TestResult::from_bool( Test::approx_eq(&k::Length::new::(&*l + &*r), &(k::Length::new::((*l).clone()) + f::Length::new::((*r).clone())))) } #[allow(trivial_casts)] fn sub(l: A, r: A) -> TestResult { let km: V = >::coefficient().value(); let f = (&*l - &*r) / &km; let i = (&*l / &km) - (&*r / &km); if !Test::approx_eq(&i, &f) { return TestResult::discard(); } TestResult::from_bool( Test::approx_eq(&k::Length::new::(&*l - &*r), &(k::Length::new::((*l).clone()) - f::Length::new::((*r).clone())))) } #[allow(trivial_casts)] fn mul_quantity(l: A, r: A) -> TestResult { let km: V = >::coefficient().value(); TestResult::from_bool( Test::approx_eq(&/*Area::new::*/(&*l * &*r), &(f::Length::new::((*l).clone()) * k::Length::new::((*r).clone())).value) && Test::approx_eq( &/*Area::new::*/(&(&*l / &km) * &(&*r / &km)), &(k::Length::new::((*l).clone()) * f::Length::new::((*r).clone())).value) && Test::approx_eq(&/*Length-mass*/(&*l * &*r), &(f::Length::new::((*l).clone()) * k::Mass::new::((*r).clone())).value) && Test::approx_eq(&/*Length-mass*/(&*l * &*r), &(k::Length::new::((*l).clone()) * f::Mass::new::((*r).clone())).value)) } #[allow(trivial_casts)] fn div_quantity(l: A, r: A) -> TestResult { if *r == V::zero() { return TestResult::discard(); } let km: V = >::coefficient().value(); TestResult::from_bool( Test::approx_eq(&/*Ratio::new::*/(&*l / &*r), &(f::Length::new::((*l).clone()) / k::Length::new::((*r).clone())).value) && Test::approx_eq(&/*Ratio::new::*/(&*l / &*r), &(k::Length::new::((*l).clone()) / f::Length::new::((*r).clone())).value) && Test::approx_eq(&/*Length/mass*/(&*l / &*r), &(f::Length::new::((*l).clone()) / k::Mass::new::((*r).clone())).value) && Test::approx_eq(&/*Length/mass*/(&*l / &km / &*r), &(k::Length::new::((*l).clone()) / f::Mass::new::((*r).clone())).value)) } #[allow(trivial_casts)] fn rem(l: A, r: A) -> TestResult { if *r == V::zero() { return TestResult::discard(); } let km: V = >::coefficient().value(); let f = (&*l % &*r) / &km; let i = (&*l / &km) % (&*r / &km); if !Test::approx_eq(&i, &f) { return TestResult::discard(); } TestResult::from_bool( Test::approx_eq(&k::Length::new::(&*l % &*r), &(k::Length::new::((*l).clone()) % f::Length::new::((*r).clone())))) } #[allow(trivial_casts)] fn eq(l: A, r: A) -> bool { let km: V = >::coefficient().value(); let a = *l == ((*r).clone() / &km) * &km; let b = (*l).clone() / &km == (*r).clone() / &km; let x = f::Length::new::((*l).clone()) == k::Length::new::((*r).clone()); let y = k::Length::new::((*l).clone()) == f::Length::new::((*r).clone()); a == x && b == y } #[allow(trivial_casts)] fn ne(l: A, r: A) -> bool { let km: V = >::coefficient().value(); let a = *l != ((*r).clone() / &km) * &km; let b = (*l).clone() / &km != (*r).clone() / &km; let x = f::Length::new::((*l).clone()) != k::Length::new::((*r).clone()); let y = k::Length::new::((*l).clone()) != f::Length::new::((*r).clone()); a == x && b == y } } } #[cfg(feature = "std")] mod fmt { macro_rules! test_format { ($v:expr, $specifier:expr) => { test_format!($v, $specifier, ["", "+", "05"]); }; ($v:expr, $specifier:expr, [$($option:expr),+]) => { let m = f::Mass::new::((*$v).clone()); let result = true; $(let result = result && format!( concat!("{:", $option, $specifier, "} kilogram{}"), *$v, if $v.is_one() { "" } else { "s" }) == format!( concat!("{:", $option, $specifier, "}"), m.clone().into_format_args(kilogram, DisplayStyle::Description));)+ return result; }; } storage_types! { use crate::tests::*; mod f { Q!(crate::tests, super::V); } quickcheck! { #[allow(trivial_casts)] fn display(v: A) -> bool { test_format!(v, ""); } #[allow(trivial_casts)] fn debug(v: A) -> bool { test_format!(v, "?"); } } #[test] fn round_trip() { let l = f::Length::new::(V::one()); let s1 = &format!("{}", l.clone().into_format_args(kilometer, DisplayStyle::Abbreviation)); assert_eq!(s1.parse::(), Ok(l.clone())); let s2 = &format!("{}", l.clone().into_format_args(meter, DisplayStyle::Abbreviation)); assert_eq!(s2.parse::(), Ok(l.clone())); } } mod float { storage_types! { types: Float; use crate::tests::*; mod f { Q!(crate::tests, super::V); } quickcheck! { #[allow(trivial_casts)] fn lower_exp(v: A) -> bool { test_format!(v, "e"); } #[allow(trivial_casts)] fn upper_exp(v: A) -> bool { test_format!(v, "E"); } } } } mod fixed { storage_types! { types: PrimInt, BigInt, BigUint; use crate::tests::*; mod f { Q!(crate::tests, super::V); } quickcheck! { #[allow(trivial_casts)] fn binary(v: A) -> bool { test_format!(v, "b"); } #[test] fn lower_hex(v: A) -> bool { test_format!(v, "x"); } #[test] fn octal(v: A) -> bool { test_format!(v, "o"); } #[test] fn upper_hex(v: A) -> bool { test_format!(v, "X"); } } } } } #[cfg(feature = "autoconvert")] mod non_big { storage_types! { types: Float, PrimInt, Rational, Rational32, Rational64; use crate::tests::*; mod f { Q!(crate::tests, super::V); } mod k { Q!(crate::tests, super::V, (kilometer, kilogram, kelvin)); } quickcheck! { #[allow(trivial_casts)] fn add_assign(l: A, r: A) -> TestResult { let km: V = >::coefficient().value(); let mut f = *l; let mut i = *l / &km; let mut v = k::Length::new::(*l); f += *r; i += *r / &km; v += f::Length::new::(*r); if !Test::approx_eq(&i, &(f / &km)) { return TestResult::discard(); } TestResult::from_bool(Test::approx_eq(&k::Length::new::(f), &v)) } #[allow(trivial_casts)] fn sub_assign(l: A, r: A) -> TestResult { let km: V = >::coefficient().value(); let mut f = *l; let mut i = *l / &km; let mut v = k::Length::new::(*l); f -= *r; i -= *r / &km; v -= f::Length::new::(*r); if !Test::approx_eq(&i, &(f / &km)) { return TestResult::discard(); } TestResult::from_bool(Test::approx_eq(&k::Length::new::(f), &v)) } #[allow(trivial_casts)] fn rem_assign(l: A, r: A) -> TestResult { if *r == V::zero() { return TestResult::discard(); } let km: V = >::coefficient().value(); let mut f = *l; let mut i = *l / &km; let mut v = k::Length::new::(*l); f %= *r; i %= *r / &km; v %= f::Length::new::(*r); if !Test::approx_eq(&i, &(f / km)) { return TestResult::discard(); } TestResult::from_bool(Test::approx_eq(&k::Length::new::(f), &v)) } } } } mod float { storage_types! { types: Float; use crate::tests::*; mod f { Q!(crate::tests, super::V); } mod k { Q!(crate::tests, super::V, (kilometer, kilogram, kelvin)); } #[test] fn floor() { let l1 = k::Length::new::(3.9999); let l2 = k::Length::new::(3.0001); let l3 = k::Length::new::(3.9999); let l4 = k::Length::new::(3.0001); let m1 = k::Mass::new::(3.9999); let m2 = k::Mass::new::(3.0001); Test::assert_eq(&3.0, &l1.floor::().get::()); Test::assert_eq(&3999.0, &l1.floor::().get::()); Test::assert_eq(&3.0, &l2.floor::().get::()); Test::assert_eq(&3000.0, &l2.floor::().get::()); Test::assert_eq(&0.0, &l3.floor::().get::()); Test::assert_eq(&3.0, &l3.floor::().get::()); Test::assert_eq(&0.0, &l4.floor::().get::()); Test::assert_eq(&3.0, &l4.floor::().get::()); Test::assert_eq(&3.0, &m1.floor::().get::()); Test::assert_eq(&3.0, &m2.floor::().get::()); } #[test] fn ceil() { let l1 = k::Length::new::(3.9999); let l2 = k::Length::new::(3.0001); let l3 = k::Length::new::(3.9999); let l4 = k::Length::new::(3.0001); let m1 = k::Mass::new::(3.9999); let m2 = k::Mass::new::(3.0001); Test::assert_eq(&4.0, &l1.ceil::().get::()); Test::assert_eq(&4000.0, &l1.ceil::().get::()); Test::assert_eq(&4.0, &l2.ceil::().get::()); Test::assert_eq(&3001.0, &l2.ceil::().get::()); Test::assert_eq(&1.0, &l3.ceil::().get::()); Test::assert_eq(&4.0, &l3.ceil::().get::()); Test::assert_eq(&1.0, &l4.ceil::().get::()); Test::assert_eq(&4.0, &l4.ceil::().get::()); Test::assert_eq(&4.0, &m1.ceil::().get::()); Test::assert_eq(&4.0, &m2.ceil::().get::()); } #[test] fn round() { let l1 = k::Length::new::(3.3); let l2 = k::Length::new::(3.5); let l3 = k::Length::new::(3.3); let l4 = k::Length::new::(3.5); let m1 = k::Mass::new::(3.3); let m2 = k::Mass::new::(3.5); Test::assert_eq(&3.0, &l1.round::().get::()); Test::assert_eq(&3300.0, &l1.round::().get::()); Test::assert_eq(&4.0, &l2.round::().get::()); Test::assert_eq(&3500.0, &l2.round::().get::()); Test::assert_eq(&0.0, &l3.round::().get::()); Test::assert_eq(&3.0, &l3.round::().get::()); Test::assert_eq(&0.0, &l4.round::().get::()); Test::assert_eq(&4.0, &l4.round::().get::()); Test::assert_eq(&3.0, &m1.round::().get::()); Test::assert_eq(&4.0, &m2.round::().get::()); } #[test] fn trunc() { let l1 = k::Length::new::(3.3); let l2 = k::Length::new::(3.5); let l3 = k::Length::new::(3.3); let l4 = k::Length::new::(3.5); let m1 = k::Mass::new::(3.3); let m2 = k::Mass::new::(3.5); Test::assert_eq(&3.0, &l1.trunc::().get::()); Test::assert_eq(&3300.0, &l1.trunc::().get::()); Test::assert_eq(&3.0, &l2.trunc::().get::()); Test::assert_eq(&3500.0, &l2.trunc::().get::()); Test::assert_eq(&0.0, &l3.trunc::().get::()); Test::assert_eq(&3.0, &l3.trunc::().get::()); Test::assert_eq(&0.0, &l4.trunc::().get::()); Test::assert_eq(&3.0, &l4.trunc::().get::()); Test::assert_eq(&3.0, &m1.trunc::().get::()); Test::assert_eq(&3.0, &m2.trunc::().get::()); } #[test] fn fract() { let l1 = k::Length::new::(3.3); let l2 = k::Length::new::(3.3); let m1 = k::Mass::new::(3.3); Test::assert_eq(&3.3.fract(), &l1.fract::().get::()); Test::assert_eq(&(3.3.fract() * 1000.0), &l1.fract::().get::()); Test::assert_eq(&((3.3 * 1000.0).fract() / 1000.0), &l1.fract::().get::()); Test::assert_eq(&(3.3 * 1000.0).fract(), &l1.fract::().get::()); Test::assert_eq(&(3.3 / 1000.0).fract(), &l2.fract::().get::()); Test::assert_eq(&((3.3 / 1000.0).fract() * 1000.0), &l2.fract::().get::()); Test::assert_eq(&(3.3.fract() / 1000.0), &l2.fract::().get::()); Test::assert_eq(&3.3.fract(), &l2.fract::().get::()); Test::assert_eq(&3.3.fract(), &m1.fract::().get::()); } #[cfg(feature = "std")] quickcheck! { #[allow(trivial_casts)] fn hypot_same(l: V, r: V) -> bool { Test::eq(&l.hypot(r), &f::Length::new::(l).hypot(f::Length::new::(r)).get::()) } } #[cfg(all(feature = "std", feature = "autoconvert"))] quickcheck! { #[allow(trivial_casts)] fn hypot_mixed(l: V, r: V) -> bool { let fk = Test::approx_eq(&l.hypot(r), &f::Length::new::(l).hypot(k::Length::new::(r)).get::()); let kf = Test::approx_eq(&l.hypot(r), &k::Length::new::(l).hypot(f::Length::new::(r)).get::()); fk && kf } } } } #[cfg(feature = "autoconvert")] mod non_complex { storage_types! { // Everything BUT complex types: PrimInt, Ratio, Float, BigInt, BigUint; use crate::tests::*; mod f { Q!(crate::tests, super::V); } mod k { Q!(crate::tests, super::V, (kilometer, kilogram, kelvin)); } quickcheck! { #[allow(trivial_casts)] fn partial_cmp(l: A, r: A) -> bool { let km: V = >::coefficient().value(); let a = (*l).partial_cmp(&(((*r).clone() / &km) * &km)); let b = ((*l).clone() / &km).partial_cmp(&((*r).clone() / &km)); let x = f::Length::new::((*l).clone()).partial_cmp( &k::Length::new::((*r).clone())); let y = k::Length::new::((*l).clone()).partial_cmp( &f::Length::new::((*r).clone())); a == x && b == y } #[allow(trivial_casts)] fn lt(l: A, r: A) -> bool { let km: V = >::coefficient().value(); let a = (*l).lt(&(((*r).clone() / &km) * &km)); let b = ((*l).clone() / &km).lt(&((*r).clone() / &km)); let x = f::Length::new::((*l).clone()).lt( &k::Length::new::((*r).clone())); let y = k::Length::new::((*l).clone()).lt( &f::Length::new::((*r).clone())); a == x && b == y } #[allow(trivial_casts)] fn le(l: A, r: A) -> bool { let km: V = >::coefficient().value(); let a = (*l).le(&(((*r).clone() / &km) * &km)); let b = ((*l).clone() / &km).le(&((*r).clone() / &km)); let x = f::Length::new::((*l).clone()).le( &k::Length::new::((*r).clone())); let y = k::Length::new::((*l).clone()).le( &f::Length::new::((*r).clone())); a == x && b == y } #[allow(trivial_casts)] fn gt(l: A, r: A) -> bool { let km: V = >::coefficient().value(); let a = (*l).gt(&(((*r).clone() / &km) * &km)); let b = ((*l).clone() / &km).gt(&((*r).clone() / &km)); let x = f::Length::new::((*l).clone()).gt( &k::Length::new::((*r).clone())); let y = k::Length::new::((*l).clone()).gt( &f::Length::new::((*r).clone())); a == x && b == y } #[allow(trivial_casts)] fn ge(l: A, r: A) -> bool { let km: V = >::coefficient().value(); let a = (*l).ge(&(((*r).clone() / &km) * &km)); let b = ((*l).clone() / &km).ge(&((*r).clone() / &km)); let x = f::Length::new::((*l).clone()).ge( &k::Length::new::((*r).clone())); let y = k::Length::new::((*l).clone()).ge( &f::Length::new::((*r).clone())); a == x && b == y } } } } uom-0.35.0/src/tests/system.rs000064400000000000000000000631531046102023000143440ustar 00000000000000//! Tests for the `system!` macro. storage_types! { use crate::tests::*; type MeterKelvinBase = dyn Units; type KilometerFahrenheitBase = dyn Units; Q!(crate::tests, V); #[test] fn zero() { let z = Length::zero(); Test::assert_eq(&V::zero(), &z.value); assert!(z.is_zero()); } quickcheck! { #[allow(trivial_casts)] fn from_base(v: A) -> bool { let km: V = >::coefficient().value(); let f_coefficient: V = >::coefficient().value(); let f_constant: V = >::constant(ConstantOp::Add).value(); // meter -> meter. Test::approx_eq(&*v, &crate::tests::from_base::(&*v)) // kilometer -> kilometer. && Test::approx_eq(&*v, &crate::tests::from_base::( &*v)) // meter -> kilometer. && Test::approx_eq(&(&*v / &km), &crate::tests::from_base::( &*v)) // kilometer -> meter. && Test::approx_eq(&(&*v * &km), &crate::tests::from_base::( &*v)) // kelvin -> kelvin. && Test::approx_eq(&*v, &crate::tests::from_base::( &*v)) // fahrenheit -> fahrenheit. // && Test::approx_eq(&*v, // &crate::tests::from_base::( // &*v)) // kelvin -> fahrenheit. && Test::approx_eq(&((&*v * (&V::one() / &f_coefficient)) - &f_constant), &crate::tests::from_base::( &*v)) // fahrenheit -> kelvin. // && Test::approx_eq(&(&(&*v + &f_constant) * &f_coefficient), // &crate::tests::from_base::( // &*v)) } #[allow(trivial_casts)] fn to_base(v: A) -> bool { let km: V = >::coefficient().value(); let f_coefficient: V = >::coefficient().value(); let f_constant: V = >::constant(ConstantOp::Add).value(); // meter -> meter. Test::approx_eq(&*v, &crate::tests::to_base::(&*v)) // kilometer -> kilometer. && Test::approx_eq(&*v, &crate::tests::to_base::( &*v)) // kilometer -> meter. && Test::approx_eq(&(&*v * &km), &crate::tests::to_base::(&*v)) // meter -> kilometer. && Test::approx_eq(&(&*v / &km), &crate::tests::to_base::( &*v)) // kelvin -> kelvin. && Test::approx_eq(&*v, &crate::tests::to_base::( &*v)) // fahrenheit -> fahrenheit. // && Test::approx_eq(&*v, // &crate::tests::to_base::( // &*v)) // fahrenheit -> kelvin. && Test::approx_eq(&(&(&*v + &f_constant) * &f_coefficient), &crate::tests::to_base::( &*v)) // kelvin -> fahrenheit. // && Test::approx_eq(&(&*v / &f_coefficient - &f_constant), // &crate::tests::to_base::( // &*v)) } #[allow(trivial_casts)] fn change_base(v: A) -> TestResult { let km: V = >::coefficient().value(); let f1 = (*v).clone(); let i1 = &*v * &km / &km; if !Test::approx_eq(&f1, &i1) { return TestResult::discard(); } TestResult::from_bool( // meter -> meter. Test::approx_eq(&*v, &crate::tests::change_base::( &*v)) // kilometer -> kilometer. && Test::approx_eq(&*v, &crate::tests::change_base::( &*v)) // kilometer -> meter. && Test::approx_eq(&(&*v * &km), &crate::tests::change_base::( &*v)) // meter -> kilometer. && Test::approx_eq(&(&*v / &km), &crate::tests::change_base::( &*v))) } #[allow(trivial_casts)] fn add(l: A, r: A) -> bool { Test::eq(&Length::new::(&*l + &*r), &(Length::new::((*l).clone()) + Length::new::((*r).clone()))) } #[allow(trivial_casts)] fn sub(l: A, r: A) -> bool { Test::eq(&Length::new::(&*l - &*r), &(Length::new::((*l).clone()) - Length::new::((*r).clone()))) } #[allow(trivial_casts)] fn mul_quantity(l: A, r: A) -> bool { Test::eq(&/*Area::new::*/(&*l * &*r), &(Length::new::((*l).clone()) * Length::new::((*r).clone())).value) } #[allow(trivial_casts)] fn mul_v(l: A, r: A) -> bool { Test::eq(&Length::new::(&*l * &*r), &(Length::new::((*l).clone()) * (*r).clone())) && Test::eq(&Length::new::(&*l * &*r), &((*l).clone() * Length::new::((*r).clone()))) } #[allow(trivial_casts)] fn div_quantity(l: A, r: A) -> TestResult { if *r == V::zero() { return TestResult::discard(); } // TODO Use `.get(?)`, add ratio type? TestResult::from_bool( Test::eq(&(&*l / &*r), &(Length::new::((*l).clone()) / Length::new::((*r).clone())).value)) } #[allow(trivial_casts)] fn div_v(l: A, r: A) -> TestResult { if *r == V::zero() { return TestResult::discard(); } TestResult::from_bool( Test::eq(&Length::new::(&*l / &*r), &(Length::new::((*l).clone()) / (*r).clone())) && Test::eq(&/*ReciprocalLength::new::*/(&*l / &*r), &((*l).clone() / Length::new::((*r).clone())).value)) } #[allow(trivial_casts)] fn eq(l: A, r: A) -> bool { (*l == *r) == (Length::new::((*l).clone()) == Length::new::((*r).clone())) } #[allow(trivial_casts)] fn ne(l: A, r: A) -> bool { (*l != *r) == (Length::new::((*l).clone()) != Length::new::((*r).clone())) } #[allow(trivial_casts)] fn rem(l: A, r: A) -> TestResult { if *r == V::zero() { return TestResult::discard(); } TestResult::from_bool( Test::approx_eq(&Length::new::(&*l % &*r), &(Length::new::((*l).clone()) % Length::new::((*r).clone())))) } } } mod prim_int { storage_types! { types: PrimInt; use crate::tests::*; Q!(crate::tests, V); quickcheck! { #[allow(trivial_casts)] fn saturating_add(l: A, r: A) -> bool { Test::eq(&(l.saturating_add(*r)), &(Length::new::((*l).clone()) .saturating_add(Length::new::((*r).clone())).get::())) } #[allow(trivial_casts)] fn saturating_sub(l: A, r: A) -> bool { Test::eq(&(l.saturating_sub(*r)), &(Length::new::((*l).clone()) .saturating_sub(Length::new::((*r).clone())).get::())) } } } } mod float { storage_types! { types: Float; use crate::tests::*; Q!(crate::tests, V); #[test] fn fp_categories() { assert!(!Length::new::(V::infinity()).is_finite()); assert!(!Length::new::(V::neg_infinity()).is_finite()); assert!(Length::new::(V::infinity()).is_infinite()); assert!(Length::new::(V::neg_infinity()).is_infinite()); assert!(Length::new::(V::min_positive_value()).is_normal()); assert!(Length::new::(V::max_value()).is_normal()); assert!(!Length::new::(V::zero()).is_normal()); assert!(!Length::new::(V::nan()).is_normal()); assert!(!Length::new::(V::infinity()).is_normal()); } quickcheck! { #[allow(trivial_casts)] fn is_nan(v: A) -> bool { v.is_nan() == Length::new::(*v).is_nan() } #[allow(trivial_casts)] fn is_infinite(v: A) -> bool { v.is_infinite() == Length::new::(*v).is_infinite() } #[allow(trivial_casts)] fn is_finite(v: A) -> bool { v.is_finite() == Length::new::(*v).is_finite() } #[allow(trivial_casts)] fn is_normal(v: A) -> bool { v.is_normal() == Length::new::(*v).is_normal() } #[allow(trivial_casts)] fn classify(v: A) -> bool { v.classify() == Length::new::(*v).classify() } #[cfg(feature = "std")] #[allow(trivial_casts)] fn cbrt(v: A) -> bool { let l: Quantity, U, V> = Quantity::, U, V> { dimension: PhantomData, units: PhantomData, value: *v, }.cbrt(); Test::eq(&v.cbrt(), &l.value) } #[cfg(feature = "std")] #[allow(trivial_casts)] fn hypot(l: A, r: A) -> bool { Test::eq(&Length::new::(l.hypot(*r)), &Length::new::(*l).hypot(Length::new::(*r))) } #[allow(trivial_casts)] fn is_sign_positive(v: A) -> bool { v.is_sign_positive() == Length::new::(*v).is_sign_positive() } #[allow(trivial_casts)] fn is_sign_negative(v: A) -> bool { v.is_sign_negative() == Length::new::(*v).is_sign_negative() } #[cfg(feature = "std")] #[allow(trivial_casts)] fn mul_add(s: A, a: A, b: A) -> bool { let r: Quantity, U, V> = Length::new::(*s).mul_add( Length::new::(*a), Quantity::, U, V> { dimension: PhantomData, units: PhantomData, value: *b }); Test::eq(&s.mul_add(*a, *b), &r.value) } #[allow(trivial_casts)] fn recip(v: A) -> bool { let a: Quantity, U, V> = Quantity::, U, V> { dimension: PhantomData, units: PhantomData, value: *v, }.recip(); Test::eq(&v.recip(), &a.value) } #[cfg(feature = "std")] #[allow(trivial_casts)] fn powi(v: A) -> bool { Test::eq(&v.powi(3), &Length::new::(*v).powi(P3::new()).value) } #[cfg(feature = "std")] #[allow(trivial_casts)] fn sqrt(v: A) -> TestResult { if *v < V::zero() { return TestResult::discard(); } let l: Quantity, U, V> = Quantity::, U, V> { dimension: PhantomData, units: PhantomData, value: *v, }.sqrt(); TestResult::from_bool(Test::eq(&v.sqrt(), &l.value)) } #[allow(trivial_casts)] fn max(l: A, r: A) -> bool { Test::eq(&Length::new::(l.max(*r)), &Length::new::(*l).max(Length::new::(*r))) } #[allow(trivial_casts)] fn min(l: A, r: A) -> bool { Test::eq(&Length::new::(l.min(*r)), &Length::new::(*l).min(Length::new::(*r))) } } } } mod signed { storage_types! { types: Signed; use crate::tests::*; Q!(crate::tests, V); quickcheck! { #[allow(trivial_casts)] fn abs(v: A) -> bool { Test::eq(&Length::new::(v.abs()), &Length::new::((*v).clone()).abs()) } #[allow(trivial_casts)] fn signum(v: A) -> bool { Test::eq(&Length::new::(v.signum()), &Length::new::((*v).clone()).signum()) } #[allow(trivial_casts)] fn neg(l: A) -> bool { Test::eq(&Length::new::(-(*l).clone()), &-Length::new::((*l).clone())) } } } } mod non_ratio { storage_types! { types: PrimInt, BigInt, BigUint, Float; use crate::tests::*; Q!(crate::tests, V); #[test] fn default() { Test::assert_eq(&Length::new::(V::default()), &Length::default()); } } } mod non_big { storage_types! { types: PrimInt, Rational, Rational32, Rational64, Float; use crate::tests::*; Q!(crate::tests, V); quickcheck! { #[allow(trivial_casts)] fn add_assign(l: A, r: A) -> bool { let mut f = *l; let mut v = Length::new::(*l); f += *r; v += Length::new::(*r); Test::eq(&Length::new::(f), &v) } #[allow(trivial_casts)] fn sub_assign(l: A, r: A) -> bool { let mut f = *l; let mut v = Length::new::(*l); f -= *r; v -= Length::new::(*r); Test::eq(&Length::new::(f), &v) } #[allow(trivial_casts)] fn mul_assign(l: A, r: A) -> bool { let mut f = *l; let mut v = Length::new::(*l); f *= *r; v *= *r; Test::eq(&Length::new::(f), &v) } #[allow(trivial_casts)] fn div_assign(l: A, r: A) -> TestResult { if *r == V::zero() { return TestResult::discard(); } let mut f = *l; let mut v = Length::new::(*l); f /= *r; v /= *r; TestResult::from_bool(Test::eq(&Length::new::(f), &v)) } #[allow(trivial_casts)] fn rem_assign(l: A, r: A) -> TestResult { if *r == V::zero() { return TestResult::discard(); } let mut f = *l; let mut v = Length::new::(*l); f %= *r; v %= Length::new::(*r); TestResult::from_bool(Test::approx_eq(&Length::new::(f), &v)) } } } } mod primitive { storage_types! { types: Float, PrimInt; use crate::tests::*; Q!(crate::tests, V); #[test] fn sum() { Test::assert_eq( &Length::new::( (1..10).map(V::from_i32).map(Option::unwrap).sum()), &(1..10).map(V::from_i32).map(Option::unwrap) .map(|v| { Length::new::(v) }).sum()); } #[cfg(feature = "serde")] quickcheck! { // These serde tests can't be run against num-backed numeric backends because the // num crate hasn't been updated to Serde 1.0 yet. #[allow(trivial_casts)] fn serde_serialize(v: A) -> bool { let m = Length::new::((*v).clone()); let json_f = serde_json::to_string(&*v).expect("Must be able to serialize num"); let json_q = serde_json::to_string(&m).expect("Must be able to serialize Quantity"); json_f == json_q } #[allow(trivial_casts)] fn serde_deserialize(v: A) -> TestResult { let json_f = serde_json::to_string(&*v).expect("Must be able to serialize num"); if serde_json::from_str::(&json_f).is_err() { return TestResult::discard(); } let length: Length = serde_json::from_str(&json_f) .expect("Must be able to deserialize Quantity"); TestResult::from_bool(Test::approx_eq(&Length::new::(*v), &length)) } } } } mod fixed { storage_types! { types: PrimInt, BigInt, BigUint, Ratio; use crate::tests::*; Q!(crate::tests, V); quickcheck! { #[allow(trivial_casts)] fn cmp(l: A, r: A) -> bool { (*l).cmp(&*r) == Length::new::((*l).clone()).cmp( &Length::new::((*r).clone())) } #[allow(trivial_casts)] fn max(l: A, r: A) -> bool { Test::eq(&Length::new::((*l).clone().max((*r).clone())), &Ord::max(Length::new::((*l).clone()), Length::new::((*r).clone()))) } #[allow(trivial_casts)] fn min(l: A, r: A) -> bool { Test::eq(&Length::new::((*l).clone().min((*r).clone())), &Ord::min(Length::new::((*l).clone()), Length::new::((*r).clone()))) } } } } mod complex { storage_types! { types: Complex; use crate::tests::*; Q!(crate::tests, V); #[test] fn fp_categories() { let float_categories = [ VV::neg_infinity(), VV::min_value(), VV::zero(), VV::max_value(), VV::infinity(), VV::nan(), ]; for re in float_categories { for im in float_categories { let complex = V::new(re, im); // Infinities if complex.is_infinite() { assert!(!Length::new::(complex).is_finite()); assert!(Length::new::(complex).is_infinite()); assert!(!Length::new::(complex).is_normal()); assert!(!Length::new::(complex).is_nan()); } // NaNs if complex.is_nan() { assert!(!Length::new::(complex).is_finite()); assert!(!Length::new::(complex).is_infinite()); assert!(!Length::new::(complex).is_normal()); assert!(Length::new::(complex).is_nan()); } // Finite and normal numbers if !complex.is_infinite() && !complex.is_nan() { assert!(Length::new::(complex).is_finite()); assert!(!Length::new::(complex).is_infinite()); assert!(Length::new::(complex).is_normal()); assert!(!Length::new::(complex).is_nan()); } } } } quickcheck! { #[allow(trivial_casts)] fn is_nan(v: A) -> bool { v.is_nan() == Length::new::(*v).is_nan() } #[allow(trivial_casts)] fn is_infinite(v: A) -> bool { v.is_infinite() == Length::new::(*v).is_infinite() } #[allow(trivial_casts)] fn is_finite(v: A) -> bool { v.is_finite() == Length::new::(*v).is_finite() } #[allow(trivial_casts)] fn is_normal(v: A) -> bool { v.is_normal() == Length::new::(*v).is_normal() } #[cfg(feature = "std")] #[allow(trivial_casts)] fn cbrt(v: A) -> bool { let l: Quantity, U, V> = Quantity::, U, V> { dimension: PhantomData, units: PhantomData, value: *v, }.cbrt(); Test::eq(&v.cbrt(), &l.value) } #[cfg(feature = "std")] #[allow(trivial_casts)] fn mul_add(s: A, a: A, b: A) -> bool { #[allow(unused_imports)] use num_traits::MulAdd; let r: Quantity, U, V> = Length::new::(*s).mul_add( Length::new::(*a), Quantity::, U, V> { dimension: PhantomData, units: PhantomData, value: *b }); Test::eq(&s.mul_add(*a, *b), &r.value) } #[cfg(feature = "std")] #[allow(trivial_casts)] fn powi(v: A) -> bool { Test::eq(&v.powi(3), &Length::new::(*v).powi(P3::new()).value) } #[cfg(feature = "std")] #[allow(trivial_casts)] fn sqrt(v: A) -> TestResult { let l: Quantity, U, V> = Quantity::, U, V> { dimension: PhantomData, units: PhantomData, value: *v, }.sqrt(); TestResult::from_bool(Test::eq(&v.sqrt(), &l.value)) } } } } mod non_complex { storage_types! { types: PrimInt, Float, Ratio, BigInt, BigUint; use crate::tests::*; Q!(crate::tests, V); quickcheck! { #[allow(trivial_casts)] fn partial_cmp(l: A, r: A) -> bool { (*l).partial_cmp(&*r) == Length::new::((*l).clone()).partial_cmp( &Length::new::((*r).clone())) } #[allow(trivial_casts)] fn lt(l: A, r: A) -> bool { (*l).lt(&*r) == Length::new::((*l).clone()).lt(&Length::new::((*r).clone())) } #[allow(trivial_casts)] fn le(l: A, r: A) -> bool { (*l).le(&*r) == Length::new::((*l).clone()).le(&Length::new::((*r).clone())) } #[allow(trivial_casts)] fn gt(l: A, r: A) -> bool { (*l).gt(&*r) == Length::new::((*l).clone()).gt(&Length::new::((*r).clone())) } #[allow(trivial_casts)] fn ge(l: A, r: A) -> bool { (*l).ge(&*r) == Length::new::((*l).clone()).ge(&Length::new::((*r).clone())) } } } } uom-0.35.0/src/unit.rs000064400000000000000000000234371046102023000126360ustar 00000000000000/// Macro to implement a set of [measurement units][measurement]. Note that units manually defined /// using this macro will not be included in the quantity unit enum or associated functions, or in /// the `FromStr` implementation. Using this macro will create submodules for the underlying storage /// types that are enabled (e.g. `mod f32`). `@...` match arms are considered private. /// /// When using the pre-built [SI][si] system included with `uom` this macro allows for new units to /// quickly be defined without requiring a release. [Pull requests][pr] to add new units upstream /// area always greatly appreciated. /// /// * `$system`: Path to the module where the [`system!`](macro.system.html) macro was run (e.g. /// `uom::si`). /// * `quantity`: Path to the module where the [`quantity!`](macro.quantity.html) macro was run /// (e.g. `uom::si::length`). /// * `$unit`: Unit name (e.g. `meter`, `foot`). /// * `$conversion`: Conversion (coefficient and constant factor) from the unit to the base unit of /// the quantity (e.g. `3.048_E-1` to convert `foot` to `meter`. `1.0_E0, 273.15_E0` to convert /// `celsius` to `kelvin`.). The coefficient is required and the constant factor is optional. /// Note that using a unit with a non-zero constant factor is not currently supported as a base /// unit. /// * `$abbreviation`: Unit abbreviation (e.g. `"m"`). /// * `$singular`: Singular unit description (e.g. `"meter"`). /// * `$plural`: Plural unit description (e.g. `"meters"`). /// /// An example invocation is given below to add kilometers to length in a meter-kilogram-second /// system. The `#[macro_use]` attribute must be used when including the `uom` crate to make the /// `unit!` macro available. /// /// ``` /// #[macro_use] /// extern crate uom; /// /// # fn main() { } /// # mod mks { /// # #[macro_use] /// # mod length { /// # quantity! { /// # /// Length (base unit meter, m). /// # quantity: Length; "length"; /// # /// Length dimension, m. /// # dimension: Q; /// # units { /// # @meter: 1.0E0; "m", "meter", "meters"; /// # @foot: 3.048E-1; "ft", "foot", "feet"; /// # } /// # } /// # } /// # #[macro_use] /// # mod mass { /// # quantity! { /// # /// Mass (base unit kilogram, kg). /// # quantity: Mass; "mass"; /// # /// Mass dimension, kg. /// # dimension: Q; /// # units { /// # @kilogram: 1.0; "kg", "kilogram", "kilograms"; /// # } /// # } /// # } /// # #[macro_use] /// # mod time { /// # quantity! { /// # /// Time (base unit second, s). /// # quantity: Time; "time"; /// # /// Time dimension, s. /// # dimension: Q; /// # units { /// # @second: 1.0; "s", "second", "seconds"; /// # } /// # } /// # } /// # system! { /// # /// System of quantities, Q. /// # quantities: Q { /// # length: meter, L; /// # mass: kilogram, M; /// # time: second, T; /// # } /// # /// System of units, U. /// # units: U { /// # mod length::Length, /// # mod mass::Mass, /// # mod time::Time, /// # } /// # } /// # mod f32 { /// # Q!(crate::mks, f32/*, (centimeter, gram, second)*/); /// # } /// # mod unit { /// unit! { /// system: crate::mks; /// quantity: crate::mks::length; /// /// @kilometer: 1.0E-03; "km", "kilometer", "kilometers"; /// } /// # } /// # } /// ``` /// /// [si]: https://jcgm.bipm.org/vim/en/1.16.html /// [measurement]: https://jcgm.bipm.org/vim/en/1.9.html /// [pr]: https://github.com/iliekturtles/uom/pulls #[macro_export] macro_rules! unit { ( system: $system:path; quantity: $quantity:path; $($(#[$unit_attr:meta])* @$unit:ident: $($conversion:expr),+; $abbreviation:expr, $singular:expr, $plural:expr;)+ ) => { use $system as __system; use $quantity as __quantity; use __quantity::{Conversion, Unit}; unit!(@units $($(#[$unit_attr])* @$unit: $($conversion),+; $abbreviation, $singular, $plural;)+); }; ( @units $($(#[$unit_attr:meta])* @$unit:ident: $($conversion:expr),+; $abbreviation:expr, $singular:expr, $plural:expr;)+ ) => { $(unit!(@unit $(#[$unit_attr])* @$unit $plural); impl __system::Unit for $unit { #[inline(always)] fn abbreviation() -> &'static str { $abbreviation } #[inline(always)] fn singular() -> &'static str { $singular } #[inline(always)] fn plural() -> &'static str { $plural } } impl Unit for $unit {})+ storage_types! { types: Float; $(impl $crate::Conversion for super::$unit { type T = V; #[inline(always)] #[allow(clippy::inconsistent_digit_grouping)] fn coefficient() -> Self::T { unit!(@coefficient $($conversion),+) } #[inline(always)] #[allow(unused_variables)] #[allow(clippy::inconsistent_digit_grouping)] fn constant(op: $crate::ConstantOp) -> Self::T { unit!(@constant op $($conversion),+) } } impl super::Conversion for super::$unit {})+ } storage_types! { types: PrimInt, BigInt; pub type T = $crate::num::rational::Ratio; #[inline(always)] fn from_f64(value: f64) -> T { ::from_f64(value).unwrap() } $(impl $crate::Conversion for super::$unit { type T = T; #[inline(always)] fn coefficient() -> Self::T { from_f64(unit!(@coefficient $($conversion),+)) } #[inline(always)] #[allow(unused_variables)] fn constant(op: $crate::ConstantOp) -> Self::T { from_f64(unit!(@constant op $($conversion),+)) } } impl super::Conversion for super::$unit {})+ } storage_types! { types: BigUint; pub type T = $crate::num::rational::Ratio; #[inline(always)] fn from_f64(value: f64) -> T { use $crate::num::FromPrimitive; let c = $crate::num::rational::Ratio::<$crate::num::BigInt>::from_f64(value) .unwrap(); T::new(c.numer().to_biguint().unwrap(), c.denom().to_biguint().unwrap()) } $(impl $crate::Conversion for super::$unit { type T = T; #[inline(always)] fn coefficient() -> Self::T { from_f64(unit!(@coefficient $($conversion),+)) } #[inline(always)] #[allow(unused_variables)] fn constant(op: $crate::ConstantOp) -> Self::T { from_f64(unit!(@constant op $($conversion),+)) } } impl super::Conversion for super::$unit {})+ } storage_types! { types: Ratio; #[inline(always)] fn from_f64(value: f64) -> V { ::from_f64(value).unwrap() } $(impl $crate::Conversion for super::$unit { type T = V; #[inline(always)] fn coefficient() -> Self::T { from_f64(unit!(@coefficient $($conversion),+)) } #[inline(always)] #[allow(unused_variables)] fn constant(op: $crate::ConstantOp) -> Self::T { from_f64(unit!(@constant op $($conversion),+)) } } impl super::Conversion for super::$unit {})+ } storage_types! { types: Complex; $(impl $crate::Conversion for super::$unit { type T = VV; #[inline(always)] #[allow(clippy::inconsistent_digit_grouping)] fn coefficient() -> Self::T { unit!(@coefficient $($conversion),+) } #[inline(always)] #[allow(unused_variables)] #[allow(clippy::inconsistent_digit_grouping)] fn constant(op: $crate::ConstantOp) -> Self::T { unit!(@constant op $($conversion),+) } } impl super::Conversion for super::$unit {})+ } }; (@unit $(#[$unit_attr:meta])+ @$unit:ident $plural:expr) => { $(#[$unit_attr])* #[allow(non_camel_case_types)] #[derive(Clone, Copy, Debug, Hash)] pub struct $unit; }; (@unit @$unit:ident $plural:expr) => { #[doc = $plural] #[allow(non_camel_case_types)] #[derive(Clone, Copy, Debug, Hash)] pub struct $unit; }; (@coefficient $factor:expr, $const:expr) => { $factor }; (@coefficient $factor:expr) => { $factor }; (@constant $op:ident $factor:expr, $const:expr) => { $const }; (@constant $op:ident $factor:expr) => { match $op { $crate::ConstantOp::Add => -0.0, $crate::ConstantOp::Sub => 0.0, } }; }