bpo-40874: Update to libmpdec-2.5.0 (GH-20652)

This commit is contained in:
Stefan Krah 2020-06-05 19:43:01 +02:00 committed by GitHub
parent 3ad52e366f
commit 087d612efe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 503 additions and 297 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,13 +27,13 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include "basearith.h"
#include "constants.h" #include "constants.h"
#include "typearith.h" #include "typearith.h"
#include "basearith.h"
/*********************************************************************/ /*********************************************************************/
@ -337,6 +337,7 @@ _mpd_basedivmod(mpd_uint_t *q, mpd_uint_t *r,
/* D2: loop */ /* D2: loop */
for (j=m; j != MPD_SIZE_MAX; j--) { for (j=m; j != MPD_SIZE_MAX; j--) {
assert(2 <= j+n && j+n <= nplusm); /* annotation for scan-build */
/* D3: calculate qhat and rhat */ /* D3: calculate qhat and rhat */
rhat = _mpd_shortdiv(w2, u+j+n-1, 2, v[n-1]); rhat = _mpd_shortdiv(w2, u+j+n-1, 2, v[n-1]);
@ -652,6 +653,3 @@ _mpd_shortdiv_b(mpd_uint_t *w, const mpd_uint_t *u, mpd_size_t n,
return rem; return rem;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,11 @@
*/ */
#ifndef BASEARITH_H #ifndef LIBMPDEC_BASEARITH_H_
#define BASEARITH_H #define LIBMPDEC_BASEARITH_H_
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
#include "typearith.h" #include "typearith.h"
@ -216,7 +215,4 @@ _mpd_isallnine(const mpd_uint_t *data, mpd_ssize_t len)
MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */
#endif /* BASEARITH_H */ #endif /* LIBMPDEC_BASEARITH_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,11 @@
*/ */
#ifndef BITS_H #ifndef LIBMPDEC_BITS_H_
#define BITS_H #define LIBMPDEC_BITS_H_
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
/* Check if n is a power of 2. */ /* Check if n is a power of 2. */
@ -186,7 +185,4 @@ mpd_bsf(mpd_size_t a)
#endif /* BSR/BSF */ #endif /* BSR/BSF */
#endif /* BITS_H */ #endif /* LIBMPDEC_BITS_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,7 +27,6 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
#include "constants.h" #include "constants.h"
@ -128,5 +127,3 @@ const char *mpd_clamp_string[MPD_CLAMP_GUARD] = {
"CLAMP_DEFAULT", "CLAMP_DEFAULT",
"CLAMP_IEEE_754" "CLAMP_IEEE_754"
}; };

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,14 @@
*/ */
#ifndef CONSTANTS_H #ifndef LIBMPDEC_CONSTANTS_H_
#define CONSTANTS_H #define LIBMPDEC_CONSTANTS_H_
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdint.h>
/* Internal header file: all symbols have local scope in the DSO */ /* Internal header file: all symbols have local scope in the DSO */
MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) MPD_PRAGMA(MPD_HIDE_SYMBOLS_START)
@ -84,7 +86,4 @@ extern const mpd_uint_t UH_P1P2;
MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */
#endif /* CONSTANTS_H */ #endif /* LIBMPDEC_CONSTANTS_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,14 +27,16 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h>
void void
mpd_dflt_traphandler(mpd_context_t *ctx UNUSED) mpd_dflt_traphandler(mpd_context_t *ctx)
{ {
(void)ctx;
raise(SIGFPE); raise(SIGFPE);
} }
@ -282,5 +284,3 @@ mpd_addstatus_raise(mpd_context_t *ctx, uint32_t flags)
mpd_traphandler(ctx); mpd_traphandler(ctx);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,15 +27,14 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
#include "bits.h" #include "bits.h"
#include "constants.h" #include "constants.h"
#include "convolute.h"
#include "fnt.h" #include "fnt.h"
#include "fourstep.h" #include "fourstep.h"
#include "numbertheory.h" #include "numbertheory.h"
#include "sixstep.h" #include "sixstep.h"
#include "umodarith.h" #include "umodarith.h"
#include "convolute.h"
/* Bignum: Fast convolution using the Number Theoretic Transform. Used for /* Bignum: Fast convolution using the Number Theoretic Transform. Used for
@ -170,5 +169,3 @@ fnt_autoconvolute(mpd_uint_t *c1, mpd_size_t n, int modnum)
return 1; return 1;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,11 @@
*/ */
#ifndef CONVOLUTE_H #ifndef LIBMPDEC_CONVOLUTE_H_
#define CONVOLUTE_H #define LIBMPDEC_CONVOLUTE_H_
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
/* Internal header file: all symbols have local scope in the DSO */ /* Internal header file: all symbols have local scope in the DSO */
@ -47,4 +46,4 @@ int fnt_autoconvolute(mpd_uint_t *c1, mpd_size_t n, int modnum);
MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */
#endif #endif /* LIBMPDEC_CONVOLUTE_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,11 +27,14 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
#include <assert.h> #include <assert.h>
#include "constants.h"
#include "crt.h"
#include "numbertheory.h" #include "numbertheory.h"
#include "umodarith.h" #include "umodarith.h"
#include "crt.h" #include "typearith.h"
/* Bignum: Chinese Remainder Theorem, extends the maximum transform length. */ /* Bignum: Chinese Remainder Theorem, extends the maximum transform length. */
@ -175,5 +178,3 @@ crt3(mpd_uint_t *x1, mpd_uint_t *x2, mpd_uint_t *x3, mpd_size_t rsize)
assert(carry[0] == 0 && carry[1] == 0 && carry[2] == 0); assert(carry[0] == 0 && carry[1] == 0 && carry[2] == 0);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,11 @@
*/ */
#ifndef CRT_H #ifndef LIBMPDEC_CRT_H_
#define CRT_H #define LIBMPDEC_CRT_H_
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
/* Internal header file: all symbols have local scope in the DSO */ /* Internal header file: all symbols have local scope in the DSO */
@ -44,4 +43,4 @@ void crt3(mpd_uint_t *x1, mpd_uint_t *x2, mpd_uint_t *x3, mpd_size_t nmemb);
MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */
#endif #endif /* LIBMPDEC_CRT_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,12 +27,14 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
#include <assert.h> #include <assert.h>
#include "bits.h" #include "bits.h"
#include "constants.h"
#include "difradix2.h"
#include "numbertheory.h" #include "numbertheory.h"
#include "umodarith.h" #include "umodarith.h"
#include "difradix2.h"
/* Bignum: The actual transform routine (decimation in frequency). */ /* Bignum: The actual transform routine (decimation in frequency). */
@ -169,5 +171,3 @@ fnt_dif2(mpd_uint_t a[], mpd_size_t n, struct fnt_params *tparams)
bitreverse_permute(a, n); bitreverse_permute(a, n);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,11 @@
*/ */
#ifndef DIF_RADIX2_H #ifndef LIBMPDEC_DIFRADIX2_H_
#define DIF_RADIX2_H #define LIBMPDEC_DIFRADIX2_H_
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
#include "numbertheory.h" #include "numbertheory.h"
@ -45,4 +44,4 @@ void fnt_dif2(mpd_uint_t a[], mpd_size_t n, struct fnt_params *tparams);
MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */
#endif #endif /* LIBMPDEC_DIFRADIX2_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,13 +27,14 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include "bits.h" #include "bits.h"
#include "difradix2.h" #include "difradix2.h"
#include "numbertheory.h"
#include "fnt.h" #include "fnt.h"
#include "numbertheory.h"
/* Bignum: Fast transform for medium-sized coefficients. */ /* Bignum: Fast transform for medium-sized coefficients. */
@ -76,6 +77,3 @@ std_inv_fnt(mpd_uint_t *a, mpd_size_t n, int modnum)
mpd_free(tparams); mpd_free(tparams);
return 1; return 1;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,11 @@
*/ */
#ifndef FNT_H #ifndef LIBMPDEC_FNT_H_
#define FNT_H #define LIBMPDEC_FNT_H_
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
/* Internal header file: all symbols have local scope in the DSO */ /* Internal header file: all symbols have local scope in the DSO */
@ -45,5 +44,4 @@ int std_inv_fnt(mpd_uint_t a[], mpd_size_t n, int modnum);
MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */
#endif #endif /* LIBMPDEC_FNT_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,12 +27,14 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <assert.h> #include <assert.h>
#include "constants.h"
#include "fourstep.h"
#include "numbertheory.h" #include "numbertheory.h"
#include "sixstep.h" #include "sixstep.h"
#include "transpose.h"
#include "umodarith.h" #include "umodarith.h"
#include "fourstep.h"
/* Bignum: Cache efficient Matrix Fourier Transform for arrays of the /* Bignum: Cache efficient Matrix Fourier Transform for arrays of the
@ -187,6 +189,7 @@ four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum)
#if 0 #if 0
/* An unordered transform is sufficient for convolution. */ /* An unordered transform is sufficient for convolution. */
/* Transpose the matrix. */ /* Transpose the matrix. */
#include "transpose.h"
transpose_3xpow2(a, R, C); transpose_3xpow2(a, R, C);
#endif #endif
@ -217,6 +220,7 @@ inv_four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum)
#if 0 #if 0
/* An unordered transform is sufficient for convolution. */ /* An unordered transform is sufficient for convolution. */
/* Transpose the matrix, producing an R*C matrix. */ /* Transpose the matrix, producing an R*C matrix. */
#include "transpose.h"
transpose_3xpow2(a, C, R); transpose_3xpow2(a, C, R);
#endif #endif
@ -253,5 +257,3 @@ inv_four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum)
return 1; return 1;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,11 @@
*/ */
#ifndef FOUR_STEP_H #ifndef LIBMPDEC_FOURSTEP_H_
#define FOUR_STEP_H #define LIBMPDEC_FOURSTEP_H_
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
/* Internal header file: all symbols have local scope in the DSO */ /* Internal header file: all symbols have local scope in the DSO */
@ -45,4 +44,4 @@ int inv_four_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum);
MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */
#endif #endif /* LIBMPDEC_FOURSTEP_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,16 +27,16 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <locale.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <limits.h>
#include <assert.h>
#include <errno.h>
#include <locale.h>
#include "bits.h"
#include "constants.h"
#include "typearith.h" #include "typearith.h"
#include "io.h" #include "io.h"
@ -277,7 +277,7 @@ mpd_qset_string(mpd_t *dec, const char *s, const mpd_context_t *ctx,
} }
} }
digits = end - coeff; digits = end - coeff;
if (dpoint) { if (dpoint) {
size_t fracdigits = end-dpoint-1; size_t fracdigits = end-dpoint-1;
if (dpoint > coeff) digits--; if (dpoint > coeff) digits--;
@ -326,6 +326,22 @@ conversion_error:
mpd_seterror(dec, MPD_Conversion_syntax, status); mpd_seterror(dec, MPD_Conversion_syntax, status);
} }
/* convert a character string to a decimal, use a maxcontext for conversion */
void
mpd_qset_string_exact(mpd_t *dec, const char *s, uint32_t *status)
{
mpd_context_t maxcontext;
mpd_maxcontext(&maxcontext);
mpd_qset_string(dec, s, &maxcontext, status);
if (*status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) {
/* we want exact results */
mpd_seterror(dec, MPD_Invalid_operation, status);
}
*status &= MPD_Errors;
}
/* Print word x with n decimal digits to string s. dot is either NULL /* Print word x with n decimal digits to string s. dot is either NULL
or the location of a decimal point. */ or the location of a decimal point. */
#define EXTRACT_DIGIT(s, x, d, dot) \ #define EXTRACT_DIGIT(s, x, d, dot) \
@ -539,8 +555,8 @@ _mpd_to_string(char **result, const mpd_t *dec, int flags, mpd_ssize_t dplace)
dplace = -1 + mod_mpd_ssize_t(dec->exp+2, 3); dplace = -1 + mod_mpd_ssize_t(dec->exp+2, 3);
} }
else { /* ldigits-1 is the adjusted exponent, which else { /* ldigits-1 is the adjusted exponent, which
* should be divisible by three. If not, move * should be divisible by three. If not, move
* dplace one or two places to the right. */ * dplace one or two places to the right. */
dplace += mod_mpd_ssize_t(ldigits-1, 3); dplace += mod_mpd_ssize_t(ldigits-1, 3);
} }
} }
@ -1247,7 +1263,7 @@ mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec,
} }
if (isupper((uchar)type)) { if (isupper((uchar)type)) {
type = tolower((uchar)type); type = (char)tolower((uchar)type);
flags |= MPD_FMT_UPPER; flags |= MPD_FMT_UPPER;
} }
if (spec->sign == ' ') { if (spec->sign == ' ') {
@ -1265,6 +1281,7 @@ mpd_qformat_spec(const mpd_t *dec, const mpd_spec_t *spec,
stackspec.align = '>'; stackspec.align = '>';
spec = &stackspec; spec = &stackspec;
} }
assert(strlen(spec->fill) == 1); /* annotation for scan-build */
if (type == '%') { if (type == '%') {
flags |= MPD_FMT_PERCENT; flags |= MPD_FMT_PERCENT;
} }
@ -1579,5 +1596,3 @@ mpd_print(const mpd_t *dec)
fputs("mpd_fprint: output error\n", stderr); /* GCOV_NOT_REACHED */ fputs("mpd_fprint: output error\n", stderr); /* GCOV_NOT_REACHED */
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,17 +26,20 @@
*/ */
#ifndef IO_H #ifndef LIBMPDEC_IO_H_
#define IO_H #define LIBMPDEC_IO_H_
#include <errno.h>
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdint.h>
#if SIZE_MAX == MPD_SIZE_MAX #if SIZE_MAX == MPD_SIZE_MAX
#define mpd_strtossize _mpd_strtossize #define mpd_strtossize _mpd_strtossize
#else #else
#include <errno.h>
static inline mpd_ssize_t static inline mpd_ssize_t
mpd_strtossize(const char *s, char **end, int base) mpd_strtossize(const char *s, char **end, int base)
{ {
@ -56,4 +59,4 @@ mpd_strtossize(const char *s, char **end, int base)
#endif #endif
#endif #endif /* LIBMPDEC_IO_H_ */

View File

@ -1,5 +1,5 @@
# #
# Copyright (c) 2008-2016 Stefan Krah. All rights reserved. # Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions # modification, are permitted provided that the following conditions

View File

@ -1,6 +1,6 @@
(* Copyright (c) 2011 Stefan Krah. All rights reserved. *) (* Copyright (c) 2011-2020 Stefan Krah. All rights reserved. *)
The Matrix Fourier Transform: The Matrix Fourier Transform:

View File

@ -1,6 +1,6 @@
(* Copyright (c) 2011 Stefan Krah. All rights reserved. *) (* Copyright (c) 2011-2020 Stefan Krah. All rights reserved. *)
========================================================================== ==========================================================================

View File

@ -1,6 +1,6 @@
(* Copyright (c) 2011 Stefan Krah. All rights reserved. *) (* Copyright (c) 2011-2020 Stefan Krah. All rights reserved. *)
======================================================================== ========================================================================

View File

@ -1,6 +1,6 @@
(* Copyright (c) 2011 Stefan Krah. All rights reserved. *) (* Copyright (c) 2011-2020 Stefan Krah. All rights reserved. *)
The Six Step Transform: The Six Step Transform:

View File

@ -1,5 +1,5 @@
; ;
; Copyright (c) 2008-2016 Stefan Krah. All rights reserved. ; Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
; ;
; Redistribution and use in source and binary forms, with or without ; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions ; modification, are permitted provided that the following conditions
@ -149,7 +149,7 @@
(defthmd addmod-correct (defthmd addmod-correct
(implies (and (< 0 m) (< m base) (implies (and (< 0 m) (< m base)
(< a m) (<= b m) (< a m) (<= b m)
(natp m) (natp base) (natp m) (natp base)
(natp a) (natp b)) (natp a) (natp b))
(equal (addmod a b m base) (equal (addmod a b m base)
@ -179,7 +179,7 @@
(defthmd submod-correct (defthmd submod-correct
(implies (and (< 0 m) (< m base) (implies (and (< 0 m) (< m base)
(< a m) (<= b m) (< a m) (<= b m)
(natp m) (natp base) (natp m) (natp base)
(natp a) (natp b)) (natp a) (natp b))
(equal (submod a b m base) (equal (submod a b m base)
@ -200,7 +200,7 @@
(defthm submod-2-correct (defthm submod-2-correct
(implies (and (< 0 m) (< m base) (implies (and (< 0 m) (< m base)
(< a m) (<= b m) (< a m) (<= b m)
(natp m) (natp base) (natp m) (natp base)
(natp a) (natp b)) (natp a) (natp b))
(equal (submod-2 a b m base) (equal (submod-2 a b m base)
@ -231,7 +231,7 @@
(defthmd ext-submod-ext-submod-2-equal (defthmd ext-submod-ext-submod-2-equal
(implies (and (< 0 m) (< m base) (implies (and (< 0 m) (< m base)
(< a (* 2 m)) (< b (* 2 m)) (< a (* 2 m)) (< b (* 2 m))
(natp m) (natp base) (natp m) (natp base)
(natp a) (natp b)) (natp a) (natp b))
(equal (ext-submod a b m base) (equal (ext-submod a b m base)
@ -239,7 +239,7 @@
(defthmd ext-submod-2-correct (defthmd ext-submod-2-correct
(implies (and (< 0 m) (< m base) (implies (and (< 0 m) (< m base)
(< a (* 2 m)) (< b (* 2 m)) (< a (* 2 m)) (< b (* 2 m))
(natp m) (natp base) (natp m) (natp base)
(natp a) (natp b)) (natp a) (natp b))
(equal (ext-submod-2 a b m base) (equal (ext-submod-2 a b m base)
@ -257,7 +257,7 @@
(defthmd dw-reduce-correct (defthmd dw-reduce-correct
(implies (and (< 0 m) (< m base) (implies (and (< 0 m) (< m base)
(< hi base) (< lo base) (< hi base) (< lo base)
(natp m) (natp base) (natp m) (natp base)
(natp hi) (natp lo)) (natp hi) (natp lo))
(equal (dw-reduce hi lo m base) (equal (dw-reduce hi lo m base)
@ -322,7 +322,7 @@
(defthmd dw-submod-correct (defthmd dw-submod-correct
(implies (and (< 0 m) (< m base) (implies (and (< 0 m) (< m base)
(natp a) (< a m) (natp a) (< a m)
(< hi base) (< lo base) (< hi base) (< lo base)
(natp m) (natp base) (natp m) (natp base)
(natp hi) (natp lo)) (natp hi) (natp lo))
(equal (dw-submod a hi lo m base) (equal (dw-submod a hi lo m base)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,10 +27,14 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "typearith.h" #include <string.h>
#include "mpalloc.h" #include "mpalloc.h"
#include "typearith.h"
#if defined(_MSC_VER) #if defined(_MSC_VER)
@ -294,4 +298,59 @@ mpd_realloc_dyn(mpd_t *result, mpd_ssize_t nwords, uint32_t *status)
return 1; return 1;
} }
/*
* Input: 'result' is a static mpd_t with a static coefficient.
* Assumption: 'nwords' >= result->alloc.
*
* Resize the static coefficient to a larger dynamic one and copy the
* existing data.
*
* On failure the value of 'result' is unchanged.
*/
int
mpd_switch_to_dyn_cxx(mpd_t *result, mpd_ssize_t nwords)
{
assert(nwords >= result->alloc);
mpd_uint_t *data = mpd_alloc(nwords, sizeof *result->data);
if (data == NULL) {
return 0;
}
memcpy(data, result->data, result->alloc * (sizeof *result->data));
result->data = data;
result->alloc = nwords;
mpd_set_dynamic_data(result);
return 1;
}
/*
* Input: 'result' is a static or a dynamic mpd_t with a dynamic coefficient.
* Resize the coefficient to length 'nwords':
* Case nwords > result->alloc:
* If realloc is successful:
* 'result' has a larger coefficient but the same value. Return 1.
* Otherwise:
* 'result' has a the same coefficient. Return 0.
* Case nwords < result->alloc:
* If realloc is successful:
* 'result' has a smaller coefficient. result->len is undefined. Return 1.
* Otherwise (unlikely):
* 'result' is unchanged. Reuse the now oversized coefficient. Return 1.
*/
int
mpd_realloc_dyn_cxx(mpd_t *result, mpd_ssize_t nwords)
{
uint8_t err = 0;
mpd_uint_t *p = mpd_realloc(result->data, nwords, sizeof *result->data, &err);
if (!err) {
result->data = p;
result->alloc = nwords;
}
else if (nwords > result->alloc) {
return 0;
}
return 1;
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,14 @@
*/ */
#ifndef MPALLOC_H #ifndef LIBMPDEC_MPALLOC_H_
#define MPALLOC_H #define LIBMPDEC_MPALLOC_H_
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdint.h>
/* Internal header file: all symbols have local scope in the DSO */ /* Internal header file: all symbols have local scope in the DSO */
MPD_PRAGMA(MPD_HIDE_SYMBOLS_START) MPD_PRAGMA(MPD_HIDE_SYMBOLS_START)
@ -41,11 +43,11 @@ int mpd_switch_to_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status);
int mpd_switch_to_dyn_zero(mpd_t *result, mpd_ssize_t size, uint32_t *status); int mpd_switch_to_dyn_zero(mpd_t *result, mpd_ssize_t size, uint32_t *status);
int mpd_realloc_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status); int mpd_realloc_dyn(mpd_t *result, mpd_ssize_t size, uint32_t *status);
int mpd_switch_to_dyn_cxx(mpd_t *result, mpd_ssize_t size);
int mpd_realloc_dyn_cxx(mpd_t *result, mpd_ssize_t size);
MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */
#endif #endif /* LIBMPDEC_MPALLOC_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,18 +27,21 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h>
#include <math.h>
#include "basearith.h" #include "basearith.h"
#include "bits.h" #include "bits.h"
#include "constants.h"
#include "convolute.h" #include "convolute.h"
#include "crt.h" #include "crt.h"
#include "mpalloc.h" #include "mpalloc.h"
#include "typearith.h" #include "typearith.h"
#include "umodarith.h"
#ifdef PPRO #ifdef PPRO
#if defined(_MSC_VER) #if defined(_MSC_VER)
@ -241,7 +244,7 @@ mpd_lsd(mpd_uint_t word)
} }
/* Coefficient size needed to store 'digits' */ /* Coefficient size needed to store 'digits' */
ALWAYS_INLINE mpd_ssize_t mpd_ssize_t
mpd_digits_to_size(mpd_ssize_t digits) mpd_digits_to_size(mpd_ssize_t digits)
{ {
mpd_ssize_t q, r; mpd_ssize_t q, r;
@ -260,8 +263,9 @@ mpd_exp_digits(mpd_ssize_t exp)
/* Canonical */ /* Canonical */
ALWAYS_INLINE int ALWAYS_INLINE int
mpd_iscanonical(const mpd_t *dec UNUSED) mpd_iscanonical(const mpd_t *dec)
{ {
(void)dec;
return 1; return 1;
} }
@ -512,6 +516,28 @@ mpd_qresize(mpd_t *result, mpd_ssize_t nwords, uint32_t *status)
return mpd_realloc_dyn(result, nwords, status); return mpd_realloc_dyn(result, nwords, status);
} }
/* Same as mpd_qresize, but do not set the result no NaN on failure. */
static ALWAYS_INLINE int
mpd_qresize_cxx(mpd_t *result, mpd_ssize_t nwords)
{
assert(!mpd_isconst_data(result)); /* illegal operation for a const */
assert(!mpd_isshared_data(result)); /* illegal operation for a shared */
assert(MPD_MINALLOC <= result->alloc);
nwords = (nwords <= MPD_MINALLOC) ? MPD_MINALLOC : nwords;
if (nwords == result->alloc) {
return 1;
}
if (mpd_isstatic_data(result)) {
if (nwords > result->alloc) {
return mpd_switch_to_dyn_cxx(result, nwords);
}
return 1;
}
return mpd_realloc_dyn_cxx(result, nwords);
}
/* Same as mpd_qresize, but the complete coefficient (including the old /* Same as mpd_qresize, but the complete coefficient (including the old
* memory area!) is initialized to zero. */ * memory area!) is initialized to zero. */
ALWAYS_INLINE int ALWAYS_INLINE int
@ -1192,7 +1218,7 @@ _c32setu64(mpd_t *result, uint64_t u, uint8_t sign, uint32_t *status)
result->data[i] = w[i]; result->data[i] = w[i];
} }
mpd_set_sign(result, sign); mpd_set_flags(result, sign);
result->exp = 0; result->exp = 0;
result->len = len; result->len = len;
mpd_setdigits(result); mpd_setdigits(result);
@ -1244,6 +1270,26 @@ mpd_qset_i64(mpd_t *result, int64_t a, const mpd_context_t *ctx,
#endif #endif
} }
/* quietly set a decimal from an int64_t, use a maxcontext for conversion */
void
mpd_qset_i64_exact(mpd_t *result, int64_t a, uint32_t *status)
{
mpd_context_t maxcontext;
mpd_maxcontext(&maxcontext);
#ifdef CONFIG_64
mpd_qset_ssize(result, a, &maxcontext, status);
#else
_c32_qset_i64(result, a, &maxcontext, status);
#endif
if (*status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) {
/* we want exact results */
mpd_seterror(result, MPD_Invalid_operation, status);
}
*status &= MPD_Errors;
}
/* quietly set a decimal from a uint64_t */ /* quietly set a decimal from a uint64_t */
void void
mpd_qset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx, mpd_qset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx,
@ -1255,8 +1301,27 @@ mpd_qset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx,
_c32_qset_u64(result, a, ctx, status); _c32_qset_u64(result, a, ctx, status);
#endif #endif
} }
#endif /* !LEGACY_COMPILER */
/* quietly set a decimal from a uint64_t, use a maxcontext for conversion */
void
mpd_qset_u64_exact(mpd_t *result, uint64_t a, uint32_t *status)
{
mpd_context_t maxcontext;
mpd_maxcontext(&maxcontext);
#ifdef CONFIG_64
mpd_qset_uint(result, a, &maxcontext, status);
#else
_c32_qset_u64(result, a, &maxcontext, status);
#endif
if (*status & (MPD_Inexact|MPD_Rounded|MPD_Clamped)) {
/* we want exact results */
mpd_seterror(result, MPD_Invalid_operation, status);
}
*status &= MPD_Errors;
}
#endif /* !LEGACY_COMPILER */
/* /*
* Quietly get an mpd_uint_t from a decimal. Assumes * Quietly get an mpd_uint_t from a decimal. Assumes
@ -1345,11 +1410,13 @@ mpd_qabs_uint(const mpd_t *a, uint32_t *status)
mpd_ssize_t mpd_ssize_t
mpd_qget_ssize(const mpd_t *a, uint32_t *status) mpd_qget_ssize(const mpd_t *a, uint32_t *status)
{ {
uint32_t workstatus = 0;
mpd_uint_t u; mpd_uint_t u;
int isneg; int isneg;
u = mpd_qabs_uint(a, status); u = mpd_qabs_uint(a, &workstatus);
if (*status&MPD_Invalid_operation) { if (workstatus&MPD_Invalid_operation) {
*status |= workstatus;
return MPD_SSIZE_MAX; return MPD_SSIZE_MAX;
} }
@ -1469,9 +1536,11 @@ mpd_qget_i64(const mpd_t *a, uint32_t *status)
uint32_t uint32_t
mpd_qget_u32(const mpd_t *a, uint32_t *status) mpd_qget_u32(const mpd_t *a, uint32_t *status)
{ {
uint64_t x = mpd_qget_uint(a, status); uint32_t workstatus = 0;
uint64_t x = mpd_qget_uint(a, &workstatus);
if (*status&MPD_Invalid_operation) { if (workstatus&MPD_Invalid_operation) {
*status |= workstatus;
return UINT32_MAX; return UINT32_MAX;
} }
if (x > UINT32_MAX) { if (x > UINT32_MAX) {
@ -1486,9 +1555,11 @@ mpd_qget_u32(const mpd_t *a, uint32_t *status)
int32_t int32_t
mpd_qget_i32(const mpd_t *a, uint32_t *status) mpd_qget_i32(const mpd_t *a, uint32_t *status)
{ {
int64_t x = mpd_qget_ssize(a, status); uint32_t workstatus = 0;
int64_t x = mpd_qget_ssize(a, &workstatus);
if (*status&MPD_Invalid_operation) { if (workstatus&MPD_Invalid_operation) {
*status |= workstatus;
return INT32_MAX; return INT32_MAX;
} }
if (x < INT32_MIN || x > INT32_MAX) { if (x < INT32_MIN || x > INT32_MAX) {
@ -1504,14 +1575,20 @@ mpd_qget_i32(const mpd_t *a, uint32_t *status)
uint64_t uint64_t
mpd_qget_u64(const mpd_t *a, uint32_t *status) mpd_qget_u64(const mpd_t *a, uint32_t *status)
{ {
return _c32_qget_u64(1, a, status); uint32_t workstatus = 0;
uint64_t x = _c32_qget_u64(1, a, &workstatus);
*status |= workstatus;
return x;
} }
/* quietly get an int64_t from a decimal */ /* quietly get an int64_t from a decimal */
int64_t int64_t
mpd_qget_i64(const mpd_t *a, uint32_t *status) mpd_qget_i64(const mpd_t *a, uint32_t *status)
{ {
return _c32_qget_i64(a, status); uint32_t workstatus = 0;
int64_t x = _c32_qget_i64(a, &workstatus);
*status |= workstatus;
return x;
} }
#endif #endif
@ -1937,6 +2014,25 @@ mpd_qcopy(mpd_t *result, const mpd_t *a, uint32_t *status)
return 1; return 1;
} }
/* Same as mpd_qcopy, but do not set the result to NaN on failure. */
int
mpd_qcopy_cxx(mpd_t *result, const mpd_t *a)
{
if (result == a) return 1;
if (!mpd_qresize_cxx(result, a->len)) {
return 0;
}
mpd_copy_flags(result, a);
result->exp = a->exp;
result->digits = a->digits;
result->len = a->len;
memcpy(result->data, a->data, a->len * (sizeof *result->data));
return 1;
}
/* /*
* Copy to a decimal with a static buffer. The caller has to make sure that * Copy to a decimal with a static buffer. The caller has to make sure that
* the buffer is big enough. Cannot fail. * the buffer is big enough. Cannot fail.
@ -3780,11 +3876,31 @@ void
mpd_qdiv(mpd_t *q, const mpd_t *a, const mpd_t *b, mpd_qdiv(mpd_t *q, const mpd_t *a, const mpd_t *b,
const mpd_context_t *ctx, uint32_t *status) const mpd_context_t *ctx, uint32_t *status)
{ {
_mpd_qdiv(SET_IDEAL_EXP, q, a, b, ctx, status); MPD_NEW_STATIC(aa,0,0,0,0);
MPD_NEW_STATIC(bb,0,0,0,0);
uint32_t xstatus = 0;
if (*status & MPD_Malloc_error) { if (q == a) {
if (!mpd_qcopy(&aa, a, status)) {
mpd_seterror(q, MPD_Malloc_error, status);
goto out;
}
a = &aa;
}
if (q == b) {
if (!mpd_qcopy(&bb, b, status)) {
mpd_seterror(q, MPD_Malloc_error, status);
goto out;
}
b = &bb;
}
_mpd_qdiv(SET_IDEAL_EXP, q, a, b, ctx, &xstatus);
if (xstatus & (MPD_Malloc_error|MPD_Division_impossible)) {
/* Inexact quotients (the usual case) fill the entire context precision, /* Inexact quotients (the usual case) fill the entire context precision,
* which can lead to malloc() failures for very high precisions. Retry * which can lead to the above errors for very high precisions. Retry
* the operation with a lower precision in case the result is exact. * the operation with a lower precision in case the result is exact.
* *
* We need an upper bound for the number of digits of a_coeff / b_coeff * We need an upper bound for the number of digits of a_coeff / b_coeff
@ -3799,25 +3915,33 @@ mpd_qdiv(mpd_t *q, const mpd_t *a, const mpd_t *b,
* We arrive at a total upper bound: * We arrive at a total upper bound:
* *
* maxdigits(a_coeff') + maxdigits(1 / b_coeff') <= * maxdigits(a_coeff') + maxdigits(1 / b_coeff') <=
* a->digits + log2(b_coeff) = * log10(a_coeff) + log2(b_coeff) =
* a->digits + log10(b_coeff) / log10(2) <= * log10(a_coeff) + log10(b_coeff) / log10(2) <=
* a->digits + b->digits * 4; * a->digits + b->digits * 4;
*/ */
uint32_t workstatus = 0;
mpd_context_t workctx = *ctx; mpd_context_t workctx = *ctx;
uint32_t ystatus = 0;
workctx.prec = a->digits + b->digits * 4; workctx.prec = a->digits + b->digits * 4;
if (workctx.prec >= ctx->prec) { if (workctx.prec >= ctx->prec) {
return; /* No point in retrying, keep the original error. */ *status |= (xstatus&MPD_Errors);
goto out; /* No point in retrying, keep the original error. */
} }
_mpd_qdiv(SET_IDEAL_EXP, q, a, b, &workctx, &workstatus); _mpd_qdiv(SET_IDEAL_EXP, q, a, b, &workctx, &ystatus);
if (workstatus == 0) { /* The result is exact, unrounded, normal etc. */ if (ystatus != 0) {
*status = 0; ystatus = *status | ((ystatus|xstatus)&MPD_Errors);
return; mpd_seterror(q, ystatus, status);
} }
mpd_seterror(q, *status, status);
} }
else {
*status |= xstatus;
}
out:
mpd_del(&aa);
mpd_del(&bb);
} }
/* Internal function. */ /* Internal function. */
@ -3907,6 +4031,7 @@ _mpd_qdivmod(mpd_t *q, mpd_t *r, const mpd_t *a, const mpd_t *b,
} }
if (b->len == 1) { if (b->len == 1) {
assert(b->data[0] != 0); /* annotation for scan-build */
if (a->len == 1) { if (a->len == 1) {
_mpd_div_word(&q->data[0], &r->data[0], a->data[0], b->data[0]); _mpd_div_word(&q->data[0], &r->data[0], a->data[0], b->data[0]);
} }
@ -6251,9 +6376,11 @@ _mpd_qpow_int(mpd_t *result, const mpd_t *base, const mpd_t *exp,
workctx.round = MPD_ROUND_HALF_EVEN; workctx.round = MPD_ROUND_HALF_EVEN;
workctx.clamp = 0; workctx.clamp = 0;
if (mpd_isnegative(exp)) { if (mpd_isnegative(exp)) {
uint32_t workstatus = 0;
workctx.prec += 1; workctx.prec += 1;
mpd_qdiv(&tbase, &one, base, &workctx, status); mpd_qdiv(&tbase, &one, base, &workctx, &workstatus);
if (*status&MPD_Errors) { *status |= workstatus;
if (workstatus&MPD_Errors) {
mpd_setspecial(result, MPD_POS, MPD_NAN); mpd_setspecial(result, MPD_POS, MPD_NAN);
goto finish; goto finish;
} }
@ -6988,6 +7115,8 @@ mpd_qrem_near(mpd_t *r, const mpd_t *a, const mpd_t *b,
mpd_ssize_t expdiff, qdigits; mpd_ssize_t expdiff, qdigits;
int cmp, isodd, allnine; int cmp, isodd, allnine;
assert(r != NULL); /* annotation for scan-build */
if (mpd_isspecial(a) || mpd_isspecial(b)) { if (mpd_isspecial(a) || mpd_isspecial(b)) {
if (mpd_qcheck_nans(r, a, b, ctx, status)) { if (mpd_qcheck_nans(r, a, b, ctx, status)) {
return; return;
@ -7218,6 +7347,11 @@ void
mpd_qtrunc(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, mpd_qtrunc(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx,
uint32_t *status) uint32_t *status)
{ {
if (mpd_isspecial(a)) {
mpd_seterror(result, MPD_Invalid_operation, status);
return;
}
(void)_mpd_qround_to_integral(TO_INT_TRUNC, result, a, ctx, status); (void)_mpd_qround_to_integral(TO_INT_TRUNC, result, a, ctx, status);
} }
@ -7226,6 +7360,12 @@ mpd_qfloor(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx,
uint32_t *status) uint32_t *status)
{ {
mpd_context_t workctx = *ctx; mpd_context_t workctx = *ctx;
if (mpd_isspecial(a)) {
mpd_seterror(result, MPD_Invalid_operation, status);
return;
}
workctx.round = MPD_ROUND_FLOOR; workctx.round = MPD_ROUND_FLOOR;
(void)_mpd_qround_to_integral(TO_INT_SILENT, result, a, (void)_mpd_qround_to_integral(TO_INT_SILENT, result, a,
&workctx, status); &workctx, status);
@ -7236,6 +7376,12 @@ mpd_qceil(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx,
uint32_t *status) uint32_t *status)
{ {
mpd_context_t workctx = *ctx; mpd_context_t workctx = *ctx;
if (mpd_isspecial(a)) {
mpd_seterror(result, MPD_Invalid_operation, status);
return;
}
workctx.round = MPD_ROUND_CEILING; workctx.round = MPD_ROUND_CEILING;
(void)_mpd_qround_to_integral(TO_INT_SILENT, result, a, (void)_mpd_qround_to_integral(TO_INT_SILENT, result, a,
&workctx, status); &workctx, status);
@ -7877,9 +8023,20 @@ void
mpd_qsqrt(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx, mpd_qsqrt(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx,
uint32_t *status) uint32_t *status)
{ {
_mpd_qsqrt(result, a, ctx, status); MPD_NEW_STATIC(aa,0,0,0,0);
uint32_t xstatus = 0;
if (*status & (MPD_Malloc_error|MPD_Division_impossible)) { if (result == a) {
if (!mpd_qcopy(&aa, a, status)) {
mpd_seterror(result, MPD_Malloc_error, status);
goto out;
}
a = &aa;
}
_mpd_qsqrt(result, a, ctx, &xstatus);
if (xstatus & (MPD_Malloc_error|MPD_Division_impossible)) {
/* The above conditions can occur at very high context precisions /* The above conditions can occur at very high context precisions
* if intermediate values get too large. Retry the operation with * if intermediate values get too large. Retry the operation with
* a lower context precision in case the result is exact. * a lower context precision in case the result is exact.
@ -7889,22 +8046,27 @@ mpd_qsqrt(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx,
* *
* NOTE: sqrt(40e9) = 2.0e+5 /\ digits(40e9) = digits(2.0e+5) = 2 * NOTE: sqrt(40e9) = 2.0e+5 /\ digits(40e9) = digits(2.0e+5) = 2
*/ */
uint32_t workstatus = 0; uint32_t ystatus = 0;
mpd_context_t workctx = *ctx; mpd_context_t workctx = *ctx;
workctx.prec = a->digits; workctx.prec = a->digits;
if (workctx.prec >= ctx->prec) { if (workctx.prec >= ctx->prec) {
return; /* No point in repeating this, keep the original error. */ *status |= (xstatus|MPD_Errors);
goto out; /* No point in repeating this, keep the original error. */
} }
_mpd_qsqrt(result, a, &workctx, &workstatus); _mpd_qsqrt(result, a, &workctx, &ystatus);
if (workstatus == 0) { if (ystatus != 0) {
*status = 0; ystatus = *status | ((xstatus|ystatus)&MPD_Errors);
return; mpd_seterror(result, ystatus, status);
} }
mpd_seterror(result, *status, status);
} }
else {
*status |= xstatus;
}
out:
mpd_del(&aa);
} }
@ -7918,6 +8080,7 @@ mpd_sizeinbase(const mpd_t *a, uint32_t base)
{ {
double x; double x;
size_t digits; size_t digits;
double upper_bound;
assert(mpd_isinteger(a)); assert(mpd_isinteger(a));
assert(base >= 2); assert(base >= 2);
@ -7934,10 +8097,14 @@ mpd_sizeinbase(const mpd_t *a, uint32_t base)
if (digits > 2711437152599294ULL) { if (digits > 2711437152599294ULL) {
return SIZE_MAX; return SIZE_MAX;
} }
upper_bound = (double)((1ULL<<53)-1);
#else
upper_bound = (double)(SIZE_MAX-1);
#endif #endif
x = (double)digits / log10(base); x = (double)digits / log10(base);
return (x > SIZE_MAX-1) ? SIZE_MAX : (size_t)x + 1; return (x > upper_bound) ? SIZE_MAX : (size_t)x + 1;
} }
/* Space needed to import a base 'base' integer of length 'srclen'. */ /* Space needed to import a base 'base' integer of length 'srclen'. */
@ -7945,6 +8112,7 @@ static mpd_ssize_t
_mpd_importsize(size_t srclen, uint32_t base) _mpd_importsize(size_t srclen, uint32_t base)
{ {
double x; double x;
double upper_bound;
assert(srclen > 0); assert(srclen > 0);
assert(base >= 2); assert(base >= 2);
@ -7953,10 +8121,15 @@ _mpd_importsize(size_t srclen, uint32_t base)
if (srclen > (1ULL<<53)) { if (srclen > (1ULL<<53)) {
return MPD_SSIZE_MAX; return MPD_SSIZE_MAX;
} }
assert((1ULL<<53) <= MPD_MAXIMPORT);
upper_bound = (double)((1ULL<<53)-1);
#else
upper_bound = MPD_MAXIMPORT-1;
#endif #endif
x = (double)srclen * (log10(base)/MPD_RDIGITS); x = (double)srclen * (log10(base)/MPD_RDIGITS);
return (x >= MPD_MAXIMPORT) ? MPD_SSIZE_MAX : (mpd_ssize_t)x + 1; return (x > upper_bound) ? MPD_SSIZE_MAX : (mpd_ssize_t)x + 1;
} }
static uint8_t static uint8_t
@ -8483,6 +8656,3 @@ mpd_qimport_u32(mpd_t *result,
mpd_qresize(result, result->len, status); mpd_qresize(result, result->len, status);
mpd_qfinalize(result, ctx, status); mpd_qfinalize(result, ctx, status);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,59 +26,51 @@
*/ */
#ifndef MPDECIMAL_H #ifndef LIBMPDEC_MPDECIMAL_H_
#define MPDECIMAL_H #define LIBMPDEC_MPDECIMAL_H_
#ifdef __cplusplus
extern "C" {
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#define MPD_CLEAR_STDC_LIMIT_MACROS
#endif
#endif
#ifndef _MSC_VER #ifndef _MSC_VER
#include "pyconfig.h" #include "pyconfig.h"
#endif #endif
#include <stdio.h> #ifdef __cplusplus
#include <stdlib.h> #include <cinttypes>
#include <string.h> #include <climits>
#include <limits.h> #include <cstdint>
#include <assert.h> #include <cstdio>
#include <stdint.h> #include <cstdlib>
#include <inttypes.h> extern "C" {
#else
#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#endif
#ifdef _MSC_VER
#include "vccompat.h" #if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \
#ifndef UNUSED defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER)
#define UNUSED #define MPD_PRAGMA(x) _Pragma(x)
#endif #define MPD_HIDE_SYMBOLS_START "GCC visibility push(hidden)"
#define MPD_HIDE_SYMBOLS_END "GCC visibility pop"
#else
#define MPD_PRAGMA(x) #define MPD_PRAGMA(x)
#define MPD_HIDE_SYMBOLS_START #define MPD_HIDE_SYMBOLS_START
#define MPD_HIDE_SYMBOLS_END #define MPD_HIDE_SYMBOLS_END
#endif
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
#define UNUSED __attribute__((unused))
#else
#define UNUSED
#endif
#if defined(_MSC_VER)
#include "vccompat.h"
#define EXTINLINE extern inline #define EXTINLINE extern inline
#else #else
#ifndef __GNUC_STDC_INLINE__
#define __GNUC_STDC_INLINE__ 1
#endif
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
#define UNUSED __attribute__((unused))
#else
#define UNUSED
#endif
#if (defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)) && \
defined(__GNUC__) && __GNUC__ >= 4 && !defined(__INTEL_COMPILER)
#define MPD_PRAGMA(x) _Pragma(x)
#define MPD_HIDE_SYMBOLS_START "GCC visibility push(hidden)"
#define MPD_HIDE_SYMBOLS_END "GCC visibility pop"
#else
#define MPD_PRAGMA(x)
#define MPD_HIDE_SYMBOLS_START
#define MPD_HIDE_SYMBOLS_END
#endif
#define EXTINLINE #define EXTINLINE
#endif #endif
@ -103,10 +95,10 @@ MPD_PRAGMA(MPD_HIDE_SYMBOLS_START)
/******************************************************************************/ /******************************************************************************/
#define MPD_MAJOR_VERSION 2 #define MPD_MAJOR_VERSION 2
#define MPD_MINOR_VERSION 4 #define MPD_MINOR_VERSION 5
#define MPD_MICRO_VERSION 2 #define MPD_MICRO_VERSION 0
#define MPD_VERSION "2.4.2" #define MPD_VERSION "2.5.0"
#define MPD_VERSION_HEX ((MPD_MAJOR_VERSION << 24) | \ #define MPD_VERSION_HEX ((MPD_MAJOR_VERSION << 24) | \
(MPD_MINOR_VERSION << 16) | \ (MPD_MINOR_VERSION << 16) | \
@ -423,6 +415,7 @@ void mpd_print(const mpd_t *dec);
/* assignment from a string */ /* assignment from a string */
void mpd_qset_string(mpd_t *dec, const char *s, const mpd_context_t *ctx, uint32_t *status); void mpd_qset_string(mpd_t *dec, const char *s, const mpd_context_t *ctx, uint32_t *status);
void mpd_qset_string_exact(mpd_t *dec, const char *s, uint32_t *status);
/* set to NaN with error flags */ /* set to NaN with error flags */
void mpd_seterror(mpd_t *result, uint32_t flags, uint32_t *status); void mpd_seterror(mpd_t *result, uint32_t flags, uint32_t *status);
@ -440,6 +433,8 @@ void mpd_qset_u32(mpd_t *result, uint32_t a, const mpd_context_t *ctx, uint32_t
#ifndef LEGACY_COMPILER #ifndef LEGACY_COMPILER
void mpd_qset_i64(mpd_t *result, int64_t a, const mpd_context_t *ctx, uint32_t *status); void mpd_qset_i64(mpd_t *result, int64_t a, const mpd_context_t *ctx, uint32_t *status);
void mpd_qset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx, uint32_t *status); void mpd_qset_u64(mpd_t *result, uint64_t a, const mpd_context_t *ctx, uint32_t *status);
void mpd_qset_i64_exact(mpd_t *result, int64_t a, uint32_t *status);
void mpd_qset_u64_exact(mpd_t *result, uint64_t a, uint32_t *status);
#endif #endif
/* quietly assign a C integer type to an mpd_t with a static coefficient */ /* quietly assign a C integer type to an mpd_t with a static coefficient */
@ -467,7 +462,8 @@ void mpd_qfinalize(mpd_t *result, const mpd_context_t *ctx, uint32_t *status);
const char *mpd_class(const mpd_t *a, const mpd_context_t *ctx); const char *mpd_class(const mpd_t *a, const mpd_context_t *ctx);
int mpd_qcopy(mpd_t *result, const mpd_t *a, uint32_t *status); int mpd_qcopy(mpd_t *result, const mpd_t *a, uint32_t *status);
int mpd_qcopy_cxx(mpd_t *result, const mpd_t *a);
mpd_t *mpd_qncopy(const mpd_t *a); mpd_t *mpd_qncopy(const mpd_t *a);
int mpd_qcopy_abs(mpd_t *result, const mpd_t *a, uint32_t *status); int mpd_qcopy_abs(mpd_t *result, const mpd_t *a, uint32_t *status);
int mpd_qcopy_negate(mpd_t *result, const mpd_t *a, uint32_t *status); int mpd_qcopy_negate(mpd_t *result, const mpd_t *a, uint32_t *status);
@ -721,7 +717,7 @@ EXTINLINE mpd_uint_t mpd_lsd(mpd_uint_t word);
EXTINLINE mpd_ssize_t mpd_digits_to_size(mpd_ssize_t digits); EXTINLINE mpd_ssize_t mpd_digits_to_size(mpd_ssize_t digits);
/* number of digits in the exponent, undefined for MPD_SSIZE_MIN */ /* number of digits in the exponent, undefined for MPD_SSIZE_MIN */
EXTINLINE int mpd_exp_digits(mpd_ssize_t exp); EXTINLINE int mpd_exp_digits(mpd_ssize_t exp);
EXTINLINE int mpd_iscanonical(const mpd_t *dec UNUSED); EXTINLINE int mpd_iscanonical(const mpd_t *dec);
EXTINLINE int mpd_isfinite(const mpd_t *dec); EXTINLINE int mpd_isfinite(const mpd_t *dec);
EXTINLINE int mpd_isinfinite(const mpd_t *dec); EXTINLINE int mpd_isinfinite(const mpd_t *dec);
EXTINLINE int mpd_isinteger(const mpd_t *dec); EXTINLINE int mpd_isinteger(const mpd_t *dec);
@ -833,15 +829,8 @@ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */
#ifdef __cplusplus #ifdef __cplusplus
#ifdef MPD_CLEAR_STDC_LIMIT_MACROS
#undef MPD_CLEAR_STDC_LIMIT_MACROS
#undef __STDC_LIMIT_MACROS
#endif
} /* END extern "C" */ } /* END extern "C" */
#endif #endif
#endif /* MPDECIMAL_H */ #endif /* LIBMPDEC_MPDECIMAL_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,11 +27,13 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h>
#include "bits.h" #include "bits.h"
#include "umodarith.h"
#include "numbertheory.h" #include "numbertheory.h"
#include "umodarith.h"
/* Bignum: Initialize the Number Theoretic Transform. */ /* Bignum: Initialize the Number Theoretic Transform. */
@ -128,5 +130,3 @@ _mpd_init_w3table(mpd_uint_t w3table[3], int sign, int modnum)
w3table[1] = kernel; w3table[1] = kernel;
w3table[2] = POWMOD(kernel, 2); w3table[2] = POWMOD(kernel, 2);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,12 @@
*/ */
#ifndef NUMBER_THEORY_H #ifndef LIBMPDEC_NUMBERTHEORY_H_
#define NUMBER_THEORY_H #define LIBMPDEC_NUMBERTHEORY_H_
#include "constants.h"
#include "mpdecimal.h" #include "mpdecimal.h"
#include "constants.h"
/* Internal header file: all symbols have local scope in the DSO */ /* Internal header file: all symbols have local scope in the DSO */
@ -73,6 +73,4 @@ std_setmodulus(int modnum, mpd_uint_t *umod)
MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */
#endif #endif /* LIBMPDEC_NUMBERTHEORY_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,15 +27,17 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include "bits.h" #include "bits.h"
#include "constants.h"
#include "difradix2.h" #include "difradix2.h"
#include "numbertheory.h" #include "numbertheory.h"
#include "sixstep.h"
#include "transpose.h" #include "transpose.h"
#include "umodarith.h" #include "umodarith.h"
#include "sixstep.h"
/* Bignum: Cache efficient Matrix Fourier Transform for arrays of the /* Bignum: Cache efficient Matrix Fourier Transform for arrays of the
@ -210,5 +212,3 @@ inv_six_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum)
return 1; return 1;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,11 @@
*/ */
#ifndef SIX_STEP_H #ifndef LIBMPDEC_SIXSTEP_H_
#define SIX_STEP_H #define LIBMPDEC_SIXSTEP_H_
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
/* Internal header file: all symbols have local scope in the DSO */ /* Internal header file: all symbols have local scope in the DSO */
@ -45,4 +44,4 @@ int inv_six_step_fnt(mpd_uint_t *a, mpd_size_t n, int modnum);
MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */
#endif #endif /* LIBMPDEC_SIXSTEP_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,15 +27,17 @@
#include "mpdecimal.h" #include "mpdecimal.h"
#include <assert.h>
#include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h>
#include <assert.h>
#include "bits.h" #include "bits.h"
#include "constants.h" #include "constants.h"
#include "typearith.h"
#include "transpose.h" #include "transpose.h"
#include "typearith.h"
#define BUFSIZE 4096 #define BUFSIZE 4096
@ -272,5 +274,3 @@ transpose_pow2(mpd_uint_t *matrix, mpd_size_t rows, mpd_size_t cols)
return 1; return 1;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,11 @@
*/ */
#ifndef TRANSPOSE_H #ifndef LIBMPDEC_TRANSPOSE_H_
#define TRANSPOSE_H #define LIBMPDEC_TRANSPOSE_H_
#include "mpdecimal.h" #include "mpdecimal.h"
#include <stdio.h>
/* Internal header file: all symbols have local scope in the DSO */ /* Internal header file: all symbols have local scope in the DSO */
@ -59,4 +58,4 @@ static inline void pointerswap(mpd_uint_t **a, mpd_uint_t **b)
MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */ MPD_PRAGMA(MPD_HIDE_SYMBOLS_END) /* restore previous scope rules */
#endif #endif /* LIBMPDEC_TRANSPOSE_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,14 @@
*/ */
#ifndef TYPEARITH_H #ifndef LIBMPDEC_TYPEARITH_H_
#define TYPEARITH_H #define LIBMPDEC_TYPEARITH_H_
#include "mpdecimal.h" #include "mpdecimal.h"
#include <assert.h>
/*****************************************************************************/ /*****************************************************************************/
/* Low level native arithmetic on basic types */ /* Low level native arithmetic on basic types */
@ -663,7 +665,4 @@ mulmod_size_t(mpd_size_t a, mpd_size_t b, mpd_size_t m)
} }
#endif /* TYPEARITH_H */ #endif /* LIBMPDEC_TYPEARITH_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,12 +26,13 @@
*/ */
#ifndef UMODARITH_H #ifndef LIBMPDEC_UMODARITH_H_
#define UMODARITH_H #define LIBMPDEC_UMODARITH_H_
#include "mpdecimal.h"
#include "constants.h" #include "constants.h"
#include "mpdecimal.h"
#include "typearith.h" #include "typearith.h"
@ -644,7 +645,4 @@ ppro_powmod(mpd_uint_t base, mpd_uint_t exp, double *dmod, uint32_t *dinvmod)
#endif /* CONFIG_32 */ #endif /* CONFIG_32 */
#endif /* UMODARITH_H */ #endif /* LIBMPDEC_UMODARITH_H_ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008-2016 Stefan Krah. All rights reserved. * Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -26,14 +26,16 @@
*/ */
#ifndef VCCOMPAT_H #ifndef LIBMPDEC_VCCOMPAT_H_
#define VCCOMPAT_H #define LIBMPDEC_VCCOMPAT_H_
/* Visual C fixes: no snprintf ... */ /* Visual C fixes: no snprintf ... */
#ifdef _MSC_VER #ifdef _MSC_VER
#undef inline #ifndef __cplusplus
#define inline __inline #undef inline
#define inline __inline
#endif
#undef random #undef random
#define random rand #define random rand
#undef srandom #undef srandom
@ -51,7 +53,4 @@
#endif #endif
#endif /* VCCOMPAT_H */ #endif /* LIBMPDEC_VCCOMPAT_H_ */

View File

@ -1,5 +1,5 @@
; ;
; Copyright (c) 2008-2016 Stefan Krah. All rights reserved. ; Copyright (c) 2008-2020 Stefan Krah. All rights reserved.
; ;
; Redistribution and use in source and binary forms, with or without ; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions ; modification, are permitted provided that the following conditions
@ -44,5 +44,3 @@ _mpd_div_words PROC
_mpd_div_words ENDP _mpd_div_words ENDP
_TEXT ENDS _TEXT ENDS
END END