Commit Graph

59 Commits

Author SHA1 Message Date
Stefan Krah 40e700ad04
bpo-40878: xlc cannot handle C99 extern inline. (GH-21887)
This applies to the default "extc99" mode.  Python does not compile with "stdc99".
2020-08-15 16:06:21 +02:00
Stefan Krah 9b9f158275
bpo-41369 Update to libmpdec-2.5.1: new features (GH-21593) 2020-07-22 21:54:42 +02:00
Stefan Krah 087d612efe
bpo-40874: Update to libmpdec-2.5.0 (GH-20652) 2020-06-05 19:43:01 +02:00
Stefan Krah 90930e6545
bpo-39576: Prevent memory error for overly optimistic precisions (GH-18581) 2020-02-21 01:52:47 +01:00
Serhiy Storchaka bfe4fd5f2e
Fix some warnings produced by different compilers. (#5593) 2018-02-09 17:31:26 +02:00
Stefan Krah 8e1da5823b Issue #26846: Workaround for non-standard stdlib.h on Android. 2016-04-25 22:48:42 +02:00
Zachary Ware fda673d59f Issue #24974: Force fp-model precice in mpdecimal.c on Windows
As suggested by Steve Dower and approved by Stefan Krah.
2015-09-03 11:52:15 -05:00
Stefan Krah 1f1ec12db9 Issue #19986: Avoid an incorrect warning of older gcc versions. 2013-12-15 20:45:08 +01:00
Stefan Krah da12adac10 Do not discard const qualifier without a reason. 2013-12-12 18:51:51 +01:00
Stefan Krah ecff6554d3 Update copyright. The four year increment is intentional (to save work). 2013-12-08 19:54:05 +01:00
Stefan Krah 4b7f7acf30 Make a couple of parameters constant. 2013-12-03 14:33:46 +01:00
Stefan Krah 45059eb1d0 1) Prepare libmpdec for the 2.4.0 release. None of the following changes affects
_decimal:

      o Make all "mpd_t to C integer" conversion functions available in both the
        64-bit and the 32-bit versions.

      o Make all mixed mpd_t/C integer arithmetic functions available in the
        32-bit version.

      o Better handling of __STDC_LIMIT_MACROS for C++ users.

      o Add struct tags (at the request of C++ users).

2) Check for libmpdec.so.2 if --with-system-libmpdec is used.
2013-11-24 19:44:57 +01:00
Ezio Melotti 3f5db3940f Fix a few typos and a double semicolon. Patch by Eitan Adler. 2013-01-27 06:20:14 +02:00
Stefan Krah 752bfb71d8 Remove trailing whitespace. 2013-01-16 15:16:10 +01:00
Stefan Krah fb7f580e81 Issue #16745: Hide a couple of symbols by making them local. 2012-12-21 23:11:05 +01:00
Stefan Krah f817a7b178 Use C-style comments. 2012-09-23 15:46:09 +02:00
Stefan Krah f21587e3a8 mpd_qpowmod(): calculate result with zero-exponent for compatibility with
decimal.py. The hack to remove the ideal exponent is no longer required.
2012-08-23 15:05:29 +02:00
Stefan Krah 2fd502f6a1 1) Use _mpd_basedivmod() regardless of the length of the dividend. This is
required for a corner case in dec_hash() in the following commit and also
   usually faster. dec_hash() needs some extra precision above MPD_MAX_PREC,
   and _mpd_base_ndivmod() is not audited for that.

2) Use _mpd_basemul() if the length of the smaller operand is less than
   or equal to 256. While this is technically an optimization, it is
   required for *testing* corner cases in dec_hash() in reasonable time.
2012-08-22 18:54:37 +02:00
Stefan Krah 26a1c7a905 Fix Visual Studio warning. 2012-07-20 12:34:18 +02:00
Stefan Krah e574402bd6 Issue #7652: Clean up _mpd_qinvroot() and mark it LIBMPDEC_ONLY. Use the
algorithm from decimal.py for mpd_qsqrt().
2012-07-12 21:17:59 +02:00
Stefan Krah 5431e30853 After 79d2eb29c755 it is no longer necessary to zero the output array:
None of the _mpd_shortadd() or _mpd_shortmul() functions read uninitialized
values. Previously zeroing was required since _mpd_real_size() was called
on the output array.
2012-06-30 21:57:49 +02:00
Stefan Krah c35a8e5c98 Proactive reliability fix for broken FPUs: The base conversion functions
use log10() to calculate the size of the output array. The current code
has been tested on x86/amd64 (and to a lesser extent on qemu-mips qemu-sparc)
and produces sufficiently large values for all inputs tested so far (coefficient
sizes of 10**18 - 1 are hard to test exhaustively).

The new code does not rely on the correctness of log10() and resizes
the output arrays if the allocated space is insufficient.
2012-06-30 18:05:33 +02:00
Stefan Krah 3077ab8237 Whitespace. 2012-06-23 00:31:04 +02:00
Stefan Krah 50b0a365ba Fix comment. 2012-06-20 23:38:51 +02:00
Stefan Krah 22385011ed Many cleanups of redundant code in mpd_qrem_near():
1) _mpd_qdivmod() uses the context precision only in two places, and
     the new code should be exactly equivalent to the previous code.

  2) Remove misleading comment.

  3) The quotient *is* an integer with exponent 0, so calling mpd_qtrunc()
     is pointless.

  4) Replace two instances of identical code by a single one.

  5) Use _mpd_cmp_abs() instead of mpd_cmp_total_mag(): the operands
     are not special.

  6) Don't clear MPD_Rounded in the status (with the current code it should
     not be set within the function).
2012-06-20 23:34:58 +02:00
Stefan Krah 9c1feb88f3 Add comments to the power functions, in particular to _mpd_qpow_real(). 2012-06-18 19:57:23 +02:00
Stefan Krah c62bd13cb2 1) State the relative errors of the power functions for integer exponents.
2) _mpd_qpow_mpd(): Abort the loop for all specials, not only infinity.

3) _mpd_qpow_mpd(): Make the function more general and distinguish between
   zero clamping and folding down the exponent. The latter case is currently
   handled by setting context->clamp to 0 before calling the function.

4) _mpd_qpow_int(): Add one to the work precision in case of a negative
   exponent. This is to get the same relative error (0.1 * 10**-prec)
   for both positive and negative exponents. The previous relative
   error for negative exponents was (0.2 * 10**-prec).

   Both errors are _before_ the final rounding to the context precision.
2012-06-16 19:45:35 +02:00
Stefan Krah b7832939c7 1) Fix signature of _mpd_qpow_uint(): contrary to the comment base is constant.
2) Abort the loop for all specials, not only infinity.

3) Make the function more general and distinguish between zero clamping
   and folding down the exponent. The latter case is currently handled
   by setting context->clamp to 0 before calling the function.
2012-06-12 21:06:06 +02:00
Stefan Krah 88e19779ad 1) Replace long-winded abort() construct by assert().
2) Remove micro optimization (inline checking for NaN before calling
   mpd_qcheck_nans()) that probably has no benefit in this case.
2012-06-11 08:57:17 +02:00
Stefan Krah 9253862f45 1) State restrictions for the transform length.
2) Switch argument order to match the function signature of mpd_calloc()
   (cosmetic change, since the order is irrelevant).
2012-06-10 16:50:55 +02:00
Stefan Krah afc0c77b42 Add one extra comparison to the _mpd_shortmul() case to avoid repetitive code. 2012-06-09 15:28:36 +02:00
Stefan Krah 5248a2d3c1 Enumerate all cases in the overflow detection strategy in mpd_qlog10(). 2012-06-09 00:01:28 +02:00
Stefan Krah 1cf6dfc8b2 1) List relative error for _mpd_qln10().
2) Add rigorous error analysis to _mpd_qlog10 (ACL2 proofs exist).

3) Use the relative error as a basis for the interval generation in the
   correction loop (same as in _mpd_qln()).
2012-06-08 18:41:33 +02:00
Stefan Krah 7bda265662 1) The overflow detection in mpd_qln() has a surprising number of case splits.
List all of them in the comment.

2) Use the recently stated relative error of _mpd_qln() to generate the
   interval for the exact value of ln(x). See also the comment in mpd_qexp().
2012-06-07 17:48:47 +02:00
Stefan Krah a3394bce33 1) Add error analysis comments to mpd_qln10() and _mpd_qln().
2) Simplify the precision adjustment code for values in [0.900, 1.15].
2012-06-06 15:57:18 +02:00
Stefan Krah 67ee1d05dd word.digits are always initialized before use in the Taylor series loop,
but this is more readable.
2012-06-01 10:58:16 +02:00
Stefan Krah 0271766c88 Use workctx instead of ctx for cosmetic reasons. Also zero-pad the result
in the simple path (not correctly rounded but faster).
2012-05-31 20:49:24 +02:00
Stefan Krah 4d3e0a695a Improve Underflow handling in the correct-rounding loop. The case for
Underflow to zero hasn't changed: _mpd_qexp() internally uses MIN_EMIN,
so the result would also underflow to zero for all emin > MIN_EMIN.

In case digits are left, the informal argument is as follows: Underflow can
occur only once in the last multiplication of the power stage (in the Horner
stage Underflow provably cannot occur, and if Underflow occurred twice in
the power stage, the result would underflow to zero on the second occasion).

Since there is no double rounding during Underflow, the effective work
precision is now 1 <= result->digits < prec. It can be shown by a somewhat
tedious argument that abs(result - e**x) < ulp(result, result->digits).

Therefore the correct rounding loop now uses ulp(result, result->digits)
to generate the bounds for e**x in case of Underflow.
2012-05-31 20:01:05 +02:00
Stefan Krah 9a5beece1b Improve comments. 2012-05-31 16:21:34 +02:00
Stefan Krah 5ddbcfc53e Pad the result with zeros just before the final rounding. 2012-05-31 16:00:21 +02:00
Stefan Krah 30c35e8154 Do not clobber existing flags. 2012-05-31 15:09:27 +02:00
Stefan Krah e34a209584 Fix Visual Studio warning. 2012-05-16 20:20:03 +02:00
Stefan Krah 696d10f1bb Changes in _mpd_qexp():
-----------------------

  1) Reduce the number of iterations in the Horner scheme for operands with
     a negative adjusted exponent. Previously the number was overestimated
     quite generously.

  2) The function _mpd_get_exp_iterations() now has an ACL2 proof and
     is rewritten accordingly.

  3) The proof relies on abs(op) > 9 * 10**(-prec-1), so operands without
     that property are now handled by the new function _mpd_qexp_check_one().

  4) The error analysis for the evaluation of the truncated Taylor series
     in Hull&Abrham's paper relies on the fact that the reduced operand
     'r' has fewer than context.prec digits.

     Since the operands may have more than context.prec digits, a new ACL2
     proof covers the case that r.digits > context.prec. To facilitate the
     proof, the Horner step now uses fma instead of rounding twice in
     multiply/add.


Changes in mpd_qexp():
----------------------

  1) Fix a bound in the correct rounding loop that was too optimistic. In
     practice results were always correctly rounded, because it is unlikely
     that the error in _mpd_qexp() ever reaches the theoretical maximum.
2012-05-16 20:10:21 +02:00
Stefan Krah 9d3a5aeabe Defensive programming: mpd_isspecial(r) already implies mpd_isspecial(q), but
this is more readable.
2012-04-20 21:00:31 +02:00
Stefan Krah 3c23a87e58 The divmod function for large numbers now has an ACL2 proof. Related changes:
1) Rename _mpd_qbarrett_divmod into _mpd_base_ndivmod: The function is
     only marginally related to either Barrett's algorithm or to the version
     in Hasselstrom's paper.

  2) In places where the proof assumes exact operations, use new versions of
     add/sub/multiply that set NaN/Invalid_operation if this condition is
     not met. According to the proof this cannot happen, so this should be
     regarded as an extra safety net.

  3) Raise Division_impossible for operands with a number of digits greater
     than MPD_MAX_PREC. This facilitates the audit of the function and can
     practically only occur in the 32-bit version under conditions where
     a MemoryError is already imminent.

  4) Use _mpd_qmul() in places where the result can exceed MPD_MAX_PREC in
     a well defined manner.

  5) Test for mpd_isspecial(qq) in a place where the addition of one
     can theoretically trigger a Malloc_error.

  6) Remove redundant code in _mpd_qdivmod().

  7) Add many comments.
2012-04-20 19:59:20 +02:00
Stefan Krah c51b7fd65b 1) Simplify comment -- one has to read the complete proof (available in ACL2)
in order to understand the algorithm anyway.

2) v->exp == -v->digits may be assumed.

3) Fix comment (v always shares data with a).
2012-04-18 19:27:32 +02:00
Stefan Krah 5d0d2e2b04 Explain the strategy to avoid huge alignment shifts in _mpd_qadd() in detail. 2012-04-18 18:59:56 +02:00
Stefan Krah ed4b21ff4f Cosmetic change: initialize digits to 1 (redundant). 2012-04-18 18:45:22 +02:00
Stefan Krah bc771e9b19 Remove redundant finalization of the result. 2012-04-18 18:25:37 +02:00
Stefan Krah aecaf0b663 Fix comments and whitespace. 2012-04-18 18:08:20 +02:00