pub fn test_overflow(result: &Float, o: Ordering) -> boolExpand description
Given the (Float, Ordering) result of an operation, determines whether an overflow occurred.
We’re defining an overflow to occur whenever the actual result is outside the representable finite range, and is rounded to either infinity or to the maximum or minimum representable finite value. An overflow can present itself in four ways:
- The result is $\infty$ and the
OrderingisGreater - The result is $-\infty$ and the
OrderingisLess - The result is the largest finite value (of any
Floatwith its precision) and theOrderingisLess - The result is the smallest (most negative) finite value (of any
Floatwith its precision) and theOrderingisGreater
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits().
§Examples
use malachite_base::num::basic::traits::{Infinity, NegativeInfinity, One};
use malachite_float::{test_overflow, Float};
use std::cmp::Ordering::*;
assert!(test_overflow(&Float::INFINITY, Greater));
assert!(test_overflow(&Float::NEGATIVE_INFINITY, Less));
assert!(test_overflow(&Float::max_finite_value_with_prec(10), Less));
assert!(test_overflow(
&-Float::max_finite_value_with_prec(10),
Greater
));
assert!(!test_overflow(&Float::INFINITY, Equal));
assert!(!test_overflow(&Float::ONE, Less));