mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: handle underflow (rounding) of float/double as zero (issue #625)
- The problem occurs when using atof to parse values such as "1e-39" since this is out of range for a float and _can_ set errno to ERANGE. Similar to parsing of integers, now parse with the longest floating point representation "long double" via strtold (guaranteed to be part of C++11) and verify against the respective VGREAT values for overflow. Treat anything smaller than VSMALL to be zero.
This commit is contained in:
@ -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
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user