Re: converting long string to number

2010-03-28 Thread feka
Really embarrassing in two ways: - Could not remove my previous post. :-) - I should have tried to create such a big number (at least after reading all the answers here) before posting... It is possible to crate a 5 digit big integer. PS: Watch out though. The aim of the problem is to add up t

Re: converting long string to number

2010-03-28 Thread feka
Looks like you are doing the 13th Project Euler problem. That means you have exactly one hundred 50 digit numbers. I am new to Clojure but AFAIK you wont be able to handle a 5000 digit number in it. You have to find another way. There is at least one... ;-) --Feka On Mar 25, 11:40 pm, Glen Rubin

Re: converting long string to number

2010-03-26 Thread Miki
> You want (java.math.BigInteger. "2342343..."). java.lang.Integer is > limited to 2^31-1. Clojure has a "bigint" function, so (bigint (apply str (re-seq #"[0-9]+" big-num-str))) will work as well. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To

Re: converting long string to number

2010-03-25 Thread Richard Newman
In those hills yonder in the lands of Common Lisp, it's usually considered good practice to blast the entire read table save for what you need when you deal with untrusted data. Barring that, a better option might be a more modular reader: read-number, read-symbol, etc. Clojure doesn't have a us

Re: converting long string to number

2010-03-25 Thread Per Vognsen
In those hills yonder in the lands of Common Lisp, it's usually considered good practice to blast the entire read table save for what you need when you deal with untrusted data. Barring that, a better option might be a more modular reader: read-number, read-symbol, etc. -Per On Fri, Mar 26, 2010

Re: converting long string to number

2010-03-25 Thread Mark Engelberg
Another unadvertised function that is useful to be aware of is clojure.lang.Numbers/reduce which will simplify a number to its most simple type. I often find that I want to use some BigInteger function, but then it is important to turn it back into a "typical Clojure number" at the end. For examp

Re: converting long string to number

2010-03-25 Thread Richard Newman
Of course, it might also pose a bit of a security threat: user> (read-string "#=(println \"I OWN YOU NOW!\")") I OWN YOU NOW! nil :) user=> (binding [*read-eval* false] (read-string "#=(println \"I OWN YOU NOW!\")")) java.lang.RuntimeException: java.lang.Exception: EvalReader not allowed w

Re: converting long string to number

2010-03-25 Thread Per Vognsen
Though it might not be the best option here, the Clojure reader is always ready to serve: user> (type (read-string "123")) java.lang.Integer user> (type (read-string "123123123123123")) java.lang.Long user> (type (read-string "123123123123123123123123123123123123")) java.math.BigInteger Of course

Re: converting long string to number

2010-03-25 Thread Chas Emerick
Glen, You want (java.math.BigInteger. "2342343..."). java.lang.Integer is limited to 2^31-1. - Chas On Mar 25, 2010, at 6:40 PM, Glen Rubin wrote: I am trying to convert a long string of numbers to a number, but get a java.lang.numberformatexception My long string of numbers has new lin

converting long string to number

2010-03-25 Thread Glen Rubin
I am trying to convert a long string of numbers to a number, but get a java.lang.numberformatexception My long string of numbers has new line characters in it, so I am filtering out the newline characters before converting it back to a string. Then I try to use Integer. on it but get the above e