| 1454 | } |
| 1455 | |
| 1456 | pub fn rounded(&self) -> Option<usize> { |
| 1457 | match self { |
| 1458 | CardinalityEstimate::Estimate(OrderedFloat(f)) => { |
| 1459 | let rounded = f.ceil(); |
| 1460 | |
| 1461 | if !rounded.is_normal() || rounded < 0.0 { |
| 1462 | warn!( |
| 1463 | "ignoring denormalized or negative cardinality estimate {f} rounded to {rounded}" |
| 1464 | ); |
| 1465 | } |
| 1466 | |
| 1467 | // if we can't cast, the value is unknown |
| 1468 | u64::try_cast_from(rounded).map(usize::cast_from) |
| 1469 | } |
| 1470 | CardinalityEstimate::Unknown => None, |
| 1471 | } |
| 1472 | } |
| 1473 | } |
| 1474 | |
| 1475 | impl std::ops::Add for CardinalityEstimate { |