Function rust_examples::typing::cmp_f64 [−][src]
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
- Clients don’t have to check for anything on the call side
- This call plays nicely with other APIs
Cons
- Call to this function might crash the program! Also clients must somehow know this (e.g. read the docs)
- Each call adds a branching instruction which might get significant when called frequently
- Typical protection against #1 will be adding the same check and thus duplicating the code
