From d13634cd6b1c9e38aa331aacc9da36c465f506f1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 14 Feb 2023 15:37:59 -0500 Subject: [PATCH] move definition of MAXBIGINT_DOUBLE to variable.cpp --- src/lmptype.h | 5 ----- src/variable.cpp | 9 ++++++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lmptype.h b/src/lmptype.h index a5aa08e390..bf56d07d77 100644 --- a/src/lmptype.h +++ b/src/lmptype.h @@ -95,8 +95,6 @@ typedef int64_t bigint; #define MAXSMALLINT INT_MAX #define MAXTAGINT INT_MAX #define MAXBIGINT INT64_MAX -// INT64_MAX cannot be represented with a double. reduce to avoid overflow when casting back. -#define MAXBIGINT_DOUBLE (INT64_MAX-512) #define MPI_LMP_TAGINT MPI_INT #define MPI_LMP_IMAGEINT MPI_INT @@ -134,8 +132,6 @@ typedef int64_t bigint; #define MAXSMALLINT INT_MAX #define MAXTAGINT INT64_MAX #define MAXBIGINT INT64_MAX -// INT64_MAX cannot be represented with a double. reduce to avoid overflow when casting back. -#define MAXBIGINT_DOUBLE (INT64_MAX-512) #define MPI_LMP_TAGINT MPI_LL #define MPI_LMP_IMAGEINT MPI_LL @@ -172,7 +168,6 @@ typedef int bigint; #define MAXSMALLINT INT_MAX #define MAXTAGINT INT_MAX #define MAXBIGINT INT_MAX -#define MAXBIGINT_DOUBLE INT_MAX #define MPI_LMP_TAGINT MPI_INT #define MPI_LMP_IMAGEINT MPI_INT diff --git a/src/variable.cpp b/src/variable.cpp index d26c0185db..2ac9bd0364 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -73,7 +73,14 @@ enum{DONE,ADD,SUBTRACT,MULTIPLY,DIVIDE,CARAT,MODULO,UNARY, enum{SUM,XMIN,XMAX,AVE,TRAP,SLOPE}; -#define BIG 1.0e20 +static constexpr double BIG = 1.0e20; + +// INT64_MAX cannot be represented with a double. reduce to avoid overflow when casting back. +#if defined(LAMMPS_SMALLBIG) || defined(LAMMPS_BIGBIG) +static constexpr double MAXBIGINT_DOUBLE = (double) (MAXBIGINT-512); +#else +static constexpr double MAXBIGINT_DOUBLE = (double) MAXBIGINT; +#endif // constants for variable expressions. customize by adding new items. // if needed (cf. 'version') initialize in Variable class constructor.