aboutsummaryrefslogtreecommitdiff
path: root/luxc/src
diff options
context:
space:
mode:
authorEduardo Julian2016-12-27 07:19:33 -0400
committerEduardo Julian2016-12-27 07:19:33 -0400
commit63dad14cec936087a2d59074494325b0118cab83 (patch)
tree6fa4d9ce58095f48f0306262f551f76d65ecddb9 /luxc/src
parentfdc924b023122b09b536a3d372658ecf15277cfb (diff)
- Fixed the (encode-frac .0) bug for the compiler's encoder, at lux.base
Diffstat (limited to '')
-rw-r--r--luxc/src/lux/base.clj31
1 files changed, 16 insertions, 15 deletions
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]