Commit 9d334e56 authored by mattijs's avatar mattijs
Browse files

Merge branch 'develop' of develop.openfoam.com:Development/OpenFOAM-plus into develop

parents 6fd6610b c1c4e91f
......@@ -118,7 +118,8 @@ int main(int argc, char *argv[])
unsigned nFail = 0;
{
Info<< nl << "Test readDouble:" << nl;
Info<< nl << "Test readDouble: (small=" << doubleScalarVSMALL
<< " great=" << doubleScalarVSMALL << "):" << nl;
nFail += testParsing
(
&readDouble,
......@@ -131,12 +132,18 @@ int main(int argc, char *argv[])
{ " 3.14159 ", true },
{ " 31.4159E-1 " , true },
{ " 100E1000 " , false },
{ " 1E-40 " , true },
{ " 1E-305 " , true },
{ " 1E-37 " , true },
{ " 1E-300 " , true },
}
);
}
{
Info<< nl << "Test readFloat:" << nl;
Info<< nl << "Test readFloat: (small=" << floatScalarVSMALL
<< " great=" << floatScalarVGREAT << "):" << nl;
nFail += testParsing
(
&readFloat,
......@@ -145,6 +152,10 @@ int main(int argc, char *argv[])
{ " 31.4159E-1 " , true },
{ " 31.4159E200 " , false },
{ " 31.4159E20 " , true },
{ " 1E-40 " , true },
{ " 1E-305 " , true },
{ " 1E-37 " , true },
{ " 1E-300 " , true },
}
);
}
......@@ -160,12 +171,16 @@ int main(int argc, char *argv[])
{ " 314.159-2 " , true },
{ " 31.4159E200 " , true },
{ " 31.4159E20 " , true },
{ " 1E-40 " , true },
{ " 1E-305 " , true },
{ " 1E-37 " , true },
{ " 1E-300 " , true },
}
);
}
{
Info<< nl << "Test readInt32 (max= " << INT32_MAX << "):" << nl;
Info<< nl << "Test readInt32 (max=" << INT32_MAX << "):" << nl;
nFail += testParsing
(
&readInt32,
......@@ -181,7 +196,7 @@ int main(int argc, char *argv[])
}
{
Info<< nl << "Test readUint32 (max= "
Info<< nl << "Test readUint32 (max="
<< unsigned(UINT32_MAX) << "):" << nl;
nFail += testParsing
(
......
......@@ -80,10 +80,15 @@ Scalar ScalarRead(const char* buf)
{
char* endptr = nullptr;
errno = 0;
const auto parsed = ScalarConvert(buf, &endptr);
const Scalar val = ScalarConvert(buf, &endptr);
const parsing::errorType err =
(
(parsed < -ScalarVGREAT || parsed > ScalarVGREAT)
? parsing::errorType::RANGE
: parsing::checkConversion(buf, endptr)
);
const parsing::errorType err = parsing::checkConversion(buf, endptr);
if (err != parsing::errorType::NONE)
{
FatalIOErrorInFunction("unknown")
......@@ -91,7 +96,13 @@ Scalar ScalarRead(const char* buf)
<< exit(FatalIOError);
}
return val;
// Round underflow to zero
return
(
(parsed > -ScalarVSMALL && parsed < ScalarVSMALL)
? 0
: Scalar(parsed)
);
}
......@@ -99,10 +110,22 @@ bool readScalar(const char* buf, Scalar& val)
{
char* endptr = nullptr;
errno = 0;
val = ScalarConvert(buf, &endptr);
return (parsing::checkConversion(buf, endptr) == parsing::errorType::NONE);
const auto parsed = ScalarConvert(buf, &endptr);
// Round underflow to zero
val =
(
(parsed > -ScalarVSMALL && parsed < ScalarVSMALL)
? 0
: Scalar(parsed)
);
return
(
(parsed < -ScalarVGREAT || parsed > ScalarVGREAT)
? false
: (parsing::checkConversion(buf, endptr) == parsing::errorType::NONE)
);
}
......
......@@ -28,6 +28,7 @@ License
#include "parsing.H"
#include "IOstreams.H"
#include <cstdlib>
#include <sstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -40,7 +41,8 @@ License
#define ScalarROOTVGREAT doubleScalarROOTVGREAT
#define ScalarROOTVSMALL doubleScalarROOTVSMALL
#define ScalarRead readDouble
#define ScalarConvert ::strtod
// Convert using larger representation to properly capture underflow
#define ScalarConvert ::strtold
#include "Scalar.C"
......
......@@ -40,7 +40,8 @@ License
#define ScalarROOTVGREAT floatScalarROOTVGREAT
#define ScalarROOTVSMALL floatScalarROOTVSMALL
#define ScalarRead readFloat
#define ScalarConvert ::strtof
// Convert using larger representation to properly capture underflow
#define ScalarConvert ::strtod
#include "Scalar.C"
......
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