diff --git a/applications/test/sigFpe/Make/files b/applications/test/sigFpe/Make/files new file mode 100644 index 0000000000000000000000000000000000000000..f2c4215e4a538264c594e9924a3d25cd77e0d9a6 --- /dev/null +++ b/applications/test/sigFpe/Make/files @@ -0,0 +1,3 @@ +Test-sigFpe.C + +EXE = $(FOAM_USER_APPBIN)/Test-sigFpe diff --git a/applications/test/sigFpe/Make/options b/applications/test/sigFpe/Make/options new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/applications/test/sigFpe/Test-sigFpe.C b/applications/test/sigFpe/Test-sigFpe.C new file mode 100644 index 0000000000000000000000000000000000000000..5c41249bc1ed63ed02d3b30c6a335d171edd577d --- /dev/null +++ b/applications/test/sigFpe/Test-sigFpe.C @@ -0,0 +1,83 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 Bernhard Gschaider + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Application + Test-sigFpe + +Description + Test handling of floating point exceptions by provoking them + +\*---------------------------------------------------------------------------*/ + +#include "OSspecific.H" +#include "IOstreams.H" +#include "scalar.H" +#include "sigFpe.H" +#include "argList.H" + +#include <cmath> + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + argList::addBoolOption("fill-nan", "Test filling memory with NaN"); + argList args(argc, argv); + + // Force on + sigFpe::unset(); + setEnv("FOAM_SIGFPE", "true", true); + // setEnv("FOAM_SETNAN", "true", true); + + sigFpe::set(true); + + if (args.found("fill-nan")) + { + Info<< nl << "Checking filling with NaN" << endl; + scalar* data = new scalar[10]; + + scalar first = data[0]; + + Info<< "First element " << first << endl; + Info<< "First element times two " << 2*first << endl; + + delete[] data; + } + else + { + Info<< nl << "Provoking sigFpe (division by zero)" << nl << endl; + + // Writing 1./0. might be optimized away by the compiler + + const scalar zeroVal = ::sin(0.0); + Info << "Infinity " << 1./zeroVal << endl; + } + + return 0; +} + + +// ************************************************************************* //