Skip to content

Commit

Permalink
Implement num::Zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
radix committed Dec 23, 2017
1 parent e05dab3 commit d7f38bd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,25 @@ macro_rules! system {
}
}

impl<D, U, V> $crate::num::Zero for Quantity<D, U, V>
where
D: Dimension + ?Sized,
U: Units<V> + ?Sized,
V: $crate::num::Num + $crate::Conversion<V>,
{
fn zero() -> Self {
Quantity {
dimension: $crate::lib::marker::PhantomData,
units: $crate::lib::marker::PhantomData,
value: V::zero(),
}
}

fn is_zero(&self) -> bool {
self.value.is_zero()
}
}

/// Macro to implement [`quantity`](si/struct.Quantity.html) type aliases for a specific
/// [system of units][units] and value storage type.
///
Expand Down
8 changes: 8 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ mod system_macro {

Q!(tests, V);

#[test]
fn zero() {
let z = Length::zero();

Test::assert_eq(z.value, 0.0);
assert!(z.is_zero());
}

quickcheck! {
#[allow(trivial_casts)]
fn from_base(v: A<V>) -> bool
Expand Down

0 comments on commit d7f38bd

Please sign in to comment.