Changes between Version 10 and Version 11 of ReplacingGMPNotes/TheCurrentGMPImplementation
 Timestamp:
 Jan 8, 2007 12:53:25 AM (10 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

ReplacingGMPNotes/TheCurrentGMPImplementation
v10 v11 65 65 * there is no specification of rounding modethis operation relies on whatever hardware rounding may take effect; and, 66 66 * 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.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. 68 68 69 69 Compare 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: … … 96 96 This is not the case with the safer `fromRat` function which ensures the Integer falls in the range of the mantissa (see the source code). 97 97 98 The problem with `__encodeFloat` and `__encodeDouble` is normativea 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 98 105 A replacement library for GMP might use the GMP strategies of including a special bitwise conversion (with appropriate masks) and a hardwarebased version. An unconventional solution might perform the rounding manually (but with relatively portable predictability) using interval arithmetic. 99 106