Skip to main content

linear_decay

Function linear_decay 

Source
pub fn linear_decay(
    reward: u64,
    finish: u64,
    from: u64,
    until: u64,
) -> Option<u64>
Expand description

The full reward up to from, falling linearly to zero at until, and None after until. Rounds down. When until is not after from, this is a deadline at from.

use task_allocation::route::rewards::linear_decay;

assert_eq!(linear_decay(100, 10, 10, 110), Some(100));
assert_eq!(linear_decay(100, 60, 10, 110), Some(50));
assert_eq!(linear_decay(100, 110, 10, 110), Some(0));
assert_eq!(linear_decay(100, 111, 10, 110), None);