LeMonADE-project / LeMonADE

Library for Monte Carlo Simulation applying the Bond Fluctuation Model
Other
3 stars 11 forks source link

Bug in Vector3D #69

Closed MartinWenge closed 7 years ago

MartinWenge commented 7 years ago

In the normalize function in contains the function isnan(). This is part of the cmath and should be written with namespace prefix std::isnan() ! If one does not use using namespace std:: somewhere, the compiler complains.

hrabbel commented 7 years ago

Good point. I believe this actually depends on the compiler. As far as I understand, from C++11 onwards the function std::isnan exists, while before isnan was a macro (from C99), and should work without the namespace. I suppose you have compiled your program with a recent compiler, while I was using some old version without C++11 enabled, when I was testing the implementation. I never tried the version using std::isnan with the old compiler, though...

MartinWenge commented 7 years ago

We could introduce the same kind of pre compiler statement as used in RandomNumbersGenerator.h: #define ENABLE_CPP11 ... std::isnan() ?

Or we use the same check as in the Vector function crossproduct and compare the values with themselves? This should be independent from the compiler version: if ( (*this).getX() != (*this).getX() || (*this).getY() != (*this).getY() || (*this).getZ() != (*this).getZ() ) ...

As always, there is also boost to do this task :D if ((boost::math::isnan)(number)) imported from #include <boost\math\special_functions\fpclassify.hpp>

So, what to use? I would prefer the the second version, compare the value with itsself, even if problem with compiler flag --fast-math are known there.

hrabbel commented 7 years ago

Ok, I just tried, and it seems the version with std::isnan is working also for me. Maybe we just use it then? I could include it in the other bugfix (pull requests #66 and #67 )...what do you think?

MartinWenge commented 7 years ago

Yes, you can add this in the branch

hrabbel:bugfix_write_subgroup

then we do not have to change the version number once again :o)