Skip to main content

work

Function work 

Source
pub fn work(force: f64, displacement: f64) -> Option<f64>
Expand description

Computes mechanical work from a constant force and displacement.

Formula: W = F * d

Returns None when either input is not finite or when the computed result is not finite. Negative force and displacement values are allowed.

ยงExamples

use use_work::work;

assert_eq!(work(10.0, 2.0), Some(20.0));
assert_eq!(work(-10.0, 2.0), Some(-20.0));
Examples found in repository?
examples/basic_usage.rs (line 6)
5fn main() {
6    assert_eq!(work(10.0, 2.0), Some(20.0));
7    assert_eq!(
8        ConstantForceWork::new(10.0, 2.0).and_then(|constant| constant.work()),
9        Some(20.0)
10    );
11    assert!(matches!(
12        work_at_angle_degrees(10.0, 2.0, 60.0),
13        Some(value) if (value - 10.0).abs() < 1e-12
14    ));
15}