Function nyx_space::io::quantity::parse_quantity [−][src]
pub fn parse_quantity(input: &str) -> Result<Quantity, ParsingError>
Expand description
Parse a distance or velocity
extern crate nyx_space as nyx; use nyx::io::quantity::parse_quantity; use std::f64::EPSILON; assert!((parse_quantity("1.0 km").unwrap().v() - 1.0).abs() < EPSILON); assert!((parse_quantity("-1.3 mm").unwrap().v() - -1.3e-6).abs() < EPSILON); assert!((parse_quantity("3.4e3 m/s").unwrap().v() - 3.4).abs() < EPSILON); assert!((parse_quantity("3.4e0 km/s").unwrap().v() - 3.4).abs() < EPSILON); assert!((parse_quantity("3.4e-3 Mm/s").unwrap().v() - 3.4).abs() < EPSILON); assert!((parse_quantity("7 m").unwrap().v() - 7e-3).abs() < EPSILON); assert!((parse_quantity("-6 km/h").unwrap().v() - -6.0/3_600.0).abs() < EPSILON);