Commit dd63128f authored by peastman's avatar peastman
Browse files

Another attempt at dealing with the fact that some compilers define round() and others don't

parent 8381aaa8
...@@ -33,16 +33,20 @@ ...@@ -33,16 +33,20 @@
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
#include "openmm/internal/SplineFitter.h" #include "openmm/internal/SplineFitter.h"
using namespace OpenMM; #ifdef _MSC_VER
using namespace std;
using Lepton::CustomFunction;
/** /**
* We need to define this ourselves, since Visual Studio is missing round() from cmath. * We need to define this ourselves, since Visual Studio is missing round() from cmath.
*/ */
static int round(double x) { static int round(double x) {
return (int) (x+0.5); return (int) (x+0.5);
} }
#else
#include <cmath>
#endif
using namespace OpenMM;
using namespace std;
using Lepton::CustomFunction;
extern "C" CustomFunction* createReferenceTabulatedFunction(const TabulatedFunction& function) { extern "C" CustomFunction* createReferenceTabulatedFunction(const TabulatedFunction& function) {
if (dynamic_cast<const Continuous1DFunction*>(&function) != NULL) if (dynamic_cast<const Continuous1DFunction*>(&function) != NULL)
...@@ -201,7 +205,7 @@ int ReferenceDiscrete1DFunction::getNumArguments() const { ...@@ -201,7 +205,7 @@ int ReferenceDiscrete1DFunction::getNumArguments() const {
} }
double ReferenceDiscrete1DFunction::evaluate(const double* arguments) const { double ReferenceDiscrete1DFunction::evaluate(const double* arguments) const {
int i = round(arguments[0]); int i = (int) round(arguments[0]);
if (i < 0 || i >= values.size()) if (i < 0 || i >= values.size())
throw OpenMMException("ReferenceDiscrete1DFunction: argument out of range"); throw OpenMMException("ReferenceDiscrete1DFunction: argument out of range");
return values[i]; return values[i];
...@@ -224,8 +228,8 @@ int ReferenceDiscrete2DFunction::getNumArguments() const { ...@@ -224,8 +228,8 @@ int ReferenceDiscrete2DFunction::getNumArguments() const {
} }
double ReferenceDiscrete2DFunction::evaluate(const double* arguments) const { double ReferenceDiscrete2DFunction::evaluate(const double* arguments) const {
int i = round(arguments[0]); int i = (int) round(arguments[0]);
int j = round(arguments[1]); int j = (int) round(arguments[1]);
if (i < 0 || i >= xsize || j < 0 || j >= ysize) if (i < 0 || i >= xsize || j < 0 || j >= ysize)
throw OpenMMException("ReferenceDiscrete2DFunction: argument out of range"); throw OpenMMException("ReferenceDiscrete2DFunction: argument out of range");
return values[i+j*xsize]; return values[i+j*xsize];
...@@ -248,9 +252,9 @@ int ReferenceDiscrete3DFunction::getNumArguments() const { ...@@ -248,9 +252,9 @@ int ReferenceDiscrete3DFunction::getNumArguments() const {
} }
double ReferenceDiscrete3DFunction::evaluate(const double* arguments) const { double ReferenceDiscrete3DFunction::evaluate(const double* arguments) const {
int i = round(arguments[0]); int i = (int) round(arguments[0]);
int j = round(arguments[1]); int j = (int) round(arguments[1]);
int k = round(arguments[2]); int k = (int) round(arguments[2]);
if (i < 0 || i >= xsize || j < 0 || j >= ysize || k < 0 || k >= zsize) if (i < 0 || i >= xsize || j < 0 || j >= ysize || k < 0 || k >= zsize)
throw OpenMMException("ReferenceDiscrete3DFunction: argument out of range"); throw OpenMMException("ReferenceDiscrete3DFunction: argument out of range");
return values[i+(j+k*ysize)*xsize]; return values[i+(j+k*ysize)*xsize];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment