Rustamath MKS

MIT licensed CI

Rustamath MKS is Rust library with support for MKS system of units and values of physical constants in MKS.

List of all constants

Here is an example that demonstrates the basic usage, it can be run with cargo test simple_pendulum -- --nocapture in the source directory.

```rust

[test]

fn simplependulum() { // simple pendulum period formula is T = 2*Pi*sqrt(L/g) let pendulumlen = MksVal::new(6.0, f64::FOOT, FOOTUNIT); let g = MksVal::new(1.0, f64::GRAVACCEL, GRAVACCELUNIT);

println!("Pendulum length is {:.2} {}", pendulum_len.val, pendulum_len.unit);
println!("G on Earth is {:.2} {}", g.val, g.unit);

assert_eq!(pendulum_len.unit.to_string(), "[m]");
assert_eq!(g.unit.to_string(), "[m / s^2]");

let pendulum_len_over_accel = pendulum_len / g;
assert!(pendulum_len_over_accel.unit == TIME_UNIT * TIME_UNIT);

let pi_x_2 = MksVal::new_scalar(2.0 * std::f64::consts::PI);

let period = pi_x_2 * pendulum_len_over_accel.sqrt();
assert!(period.unit == TIME_UNIT);

println!("Pendulum period is {:.2} {}", period.val, period.unit);
assert_eq!(period.unit.to_string(), "[s]");

} ```

And the output is:

console Pendulum length is 1.83 [m] G on Earth is 9.81 [m / s^2] Pendulum period is 2.71 [s]

(Check the result with any online calculator, for example https://www.omnicalculator.com/physics/simple-pendulum)

This crate provides: