Version: dev

exact_scale

Stable type · Units

Tier: stable · Kind: type · Topic: Units

JuliaTypeScriptPythonRustGo
not exportednot exportednot exportedExactScaleExactScale

Julia

Julia does not export this type.

TypeScript

TypeScript does not export this type.

Python

Python does not export this type.

Rust

pub struct ExactScale {
    /* private fields */
}

impl ExactScale { pub fn one() -> Self }

impl ExactScale { pub fn integer(n: u64) -> Self }

impl ExactScale { pub fn ratio(num: u64, den: u64) -> Self }

impl ExactScale { pub fn power_of_ten(k: i32) -> Self }

impl ExactScale { pub fn pi() -> Self }

impl ExactScale { pub fn decimal(s: &str) -> Self }

impl ExactScale { pub fn multiply(&self, other: &Self) -> Self }

impl ExactScale { pub fn divide(&self, other: &Self) -> Self }

impl ExactScale { pub fn power(&self, exponent: Rational) -> Self }

impl ExactScale { pub fn is_one(&self) -> bool }

impl ExactScale { pub fn to_f64(&self) -> f64 }

impl ExactScale { pub fn ratio_string(&self) -> Option<String> }

The EXACT scale of a unit relative to SI (esm-spec §4.8.1 “Scales are EXACT”).

Stored as a product of prime powers and a power of π, each with a rational exponent: mi is 2⁴·3²·5⁻³·11·127. Multiplying units adds exponents, dividing subtracts them and a rational power multiplies them, so a composite unit’s scale never rounds and sqrt(km) stays exact. Equality is exact, which is what lets a checker decide m + km or m/s = mi/h without a floating-point tolerance. The floating-point Unit::scale is kept for NUMERIC conversion only.

Source · Rust docs

Go

type ExactScale struct {
	// contains filtered or unexported fields
}

func (e ExactScale) Div(o ExactScale) ExactScale

func (e ExactScale) Equal(o ExactScale) bool

func (e ExactScale) Float() float64

func (e ExactScale) IsOne() bool

func (e ExactScale) Mul(o ExactScale) ExactScale

func (e ExactScale) Pow(r Rat) ExactScale

func (e ExactScale) RatioString() (string, bool)

func (e ExactScale) String() string

ExactScale is the EXACT scale of a unit relative to SI (esm-spec §4.8.1 “Scales are EXACT”): a product of prime powers and a power of pi, each with a rational exponent, so mi is 2^4 * 3^2 * 5^-3 * 11 * 127. Multiplying units adds exponents, dividing subtracts them and a rational power multiplies them, so a composite unit’s scale never rounds. The zero value is exactly 1. Every scale AGREEMENT (m + km, m/s = mi/h) is decided with Equal; the float Scale on Unit is kept for numeric conversion only.

Methods

func (e ExactScale) Div(o ExactScale) ExactScale

Div is the exact scale of a quotient of units.

func (e ExactScale) Equal(o ExactScale) bool

Equal reports whether two exact scales are the same number.

func (e ExactScale) Float() float64

Float is the nearest float64, for diagnostics and numeric conversion. Two scales are never compared through it.

func (e ExactScale) IsOne() bool

IsOne reports whether the scale is exactly 1.

func (e ExactScale) Mul(o ExactScale) ExactScale

Mul is the exact scale of a product of units.

func (e ExactScale) Pow(r Rat) ExactScale

Pow is the exact scale of a unit raised to a rational power.

func (e ExactScale) RatioString() (string, bool)

RatioString renders the scale as “p/q”, “p/q*pi” or “p/q*pi^k” in lowest terms ("/q" omitted when it is 1) – the spelling tests/conformance/unit_registry pins. ok is false when an exponent is not whole (sqrt(km)).

func (e ExactScale) String() string

String renders the scale for a diagnostic.

Source · Go docs