[chronojump] Safer DivideSafeFraction



commit 115d3952cafb5b6b2382de153f3cef1110011256
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Apr 1 06:31:58 2016 +0200

    Safer DivideSafeFraction

 src/util.cs |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
---
diff --git a/src/util.cs b/src/util.cs
index dcd7daf..de3f03f 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1555,11 +1555,16 @@ public class Util
        //thought for being between 0, 1
        //ideal for progressBars
        public static double DivideSafeFraction (double val1, double val2) {
+               if(val1 == 0 || val2 == 0)
+                       return 0;
+
                double result = val1 / val2;
+               
                if(result > 1)
                        result = 1;
                else if(result < 0)
                        result = 0;
+
                return result;
        }
        


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]