aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc/util.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/cljcc/util.clj')
-rw-r--r--src/cljcc/util.clj16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/cljcc/util.clj b/src/cljcc/util.clj
index 6ced120..01eabd4 100644
--- a/src/cljcc/util.clj
+++ b/src/cljcc/util.clj
@@ -87,7 +87,7 @@
_ (-> strip-l-or-L
Long/parseLong
Long/toString)]
- s)
+ s)
(catch Exception _e
false)))
@@ -102,3 +102,17 @@
(exc/lex-error {:line line
:col col})))
+(defn round-away-from-zero [num div]
+ (let [div (abs div)]
+ (cond
+ (= (mod num div) 0) num
+ (< num 0) (- num (- div (mod num div)))
+ :else (+ num (- div (mod num div))))))
+
+(defn in-int-range?
+ "Verifies whether -2^31 <= x <= 2^31."
+ [v]
+ (and (>= v Integer/MIN_VALUE)
+ (<= v Integer/MAX_VALUE)))
+
+(not (in-int-range? Long/MAX_VALUE))