File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
akhilesh pandey
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akhilesh pandey wrote:The '/' (i.e. divide) operand returns the integer quotient.


by the way that('/') is Operator not an operand
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
akhilesh pandey
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you all for replying.
i ahve good news to complete my requirement using BIGINTEGER
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic