Add IEEE 754 single/double precision support to wxDataStream classes.

Allow to optionally raed/write float/double values in IEEE 754 single/double
precision formats, respectively, instead of always using the extended
precision format for both of them.

This makes the code more flexible, allowing for better interoperability with
the other programs, and also allows to implement floating point functions in
these classes even when wxUSE_APPLE_IEEE is turned off (as can be the case
because of the licencing concerns for the code in extended.c).

Closes #10625.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73938 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-05-06 00:31:03 +00:00
parent be2a424da6
commit 789ab84044
6 changed files with 327 additions and 31 deletions

View File

@@ -50,6 +50,17 @@ private:
CPPUNIT_TEST( PseudoTest_UseBigEndian );
CPPUNIT_TEST( FloatRW );
CPPUNIT_TEST( DoubleRW );
// Only test standard IEEE 754 formats if we're using IEEE extended
// format by default, otherwise the tests above already covered them.
#if wxUSE_APPLE_IEEE
CPPUNIT_TEST( PseudoTest_UseIEEE754 );
CPPUNIT_TEST( FloatRW );
CPPUNIT_TEST( DoubleRW );
// Also retest little endian version with standard formats.
CPPUNIT_TEST( PseudoTest_UseLittleEndian );
CPPUNIT_TEST( FloatRW );
CPPUNIT_TEST( DoubleRW );
#endif // wxUSE_APPLE_IEEE
CPPUNIT_TEST_SUITE_END();
wxFloat64 TestFloatRW(wxFloat64 fValue);
@@ -65,8 +76,15 @@ private:
void NaNRW();
void PseudoTest_UseBigEndian() { ms_useBigEndianFormat = true; }
void PseudoTest_UseLittleEndian() { ms_useBigEndianFormat = false; }
#if wxUSE_APPLE_IEEE
void PseudoTest_UseIEEE754() { ms_useIEEE754 = true; }
#endif // wxUSE_APPLE_IEEE
static bool ms_useBigEndianFormat;
#if wxUSE_APPLE_IEEE
static bool ms_useIEEE754;
#endif // wxUSE_APPLE_IEEE
DECLARE_NO_COPY_CLASS(DataStreamTestCase)
};
@@ -78,6 +96,9 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DataStreamTestCase );
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DataStreamTestCase, "DataStreamTestCase" );
bool DataStreamTestCase::ms_useBigEndianFormat = false;
#if wxUSE_APPLE_IEEE
bool DataStreamTestCase::ms_useIEEE754 = false;
#endif // wxUSE_APPLE_IEEE
DataStreamTestCase::DataStreamTestCase()
{
@@ -91,6 +112,11 @@ wxFloat64 DataStreamTestCase::TestFloatRW(wxFloat64 fValue)
if ( ms_useBigEndianFormat )
pDataOutput.BigEndianOrdered(true);
#if wxUSE_APPLE_IEEE
if ( ms_useIEEE754 )
pDataOutput.UseBasicPrecisions();
#endif // wxUSE_APPLE_IEEE
pDataOutput << fValue;
}
@@ -99,6 +125,11 @@ wxFloat64 DataStreamTestCase::TestFloatRW(wxFloat64 fValue)
if ( ms_useBigEndianFormat )
pDataInput.BigEndianOrdered(true);
#if wxUSE_APPLE_IEEE
if ( ms_useIEEE754 )
pDataInput.UseBasicPrecisions();
#endif // wxUSE_APPLE_IEEE
wxFloat64 fInFloat;
pDataInput >> fInFloat;