Changes between Version 10 and Version 11 of ReplacingGMPNotes/TheCurrentGMPImplementation


Ignore:
Timestamp:
Jan 8, 2007 12:53:25 AM (7 years ago)
Author:
p_tanski
Comment:

Added concluding comment for encodeFloat/Double; correct typo.

Legend:

Unmodified
Added
Removed
Modified
  • ReplacingGMPNotes/TheCurrentGMPImplementation

    v10 v11  
    6565 * there is no specification of rounding mode--this operation relies on whatever hardware rounding may take effect; and, 
    6666 * certain floating point hardware exceptions (traps) for overflow or underflow may be triggered (though this is not generally the case; note: on x86 machines floating point exceptions may not be triggered but the resulting float may denormalized). 
    67 Nowhere in this function is there a check for whether the GMP number (the `const mp_limb_t *arr`) may be greater than the size of a double and either warn the user (possibly with an `ArithException` or round the resulting double toward zero.   
     67Nowhere in this function is there a check for whether the GMP number (the `const mp_limb_t *arr`) may be greater than the size of a double and either warn the user, possibly with an `ArithException`, or round the resulting double toward zero.   
    6868 
    6969Compare the problem section in `__encodeDouble` to the exponent check in the internal GMP function, `mpn_get_d`, that avoids overflow by comparing the relative magnitude of the GMP number with the maximum magnitude of the double: 
     
    9696This is not the case with the safer `fromRat` function which ensures the Integer falls in the range of the mantissa (see the source code). 
    9797 
     98The problem with `__encodeFloat` and `__encodeDouble` is normative--a matter of design.  The current implementation places the responsibility for ensuring that large integers converted to floating point numbers do not overflow or underflow and it is practically impossible (with rounding) to join encoding and decoding and come out with a reasonably equivalent result, as in: 
     99{{{ 
     100#!html 
     101<pre><font color=Orange>encodeFloat</font> <font color=Blue>.</font> <font color=Orange>decodeFloat</font></pre> 
     102}}} 
     103(Note: this is a standard problem with floating point.  A replacement library could probably do little better.) 
     104 
    98105A replacement library for GMP might use the GMP strategies of including a special bitwise conversion (with appropriate masks) and a hardware-based version.  An unconventional solution might perform the rounding manually (but with relatively portable predictability) using interval arithmetic.   
    99106