This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
how to apply arthmetic operation on String containing only large number of digits
akhilesh pandey
Greenhorn
Joined: May 02, 2007
Posts: 6
posted
0
I am looking to Implement a function that evaluates an expression consisting of following operands : '(', ')', '+', '-', '*', '/'. Each numbers in the expression could be large (as large as being represented by string of 1000 digits). The '/' (i.e. divide) operand returns the integer quotient.
I can not use the Java class BigInteger or other such Class / Library. I am not sure but hope there will be some thing on basic of java which can do this very fast like binary level
If you do not want to use BigInteger (why not?), then you'll have to code the arithmetic yourself, based on the characters contained in the string. That's bound to be slower than using BigInteger, though.
Hi
As i wrote in my first post each numbers in the expression could be large as large as being represented by string of 1000 digits thats why i am not able to use BIGINTEGER of java. for example if i have an expression like
((10000000000000000000000001231234448563465435434723854278423 / 1111111111234623874627)*1111111111234623874627777778888312674534) then how i will manipulate it. in which data type i can store this for arthmetic operation
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
0
The whole expression would be a String, which you would then parse into its constituent pieces. Once you have identified which parts make up the numbers, you can easily build BigInteger objects from them.
This expression parsing code of mine may serve as inspiration: http://www.ulfdittmer.com/code/Expr.html You'd need to replace the use of doubles by BigIntegers, but you can also simplify it a lot, since you're not dealing with functions.
akhilesh pandey
Greenhorn
Joined: May 02, 2007
Posts: 6
posted
0
thank you all for replying.
i ahve good news to complete my requirement using BIGINTEGER
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: how to apply arthmetic operation on String containing only large number of digits