Function rust_examples::typing::cmp_f64[][src]

pub fn cmp_f64(a: f64, b: f64) -> Ordering
Expand description

Naive positive f64 comparison function.

This implementation first checks both arguments whether they are positive and panics otherwise. After this check it is safe to call f64::to_int_unchecked and do the comparison on u32s;

Pros

  1. Clients don’t have to check for anything on the call side
  2. This call plays nicely with other APIs

Cons

  1. Call to this function might crash the program! Also clients must somehow know this (e.g. read the docs)
  2. Each call adds a branching instruction which might get significant when called frequently
  3. Typical protection against #1 will be adding the same check and thus duplicating the code