Exact division and mpf

Torbjorn Granlund tege at swox.com
Mon Nov 21 13:41:21 CET 2005


Paul.Zimmermann at loria.fr (Paul Zimmermann) writes:

     From: "Elias P. TSIGARIDAS" <et at di.uoa.gr>
  
     Can anyone tell me if I can assume exact division for mpf_class?
  
     For example can I assume that
     mpf_class( 6) / mpf_class( 3)
     will return mpf_class( 2) ?
  
  I don't know for mpf, but mpfr guarantees correct rounding, which implies
  that if a division is exact, you get the exact quotient. See mpfr.org for
  further details.
  
Let me add that it also requires that that exact quotient fits
into the declared mantissa precision.  When dividing 6 by 3, you
will always get 2, but dividing 6000000000 by 3 needs 31 bits,
which will not be the case if the quotient variable was
initialized using mpfr_init2(q,30);

(Under similar conditions, also mpf does what you want.)

-- 
Torbjörn


More information about the gmp-discuss mailing list