Git Product home page Git Product logo

natural_unit's Introduction

Natural Unit

On crates.io On docs.rs travis
maintenance

Physical unit conversion with Fundamental constants

Unit System List

  • SI
  • CGS
  • Geometrized(With CGS)
  • Geometrized with unit solar mass
  • Natural Unit(With CGS)
  • Natural Unit(MeV)
  • Natural Unit(Gaussian)

How to use?

  1. Just declare three conversion factors - M, L, T
  2. Get automatically obtained remain conversion factors (momentum, energy and etc.)
  3. 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);
}

natural_unit's People

Contributors

axect avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.