2

i have a float value that is hundreds of digits long (like the first 100 digits of pi - 3) and need a way to operate on it. is there any way to store and operate on the float that has a large number of decimals and maintain much precision with built in libraries? is there anything like python's Decimal module in c++?

cspotrun
  • 21
  • 1
  • 2

3 Answers3

4

The other answers all point to high precision integer libraries. There are however a few floating point libraries around:

... and don't forget the possibility that you can always implement your own solution. (Might not be the most effective or fastest solution, but it's "the" solution if you want to learn something.

2

No built-in library, but you can do that using Bignum arithmetics :) http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic.

What a Bignum is: an array (vector) of digits. You can easily implement sum/difference....

I've actually asked something simillar here: STL big int class implementation

Community
  • 1
  • 1
XCS
  • 27,244
  • 26
  • 101
  • 151
1

Unless it is some extra exotic platform, where a float is 100+ bytes long, you will find it hard to archive what you want without a library for big numbers.

BЈовић
  • 62,405
  • 41
  • 173
  • 273