Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new SI prefixes #49

Merged
merged 4 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Added the new SI unit prefixes `QUECTO`, `RONTO`, `RONNA`, and `QUETTA`. [#49](https://github.com/itt-ustutt/quantity/pull/49)

## [0.5.1] - 2022-06-08
### Added
Expand Down
2 changes: 2 additions & 0 deletions si-units/docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ All units can be combined with the following prefixes:
.. autoclass:: ATTO, :math:`\text{a}`, :math:`10^{-18}`, .. autoclass:: EXA, :math:`\text{E}`, :math:`10^{18}`
.. autoclass:: ZEPTO, :math:`\text{z}`, :math:`10^{-21}`, .. autoclass:: ZETTA, :math:`\text{Z}`, :math:`10^{21}`
.. autoclass:: YOCTO, :math:`\text{y}`, :math:`10^{-24}`, .. autoclass:: YOTTA, :math:`\text{Y}`, :math:`10^{24}`
.. autoclass:: RONTO, :math:`\text{r}`, :math:`10^{-27}`, .. autoclass:: RONNA, :math:`\text{R}`, :math:`10^{27}`
.. autoclass:: QUECTO, :math:`\text{q}`, :math:`10^{-30}`, .. autoclass:: QUETTA, :math:`\text{Q}`, :math:`10^{30}`

Datatypes
~~~~~~~~~
Expand Down
4 changes: 4 additions & 0 deletions src/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ pub fn quantity(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add("G", G)?;
m.add("RGAS", RGAS)?;

m.add("QUECTO", crate::si::QUECTO)?;
m.add("RONTO", crate::si::RONTO)?;
m.add("YOCTO", crate::si::YOCTO)?;
m.add("ZEPTO", crate::si::ZEPTO)?;
m.add("ATTO", crate::si::ATTO)?;
Expand All @@ -149,5 +151,7 @@ pub fn quantity(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add("EXA", crate::si::EXA)?;
m.add("ZETTA", crate::si::ZETTA)?;
m.add("YOTTA", crate::si::YOTTA)?;
m.add("RONNA", crate::si::RONNA)?;
m.add("QUETTA", crate::si::QUETTA)?;
Ok(())
}
10 changes: 10 additions & 0 deletions src/si.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
//! [ATTO] | $\text{a}$ | $10^{-18}$ | | [EXA] | $\text{E}$ | $10^{18}$
//! [ZEPTO] | $\text{z}$ | $10^{-21}$ | | [ZETTA] | $\text{Z}$ | $10^{21}$
//! [YOCTO] | $\text{y}$ | $10^{-24}$ | | [YOTTA] | $\text{Y}$ | $10^{24}$
//! [RONTO] | $\text{r}$ | $10^{-27}$ | | [RONNA] | $\text{R}$ | $10^{27}$
//! [QUECTO] | $\text{q}$ | $10^{-30}$ | | [QUETTA] | $\text{Q}$ | $10^{30}$
use super::{Quantity, QuantityError, Unit};
use ang::{Angle, Degrees, Radians};
use ndarray::*;
Expand Down Expand Up @@ -439,6 +441,10 @@ pub const RADIANS: Angle = Radians(1.0);
/// Angle unit degree $\\left(1^\\circ=\frac{\pi}{180}\\,\text{rad}\\approx 0.0174532925\\,\text{rad}\\right)$
pub const DEGREES: Angle = Degrees(1.0);

/// Prefix quecto $\\left(\text{q}=10^{-30}\\right)$
pub const QUECTO: f64 = 1e-30;
/// Prefix ronto $\\left(\text{r}=10^{-27}\\right)$
pub const RONTO: f64 = 1e-27;
/// Prefix yocto $\\left(\text{y}=10^{-24}\\right)$
pub const YOCTO: f64 = 1e-24;
/// Prefix zepto $\\left(\text{z}=10^{-21}\\right)$
Expand Down Expand Up @@ -479,6 +485,10 @@ pub const EXA: f64 = 1e18;
pub const ZETTA: f64 = 1e21;
/// Prefix yotta $\\left(\text{Y}=10^{24}\\right)$
pub const YOTTA: f64 = 1e24;
/// Prefix ronna $\\left(\text{R}=10^{27}\\right)$
pub const RONNA: f64 = 1e27;
/// Prefix quetta $\\left(\text{Q}=10^{30}\\right)$
pub const QUETTA: f64 = 1e30;

/// Additional unit celsius
pub struct CELSIUS;
Expand Down
4 changes: 2 additions & 2 deletions src/si_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ impl SINumber {
if DERIVED_UNITS.contains_key(&self.unit) && !self.is_nan() {
let (unit, _, has_prefix, symbols, exponents) = DERIVED_UNITS.get(&self.unit).unwrap();
let (value, prefix) = get_prefix(self.to_reduced(*unit).unwrap(), *has_prefix);
return format!(
format!(
"{}\\,{}",
float_to_latex(value),
&unit_to_latex(symbols, exponents, Some(prefix))
);
)
} else {
format!("{}\\,{}", float_to_latex(self.value), &self.unit.to_latex())
}
Expand Down