|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73510 - in sandbox/e_float: boost/e_float libs/e_float/build libs/e_float/src/e_float/efx libs/e_float/test/real
From: e_float_at_[hidden]
Date: 2011-08-03 12:44:33
Author: christopher_kormanyos
Date: 2011-08-03 12:44:32 EDT (Wed, 03 Aug 2011)
New Revision: 73510
URL: http://svn.boost.org/trac/boost/changeset/73510
Log:
- Made additional progress toward compatibility with bindings for Boost.Math.
Text files modified:
sandbox/e_float/boost/e_float/e_float_complex.hpp | 23 +++
sandbox/e_float/boost/e_float/e_float_efx.hpp | 54 ++------
sandbox/e_float/libs/e_float/build/MakefileFiles.gmk | 1
sandbox/e_float/libs/e_float/build/e_float.vcxproj | 1
sandbox/e_float/libs/e_float/build/e_float.vcxproj.filters | 3
sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp | 222 ++++++++++++++++++++++++++++++++++++++-
sandbox/e_float/libs/e_float/test/real/test_real.cpp | 2
7 files changed, 253 insertions(+), 53 deletions(-)
Modified: sandbox/e_float/boost/e_float/e_float_complex.hpp
==============================================================================
--- sandbox/e_float/boost/e_float/e_float_complex.hpp (original)
+++ sandbox/e_float/boost/e_float/e_float_complex.hpp 2011-08-03 12:44:32 EDT (Wed, 03 Aug 2011)
@@ -29,11 +29,24 @@
e_float Im;
public:
- ef_complex(const INT32 n) : Re(n), Im(ef::zero()) { }
- ef_complex(const INT64 n) : Re(n), Im(ef::zero()) { }
- ef_complex(const UINT32 u) : Re(u), Im(ef::zero()) { }
- ef_complex(const UINT64 u) : Re(u), Im(ef::zero()) { }
- ef_complex(const double d) : Re(d), Im(ef::zero()) { }
+ ef_complex(const char n) : Re(n), Im(ef::zero()) { }
+ ef_complex(const signed char n) : Re(n), Im(ef::zero()) { }
+ ef_complex(const unsigned char n) : Re(n), Im(ef::zero()) { }
+ ef_complex(const wchar_t n) : Re(n), Im(ef::zero()) { }
+ ef_complex(const signed short n) : Re(n), Im(ef::zero()) { }
+ ef_complex(const unsigned short n) : Re(n), Im(ef::zero()) { }
+ ef_complex(const signed int n) : Re(n), Im(ef::zero()) { }
+ ef_complex(const unsigned int n) : Re(n), Im(ef::zero()) { }
+ ef_complex(const signed long n) : Re(n), Im(ef::zero()) { }
+ ef_complex(const unsigned long n) : Re(n), Im(ef::zero()) { }
+ ef_complex(const signed long long n) : Re(n), Im(ef::zero()) { }
+ ef_complex(const unsigned long long n) : Re(n), Im(ef::zero()) { }
+ ef_complex(const float f) : Re(f), Im(ef::zero()) { }
+ ef_complex(const double d) : Re(d), Im(ef::zero()) { }
+ ef_complex(const long double ld) : Re(ld), Im(ef::zero()) { }
+
+ explicit ef_complex(const char* const s) : Re(s), Im(ef::zero()) { }
+ explicit ef_complex(const std::string& str) : Re(str), Im(ef::zero()) { }
ef_complex(const e_float& re = e_float(), const e_float& im = e_float()) : Re(re), Im(im) { }
ef_complex(const ef_complex& z) : Re(z.Re), Im(z.Im) { }
Modified: sandbox/e_float/boost/e_float/e_float_efx.hpp
==============================================================================
--- sandbox/e_float/boost/e_float/e_float_efx.hpp (original)
+++ sandbox/e_float/boost/e_float/e_float_efx.hpp 2011-08-03 12:44:32 EDT (Wed, 03 Aug 2011)
@@ -65,43 +65,21 @@
fpclass (ef_finite),
prec_elem(ef_elem_number) { }
- e_float(const INT32 n) : data (),
- exp (static_cast<INT64>(0)),
- neg (n < static_cast<INT32>(0)),
- fpclass (ef_finite),
- prec_elem(ef_elem_number)
- {
- from_uint32((!neg) ? static_cast<UINT32>(n) : static_cast<UINT32>(-n));
- }
-
- e_float(const INT64 n) : data (),
- exp (static_cast<INT64>(0)),
- neg (n < static_cast<INT64>(0)),
- fpclass (ef_finite),
- prec_elem(ef_elem_number)
- {
- from_uint64((!neg) ? static_cast<UINT64>(n) : static_cast<UINT64>(-n));
- }
-
- e_float(const UINT32 u) : data (),
- exp (static_cast<INT64>(0)),
- neg (false),
- fpclass (ef_finite),
- prec_elem(ef_elem_number)
- {
- from_uint32(u);
- }
-
- e_float(const UINT64 u) : data (),
- exp (static_cast<INT64>(0)),
- neg (false),
- fpclass (ef_finite),
- prec_elem(ef_elem_number)
- {
- from_uint64(u);
- }
-
+ e_float(const char n);
+ e_float(const signed char n);
+ e_float(const unsigned char n);
+ e_float(const wchar_t n);
+ e_float(const signed short n);
+ e_float(const unsigned short n);
+ e_float(const signed int n);
+ e_float(const unsigned int n);
+ e_float(const signed long n);
+ e_float(const unsigned long n);
+ e_float(const signed long long n);
+ e_float(const unsigned long long n);
+ e_float(const float f);
e_float(const double d);
+ e_float(const long double ld);
e_float(const char* const s);
e_float(const std::string& str);
@@ -120,8 +98,8 @@
static bool data_elem_is_nonzero_predicate(const UINT32& d) { return (d != static_cast<UINT32>(0u)); }
static bool char_is_nonzero_predicate (const char& c) { return (c != static_cast<char>('0')); }
- void from_uint64(const UINT64 u);
- void from_uint32(const UINT32 u);
+ void from_unsigned_long_long(const unsigned long long u);
+ void from_unsigned_long(const unsigned long u);
INT32 cmp_data(const array_type& vd) const;
Modified: sandbox/e_float/libs/e_float/build/MakefileFiles.gmk
==============================================================================
--- sandbox/e_float/libs/e_float/build/MakefileFiles.gmk (original)
+++ sandbox/e_float/libs/e_float/build/MakefileFiles.gmk 2011-08-03 12:44:32 EDT (Wed, 03 Aug 2011)
@@ -70,6 +70,7 @@
FILES_TEST_REAL = ../test/real/test_real \
../test/real/cases/test_case_0000x_overflow_underflow \
../test/real/cases/test_case_0000y_write_to_ostream \
+ ../test/real/cases/test_case_0000z_global_ops_pod \
../test/real/cases/test_case_00011_various_elem_math \
../test/real/cases/test_case_00021_bernoulli \
../test/real/cases/test_case_00051_factorial \
Modified: sandbox/e_float/libs/e_float/build/e_float.vcxproj
==============================================================================
--- sandbox/e_float/libs/e_float/build/e_float.vcxproj (original)
+++ sandbox/e_float/libs/e_float/build/e_float.vcxproj 2011-08-03 12:44:32 EDT (Wed, 03 Aug 2011)
@@ -1034,6 +1034,7 @@
<ClCompile Include="..\test\imag\test_imag.cpp" />
<ClCompile Include="..\test\real\cases\test_case_0000x_overflow_underflow.cpp" />
<ClCompile Include="..\test\real\cases\test_case_0000y_write_to_ostream.cpp" />
+ <ClCompile Include="..\test\real\cases\test_case_0000z_global_ops_pod.cpp" />
<ClCompile Include="..\test\real\cases\test_case_00011_various_elem_math.cpp" />
<ClCompile Include="..\test\real\cases\test_case_00021_bernoulli.cpp" />
<ClCompile Include="..\test\real\cases\test_case_00051_factorial.cpp" />
Modified: sandbox/e_float/libs/e_float/build/e_float.vcxproj.filters
==============================================================================
--- sandbox/e_float/libs/e_float/build/e_float.vcxproj.filters (original)
+++ sandbox/e_float/libs/e_float/build/e_float.vcxproj.filters 2011-08-03 12:44:32 EDT (Wed, 03 Aug 2011)
@@ -376,6 +376,9 @@
<ClCompile Include="..\example\example_008_gauss_laguerre.cpp">
<Filter>libs\e_float\example</Filter>
</ClCompile>
+ <ClCompile Include="..\test\real\cases\test_case_0000z_global_ops_pod.cpp">
+ <Filter>libs\e_float\test\real\cases</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\functions\gamma\gamma_util.h">
Modified: sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp (original)
+++ sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp 2011-08-03 12:44:32 EDT (Wed, 03 Aug 2011)
@@ -52,12 +52,12 @@
public:
native_float_parts(const native_float_type f) : u(0uLL), e(0) { make_parts(f); }
- const UINT64& get_mantissa(void) const { return u; }
- const int& get_exponent(void) const { return e; }
+ const unsigned long long& get_mantissa(void) const { return u; }
+ const int& get_exponent(void) const { return e; }
private:
- UINT64 u;
- int e;
+ unsigned long long u;
+ int e;
native_float_parts();
@@ -91,12 +91,167 @@
}
// Ensure that the value is normalized and adjust the exponent.
- u |= static_cast<UINT64>(1uLL << (std::numeric_limits<native_float_type>::digits - 1));
+ u |= static_cast<unsigned long long>(1uLL << (std::numeric_limits<native_float_type>::digits - 1));
e -= 1;
}
};
}
+efx::e_float::e_float(const char n) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (std::numeric_limits<char>::is_signed ? (n < static_cast<char>(0)) : false),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ from_unsigned_long((!neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n));
+}
+
+efx::e_float::e_float(const signed char n) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (n < static_cast<INT32>(0)),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ from_unsigned_long((!neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n));
+}
+
+efx::e_float::e_float(const unsigned char n) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (false),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ from_unsigned_long(static_cast<unsigned long>(n));
+}
+
+efx::e_float::e_float(const wchar_t n) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (false),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ from_unsigned_long(static_cast<unsigned long>(n));
+}
+
+efx::e_float::e_float(const signed short n) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (n < static_cast<INT32>(0)),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ from_unsigned_long((!neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n));
+}
+
+efx::e_float::e_float(const unsigned short n) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (false),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ from_unsigned_long(static_cast<unsigned long>(n));
+}
+
+efx::e_float::e_float(const signed int n) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (n < 0),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ from_unsigned_long((!neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n));
+}
+
+efx::e_float::e_float(const unsigned int n) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (false),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ from_unsigned_long(n);
+}
+
+efx::e_float::e_float(const signed long n) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (n < static_cast<signed long>(0)),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ from_unsigned_long((!neg) ? static_cast<unsigned long>(n) : static_cast<unsigned long>(-n));
+}
+
+efx::e_float::e_float(const unsigned long n) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (false),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ from_unsigned_long(n);
+}
+
+efx::e_float::e_float(const signed long long n) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (n < static_cast<signed long long>(0)),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ from_unsigned_long_long((!neg) ? static_cast<unsigned long long>(n) : static_cast<UINT64>(-n));
+}
+
+efx::e_float::e_float(const unsigned long long n) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (false),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ from_unsigned_long_long(n);
+}
+
+efx::e_float::e_float(const float f) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (false),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ bool b_neg;
+
+ {
+ const double d = static_cast<double>(f);
+
+ b_neg = ef::isneg(d);
+
+ if(!ef::isfinite(d))
+ {
+ operator=(ef::isnan(d) ? my_value_nan() : ((!ef::isneg(d)) ? my_value_inf() : -my_value_inf()));
+ return;
+ }
+ }
+
+ const native_float_parts<float> fb((!b_neg) ? f : -f);
+
+ // Create an e_float from the fractional part of the
+ // mantissa expressed as an unsigned long long.
+ from_unsigned_long_long(fb.get_mantissa());
+
+ // Scale the UINT64 representation to the fractional part of
+ // the double and multiply with the base-2 exponent.
+ const int p2 = fb.get_exponent() - (std::numeric_limits<float>::digits - 1);
+
+ if(p2 == 0) { }
+ else if((p2 > 0) && (p2 < 27))
+ {
+ mul_by_int(static_cast<INT32>(1uL << p2));
+ }
+ else if((p2 < 0) && (p2 > -27))
+ {
+ div_by_int(static_cast<INT32>(1uL << -p2));
+ }
+ else
+ {
+ operator*=(ef::pow2(static_cast<INT64>(p2)));
+ }
+
+ neg = b_neg;
+}
+
efx::e_float::e_float(const double d) : data (),
exp (static_cast<INT64>(0)),
neg (false),
@@ -108,7 +263,7 @@
if(!ef::isfinite(d))
{
- operator=(ef::isnan(d) ? my_value_nan() : my_value_inf());
+ operator=(ef::isnan(d) ? my_value_nan() : ((!ef::isneg(d)) ? my_value_inf() : -my_value_inf()));
}
else
{
@@ -117,8 +272,8 @@
const native_float_parts<double> db((!b_neg) ? d : -d);
// Create an e_float from the fractional part of the
- // mantissa expressed as a UINT64.
- from_uint64(db.get_mantissa());
+ // mantissa expressed as an unsigned long long.
+ from_unsigned_long_long(db.get_mantissa());
// Scale the UINT64 representation to the fractional part of
// the double and multiply with the base-2 exponent.
@@ -142,6 +297,53 @@
}
}
+efx::e_float::e_float(const long double ld) : data (),
+ exp (static_cast<INT64>(0)),
+ neg (false),
+ fpclass (ef_finite),
+ prec_elem(ef_elem_number)
+{
+ bool b_neg;
+
+ {
+ const double d = static_cast<double>(ld);
+
+ b_neg = ef::isneg(d);
+
+ if(!ef::isfinite(d))
+ {
+ operator=(ef::isnan(d) ? my_value_nan() : ((!ef::isneg(d)) ? my_value_inf() : -my_value_inf()));
+ return;
+ }
+ }
+
+ const native_float_parts<long double> ldb((!b_neg) ? ld : -ld);
+
+ // Create an e_float from the fractional part of the
+ // mantissa expressed as an unsigned long long.
+ from_unsigned_long_long(ldb.get_mantissa());
+
+ // Scale the UINT64 representation to the fractional part of
+ // the double and multiply with the base-2 exponent.
+ const int p2 = ldb.get_exponent() - (std::numeric_limits<long double>::digits - 1);
+
+ if(p2 == 0) { }
+ else if((p2 > 0) && (p2 < 27))
+ {
+ mul_by_int(static_cast<INT32>(1uL << p2));
+ }
+ else if((p2 < 0) && (p2 > -27))
+ {
+ div_by_int(static_cast<INT32>(1uL << -p2));
+ }
+ else
+ {
+ operator*=(ef::pow2(static_cast<INT64>(p2)));
+ }
+
+ neg = b_neg;
+}
+
efx::e_float::e_float(const char* const s) : data (),
exp (static_cast<INT64>(0)),
neg (false),
@@ -242,7 +444,7 @@
}
}
-void efx::e_float::from_uint32(const UINT32 u)
+void efx::e_float::from_unsigned_long(const unsigned long u)
{
std::fill(data.begin(), data.end(), static_cast<UINT32>(0u));
@@ -269,7 +471,7 @@
}
}
-void efx::e_float::from_uint64(const UINT64 u)
+void efx::e_float::from_unsigned_long_long(const unsigned long long u)
{
std::fill(data.begin(), data.end(), static_cast<UINT32>(0u));
Modified: sandbox/e_float/libs/e_float/test/real/test_real.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/test/real/test_real.cpp (original)
+++ sandbox/e_float/libs/e_float/test/real/test_real.cpp 2011-08-03 12:44:32 EDT (Wed, 03 Aug 2011)
@@ -23,6 +23,7 @@
bool test_case_00006_write_os_floatfield_fixed (const bool b_write_output);
bool test_case_00007_write_os_floatfield_scientific(const bool b_write_output);
bool test_case_00008_write_os_floatfield_not_set (const bool b_write_output);
+ bool test_case_00009_global_ops_pod_equal (const bool b_write_output);
bool test_case_00011_various_elem_math (const bool b_write_output);
bool test_case_00021_bernoulli (const bool b_write_output);
bool test_case_00051_factorial (const bool b_write_output);
@@ -68,6 +69,7 @@
test_ok &= test::real::test_case_00006_write_os_floatfield_fixed (b_write_output);
test_ok &= test::real::test_case_00007_write_os_floatfield_scientific(b_write_output);
test_ok &= test::real::test_case_00008_write_os_floatfield_not_set (b_write_output);
+ test_ok &= test::real::test_case_00009_global_ops_pod_equal (b_write_output);
test_ok &= test::real::test_case_00011_various_elem_math (b_write_output);
test_ok &= test::real::test_case_00021_bernoulli (b_write_output);
test_ok &= test::real::test_case_00051_factorial (b_write_output);
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk