Welcome! Please see the About page for a little more info on how this works.

+1 vote
ago in Syntax and reader by

Consider this:

user> (.pow (bigdec 2) 3)
8M

user> (.pow (bigint 2) 3)
Execution error (IllegalArgumentException) at foo/eval10898 (REPL:1093).
No matching method pow found taking 1 args for class clojure.lang.BigInt

Is that an intentional choice in the language?

Note that this works:

user=> (.pow (biginteger 2) 3)
8
user=> (type (.pow (biginteger 2) 3))
java.math.BigInteger

Except the type is not clojure.lang.BigInt, but java.math.BigInteger, which are different types.

ago by
Not writing it as an answer because I don't have a 100% accurate information, but I believe that `clojure.lang.BigInt` exists not as a replacement for `java.math.BigInteger` but as a way to make operations dealing with numbers that can be either `long` or `BigInteger` faster than if everything were dealing with `BigInteger`. As such, it deals with the necessary minimum, and if a programmer needs more then they can always use `(biginteger a-big-int)` or `(bigdec a-big-int)`.

1 Answer

0 votes
ago by
selected ago by
 
Best answer

Per the reference, the Clojure bigint type is clojure.lang.BigInt, which is like java.math.BigInteger but optimized for ops in the long range. Because there are lots of ways you can end up with java.lang.BigInt, both are supported in lots of places. If you're going after specific interop on the type, you'll need to confine yourself to clojure BigInt or else use biginteger to get to java BigInteger.

ago by
the question is about the specific method `.pow` and whether it is an oversight that it doesn't exist when the method exists on both bigdec and biginteger classes.
ago by
It's not a goal of BigInt to be API compatible with BigInteger.
ago by
i think that answers the question, thanks.
ago by
Yeah, it is a bit odd that `.pow` exists on some numeric types but not on others.

Anyway, I deem my question answered. Thank you all.
ago by
Do us a favor and mark the answer as "Answered" with the checkmark?
...