From 63dad14cec936087a2d59074494325b0118cab83 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 27 Dec 2016 07:19:33 -0400 Subject: - Fixed the (encode-frac .0) bug for the compiler's encoder, at lux.base --- luxc/src/lux/base.clj | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'luxc') diff --git a/luxc/src/lux/base.clj b/luxc/src/lux/base.clj index 1cb069021..823144acf 100644 --- a/luxc/src/lux/base.clj +++ b/luxc/src/lux/base.clj @@ -1114,23 +1114,24 @@ (recur (dec index) (assoc output index (rem raw 10)) (int (/ raw 10)))) - output))) - ] + output)))] ;; Based on the LuxRT.encode_frac method (defn encode-frac [input] - (loop [index (dec frac-bits) - output (vec (repeat frac-bits 0))] - (if (>= index 0) - (recur (dec index) - (if (bit-test input index) - (->> (- (dec frac-bits) index) - frac-digit-power - (add-frac-digit-powers output)) - output)) - (-> output frac-digits-to-text - (->> (str ".")) - (.split "0*$") - (aget 0))))) + (if (= 0 input) + ".0" + (loop [index (dec frac-bits) + output (vec (repeat frac-bits 0))] + (if (>= index 0) + (recur (dec index) + (if (bit-test input index) + (->> (- (dec frac-bits) index) + frac-digit-power + (add-frac-digit-powers output)) + output)) + (-> output frac-digits-to-text + (->> (str ".")) + (.split "0*$") + (aget 0)))))) ;; Based on the LuxRT.decode_frac method (defn decode-frac [^String input] -- cgit v1.2.3