Crates.io | natural_unit |
lib.rs | natural_unit |
version | 0.1.4 |
source | src |
created_at | 2019-05-14 11:42:32.360323 |
updated_at | 2020-04-22 16:28:09.841383 |
description | Physical unit conversion program (SI, CGS, Natural, Geometrized) |
homepage | |
repository | https://github.com/Axect/Natural_Unit |
max_upload_size | |
id | 134255 |
size | 11,860 |
Physical unit conversion with Fundamental constants
convert
value using by declared conversion factor structure.Example: CGS -> Geometrized with Solar radius = 1
extern crate natural_unit;
use natural_unit::*;
fn main() {
// Declare mass, length, time conversion factor.
let cgs_to_geom = ConversionFactor::new(
CONSTANT_CGS.G / (CONSTANT_CGS.c.powi(2) * CONSTANT_CGS.r_solar), // Mass conversion factor
1f64 / CONSTANT_CGS.r_solar, // Length conversion factor
CONSTANT_CGS.c / CONSTANT_CGS.r_solar // Time conversion factor
);
// What do you want to convert?
let solar_mass_cgs = CONSTANT_CGS.m_solar; // CGS Solar Mass
// Convert! (`convert(f64, Dimension, ConversionFactor)`)
let new_solar_mass = convert(solar_mass_cgs, Mass, cgs_to_geom); // Converted Solar Mass
// Invert! (`invert(f64, Dimension, ConversionFactor)`)
let inverted_solar_mass = invert(new_solar_mass, Mass, cgs_to_geom); // Inverted Solar Mass
assert_eq!(solar_mass_cgs, inverted_solar_mass);
}