How To calculate/display large float numbers?

Torbjörn Granlund tg at gmplib.org
Sun Nov 27 14:55:03 UTC 2016


Marc Glisse <marc.glisse at inria.fr> writes:

  On Sun, 27 Nov 2016, Torbjörn Granlund wrote:
  
  > (Allowing floating-point input strings would be a conceivable extension
  > here, since any finite string corresponds to a rational number.)
  
  That would be welcome, I had to write quite a few workarounds in CGAL
  because this was missing...

It shouldn't be too hard.

Perhaps this works:

1. Scan the number as an integer in the given base, ignoring the dot
   (ensuring >= 1 dot).  Call this integer a'.

2. Let b' = (base)^n where n is the number of digits after the dot.  If
   there is no dot, assume n = 0 (this can skip the gcd calculation).

3. Compute g = gcd(a',b') and let the result be a/b where a = a'/g and
   b = b'/g.

4. Write proper test code.  :-|

-- 
Torbjörn
Please encrypt, key id 0xC8601622


More information about the gmp-discuss mailing list