bigint

clojure.core

  • (bigint x)
Coerce to BigInt

3 Examples top

  • user=> (bigint 30)
    30
    
    
    ;; Actually do something BigInteger-ish... (http://download.oracle.com/javase/6/docs/api/)
    
    user=> (def x (bigint 97))
    #'user/x
    
    user=> (.isProbablePrime (.toBigInteger x) 100)
    true
    
  • user> (= (bigint 42) (clojure.lang.BigInt/fromBigInteger (BigInteger. "42"))
    true
    user> (= 42N (bigint 42))
    true
    user> (= 42 (bigint 42))
    true
    user> (= 42 (clojure.lang.BigInt/fromBigInteger (BigInteger. "42"))
    true
    
  • user> (reduce * (repeat 20 1000))
    ArithmeticException integer overflow  clojure.lang.Numbers.throwIntOverflow (Numbers.java:1388)
    
    user> (reduce * (repeat 20 (bigint 1000)))
    1000000000000000000000000000000000000000000000000000000000000N
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:3212 top

(defn bigint
  "Coerce to BigInt"
  {:tag clojure.lang.BigInt
   :static true
   :added "1.3"}
  [x] (cond
       (instance? clojure.lang.BigInt x) x
       (instance? BigInteger x) (clojure.lang.BigInt/fromBigInteger x)
       (decimal? x) (bigint (.toBigInteger ^BigDecimal x))
       (ratio? x) (bigint (.bigIntegerValue ^clojure.lang.Ratio x))
       (number? x) (clojure.lang.BigInt/valueOf (long x))
       :else (bigint (BigInteger. x))))
Vars in clojure.core/bigint:
Used in 0 other vars

Comments top

No comments for bigint. Log in to add a comment.