From 3de276cbaac44c5af971bf62b8dbd05f755a46f4 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Wed, 25 Oct 2017 07:11:24 -0700 Subject: [PATCH] Make MIS routines handle infinite importance better. Handle it like the limit case: as A approaches infinity, the limit approaches 1.0. Before this, we were getting NaN values. This fixes that. --- src/mis.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/mis.rs b/src/mis.rs index 1a92dd5..609be2b 100644 --- a/src/mis.rs +++ b/src/mis.rs @@ -1,13 +1,21 @@ #![allow(dead_code)] pub fn balance_heuristic(a: f32, b: f32) -> f32 { - let mis_fac = a / (a + b); - a / mis_fac + if a.is_infinite() { + a + } else { + let mis_fac = a / (a + b); + a / mis_fac + } } pub fn power_heuristic(a: f32, b: f32) -> f32 { - let a2 = a * a; - let b2 = b * b; - let mis_fac = a2 / (a2 + b2); - a / mis_fac + if a.is_infinite() { + a + } else { + let a2 = a * a; + let b2 = b * b; + let mis_fac = a2 / (a2 + b2); + a / mis_fac + } }