aspose file tools*
The moose likes Servlets and the fly likes how to apply arthmetic operation on String containing only large number of digits Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to apply arthmetic operation on String containing only large number of digits" Watch "how to apply arthmetic operation on String containing only large number of digits" New topic
Author

how to apply arthmetic operation on String containing only large number of digits

akhilesh pandey
Greenhorn

Joined: May 02, 2007
Posts: 6
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
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

akhilesh pandey wrote:The '/' (i.e. divide) operand returns the integer quotient.


by the way that('/') is Operator not an operand
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
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.


Ping & DNS - my free Android networking tools app
akhilesh pandey
Greenhorn

Joined: May 02, 2007
Posts: 6
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: 42264
    
  64
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
thank you all for replying.
i ahve good news to complete my requirement using BIGINTEGER
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to apply arthmetic operation on String containing only large number of digits