Skip to content

Instantly share code, notes, and snippets.

@Kimundi
Created February 6, 2013 11:04
Show Gist options
  • Select an option

  • Save Kimundi/4721932 to your computer and use it in GitHub Desktop.

Select an option

Save Kimundi/4721932 to your computer and use it in GitHub Desktop.
trait Integer {}
impl Integer for int {}
trait Float { static fn NaN() -> Self; }
impl Float for float { static fn NaN() -> float { 0./0. } }
trait NumStrHelper {
static fn has_special_values() -> bool;
static fn NaN() -> Option<Self>;
fn is_NaN(&self) -> bool;
// ...
}
impl <T: Integer> NumStrHelper for T {
static fn has_special_values() -> bool { false }
static fn NaN() -> Option<T> { None }
fn is_NaN(&self) -> bool { false }
// ...
}
impl <U: Float Eq> NumStrHelper for U {
static fn has_special_values() -> bool { true }
static fn NaN() -> Option<U> { Some(Float::NaN()) }
fn is_NaN(&self) -> bool { *self != *self }
// ...
}
fn main() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment