From 85351d751c52ef11516dab7f8502ebfd7d19362f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Sat, 15 Apr 2023 15:47:55 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20qmc=5Fsequence=20MEX:=20large=20?= =?UTF-8?q?input=20seeds=20would=20be=20truncated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- mex/sources/sobol/qmc_sequence.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mex/sources/sobol/qmc_sequence.cc b/mex/sources/sobol/qmc_sequence.cc index a3856517fc..237fb0019c 100644 --- a/mex/sources/sobol/qmc_sequence.cc +++ b/mex/sources/sobol/qmc_sequence.cc @@ -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). */ -- GitLab