Answered by:
How to implement arbitrary precision calculator
Question

Hi all,
I'm trying to implement an arbitrary precision calculator using C (if you know linux, I'm trying to clone dc). Since it is going to be arbitrary precision, I need to store the input and intermediate results in something other than simple doubles. I'm thinking of 2 options:
* strings containing the numbers as it is:for eg. 3.14 will be "3.14". But this will need converting back and forth between string and numeric every time a computation is done.
* a linked list of long's: for eg., 3.14159265358979 might be stored as 3, 1415926, 5358979 with an external variable holding the position of the decimal point.
Is either of these a good choice, or is there a better way (one with a good tradeoff between ease of programming and efficiency) ?Monday, June 11, 2007 7:59 PM
Answers

Arbitrary precision is used in applications where arithmetic performance is not a limiting factor, or where precise results or exact integer arithmetic with very large numbers is required. It is also useful for checking the results of fixedprecision calculations. Hence, for APA, we need to look at the accuracy of the results and not at the efficiency.
As for ur query regarding storage of the value of "pi", rational numbers can be stored as a pair of two integers for the numerator and denominator, in a fixedpoint format with a fixed denominator, or in a floatingpoint format as a significand multiplied by an arbitrary exponent.
For further help, you can have a look at these softwares.
Arbitraryprecision software
Arbitraryprecision arithmetic in most computer software is implemented by calling an external library that provides datatypes and subroutines to store numbers with the requested precision and to perform computations.
 GNU MultiPrecision Library (and MPFR): C bignum libraries
 Java.math: BigInteger and BigDecimal classes for Java
 decNumber: C package for decimal bignums
 Computable Real Numbers: arbitraryprecision library for Common Lisp
 LargeInteger  JScience Library
 Math::BigFloat is an arbitraryprecision module for Perl
 BigDigits is an arbitraryprecision library in C
 Crypto++ includes arbitraryprecision arithmetic in C++
 apfloat arbitraryprecision library for Java and C++
 LGPLlicensed integer bignum source code written in C
 MAPM A Portable Arbitrary Precision Math Library in C. (Also includes bindings for C++ and Lua.)
 LiDIA A C++ Library For Computational Number Theory for C and C++
 NTL NTL: A Library for doing Number Theory for C and C++
 CLN A Class Library for Numbers (arbitrary integers and floating point numbers for C and C++)
Standalone application software that supports arbitrary precision computations:
 PARI/GP, an open source computer algebra system that supports arbitrary precision.
 Mathematica, Maple computer algebra system, and Macsyma: computer algebra software including arbitraryprecision arithmetic
 BCMath: the PHP binary calculator functions
 bc programming language: the POSIX / GNU basic calculator
 dc programming language: the POSIX desk calculator
 The Python programming language: the builtin long integer type is of arbitrary precision. The Decimal builtin module has user definable precision.
 REXX: programming language (including Open Object Rexx and NetRexx)
Tuesday, June 12, 2007 7:10 AM
All replies

Arbitrary precision is used in applications where arithmetic performance is not a limiting factor, or where precise results or exact integer arithmetic with very large numbers is required. It is also useful for checking the results of fixedprecision calculations. Hence, for APA, we need to look at the accuracy of the results and not at the efficiency.
As for ur query regarding storage of the value of "pi", rational numbers can be stored as a pair of two integers for the numerator and denominator, in a fixedpoint format with a fixed denominator, or in a floatingpoint format as a significand multiplied by an arbitrary exponent.
For further help, you can have a look at these softwares.
Arbitraryprecision software
Arbitraryprecision arithmetic in most computer software is implemented by calling an external library that provides datatypes and subroutines to store numbers with the requested precision and to perform computations.
 GNU MultiPrecision Library (and MPFR): C bignum libraries
 Java.math: BigInteger and BigDecimal classes for Java
 decNumber: C package for decimal bignums
 Computable Real Numbers: arbitraryprecision library for Common Lisp
 LargeInteger  JScience Library
 Math::BigFloat is an arbitraryprecision module for Perl
 BigDigits is an arbitraryprecision library in C
 Crypto++ includes arbitraryprecision arithmetic in C++
 apfloat arbitraryprecision library for Java and C++
 LGPLlicensed integer bignum source code written in C
 MAPM A Portable Arbitrary Precision Math Library in C. (Also includes bindings for C++ and Lua.)
 LiDIA A C++ Library For Computational Number Theory for C and C++
 NTL NTL: A Library for doing Number Theory for C and C++
 CLN A Class Library for Numbers (arbitrary integers and floating point numbers for C and C++)
Standalone application software that supports arbitrary precision computations:
 PARI/GP, an open source computer algebra system that supports arbitrary precision.
 Mathematica, Maple computer algebra system, and Macsyma: computer algebra software including arbitraryprecision arithmetic
 BCMath: the PHP binary calculator functions
 bc programming language: the POSIX / GNU basic calculator
 dc programming language: the POSIX desk calculator
 The Python programming language: the builtin long integer type is of arbitrary precision. The Decimal builtin module has user definable precision.
 REXX: programming language (including Open Object Rexx and NetRexx)
Tuesday, June 12, 2007 7:10 AM 
Thank you Arijit. The decNumber and GNU MPL library links were very helpful.. I shall read through them and try to use their algorithms.Tuesday, June 12, 2007 5:53 PM

Really good resources man. Thanks a lot.Thursday, June 14, 2007 2:51 PM

even i'm trying to build calculator but in java.
most of the work is done.
but the operators which i'm considering are +, ,unary  & *.
though this can be expanded.
actually the code which i'm trying to develop is for web application.
the context is very different.
the expression you will get will be a string.
if you want to try, give it a try & can also share it here.
soon, i'll post here my logicSunday, June 24, 2007 5:32 AM