我是 Clojure 新手,找不到整数的等效项?在Chez方案8.4中,主要针对以下测试用例:
(integer? 39.0) => #t
到目前为止我提出的功能是:
(defn actual-integer? [x] (or (= 0.0 (- x (int x))) (integer? x)))
当x是任意数字类型时它是否有效或者有更好的解决方案吗?
谢谢。
最佳答案
严格来说,39.0
不是一个整数文字,因为它末尾有 .0
部分。该过程的一个简单实现是:
(defn actual-integer? [x] (== (int x) x))
请注意 ==
operator :
Returns non-nil if nums all have the equivalent value (type-independent), otherwise false
关于clojure - 在 Clojure 中实现整数?计划中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19061255/