[recipes] Fix up rational approximation



commit 018350ab305730f132da387f58f093c150abebb1
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 5 00:07:34 2017 -0400

    Fix up rational approximation
    
    We need to deal with rounding errors that end up yielding
    409 1/1 g when scaling 200g in a 4 serving recipe to 8.2.

 src/gr-number.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-number.c b/src/gr-number.c
index e9a82af..90f9943 100644
--- a/src/gr-number.c
+++ b/src/gr-number.c
@@ -332,5 +332,11 @@ gr_number_format (double number)
         number -= integral;
 
         rational_approximation (number, &num, &denom);
+
+        if (num == 1 && denom == 1) {
+                integral += 1;
+                num = denom = 0;
+        }
+
         return format_fraction ((int)integral, num, denom);
 }


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