🐛 qmc_sequence MEX: large input seeds would be truncated

The int64 input seed was converted to a double before being converted back to
an int64. But large integers cannot be represented exactly in a double.
mr#2134
Sébastien Villemot 2023-04-15 15:47:55 +02:00
parent 9dff1ff28e
commit 85351d751c
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 7 additions and 2 deletions

View File

@ -1,7 +1,7 @@
/*
** Computes Quasi Monte-Carlo sequence.
**
** Copyright © 2010-2022 Dynare Team
** Copyright © 2010-2023 Dynare Team
**
** This file is part of Dynare (can be used outside Dynare).
**
@ -73,7 +73,12 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
if (!(mxIsNumeric(prhs[1]) && mxIsClass(prhs[1], "int64")))
mexErrMsgTxt("qmc_sequence:: Second input (seed) has to be an integer [int64]!");
int64_T seed = static_cast<int64_T>(mxGetScalar(prhs[1]));
#if MX_HAS_INTERLEAVED_COMPLEX
int64_T seed = *mxGetInt64s(prhs[1]);
#else
int64_T seed = *static_cast<int64_T *>(mxGetData(prhs[1]));
#endif
/*
** Test the third input argument and assign it to type (kind of QMC sequence).
*/