|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73531 - in sandbox/e_float: boost/e_float libs/e_float/src/e_float/efx libs/e_float/src/functions/elementary
From: e_float_at_[hidden]
Date: 2011-08-04 13:27:31
Author: christopher_kormanyos
Date: 2011-08-04 13:27:30 EDT (Thu, 04 Aug 2011)
New Revision: 73531
URL: http://svn.boost.org/trac/boost/changeset/73531
Log:
- Added missing functions such as frexp, ldexp, etc (has-its-own mechanism still missing).
- Made efx::e_float's make-functions from unsigned long and unsigned long long portable.
Text files modified:
sandbox/e_float/boost/e_float/e_float_elementary_math.hpp | 3 +
sandbox/e_float/libs/e_float/src/e_float/efx/e_float_efx.cpp | 78 ++++++++++++++++++---------------------
sandbox/e_float/libs/e_float/src/functions/elementary/elementary_math.cpp | 38 +++++++++++++++---
3 files changed, 70 insertions(+), 49 deletions(-)
Modified: sandbox/e_float/boost/e_float/e_float_elementary_math.hpp
==============================================================================
--- sandbox/e_float/boost/e_float/e_float_elementary_math.hpp (original)
+++ sandbox/e_float/boost/e_float/e_float_elementary_math.hpp 2011-08-04 13:27:30 EDT (Thu, 04 Aug 2011)
@@ -22,6 +22,9 @@
e_float floor(const e_float& x);
e_float ceil (const e_float& x);
INT32 sgn (const e_float& x);
+ e_float ldexp(const e_float& v, int e);
+ e_float frexp(const e_float& v, int* expon);
+ e_float fmod (const e_float& v1, const e_float& v2);
bool isnan(const double x);
inline bool isnan(const e_float& x) { return x.isnan(); }
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-04 13:27:30 EDT (Thu, 04 Aug 2011)
@@ -448,62 +448,56 @@
{
std::fill(data.begin(), data.end(), static_cast<UINT32>(0u));
- if(u != static_cast<UINT32>(0u))
- {
- const UINT32 data_med = static_cast<UINT32>(u / static_cast<UINT32>(ef_elem_mask));
- const UINT32 data_lo = static_cast<UINT32>(u % static_cast<UINT32>(ef_elem_mask));
+ exp = static_cast<INT64>(0);
- if(data_med != static_cast<UINT32>(0u))
- {
- data[0] = data_med;
- data[1] = data_lo;
- exp = static_cast<INT64>(ef_elem_digits10);
- }
- else
- {
- data[0] = data_lo;
- exp = static_cast<INT64>(0);
- }
+ std::size_t i = 0u;
+
+ unsigned long uu = u;
+
+ UINT32 temp[(std::numeric_limits<unsigned long>::digits10 / static_cast<int>(ef_elem_digits10)) + 3] = { static_cast<UINT32>(0u) };
+
+ while(uu != static_cast<unsigned long>(0u))
+ {
+ temp[i] = static_cast<UINT32>(uu % static_cast<unsigned long>(ef_elem_mask));
+ uu = static_cast<unsigned long>(uu / static_cast<unsigned long>(ef_elem_mask));
+ ++i;
}
- else
+
+ if(i > static_cast<std::size_t>(1u))
{
- exp = static_cast<INT64>(0);
+ exp += static_cast<INT64>((i - 1u) * static_cast<std::size_t>(ef_elem_digits10));
}
+
+ std::reverse(temp, temp + i);
+ std::copy(temp, temp + (std::min)(i, static_cast<std::size_t>(ef_elem_number)), data.begin());
}
void efx::e_float::from_unsigned_long_long(const unsigned long long u)
{
std::fill(data.begin(), data.end(), static_cast<UINT32>(0u));
- if(u != static_cast<UINT64>(0u))
- {
- const UINT32 data_hi = static_cast<UINT32>(static_cast<UINT64>(u / static_cast<UINT32>(ef_elem_mask)) / static_cast<UINT32>(ef_elem_mask));
- const UINT32 data_med = static_cast<UINT32>( (u / static_cast<UINT32>(ef_elem_mask)) % static_cast<UINT32>(ef_elem_mask));
- const UINT32 data_lo = static_cast<UINT32>( u % static_cast<UINT32>(ef_elem_mask));
+ exp = static_cast<INT64>(0);
- if(data_hi != static_cast<UINT32>(0u))
- {
- data[0] = data_hi;
- data[1] = data_med;
- data[2] = data_lo;
- exp = static_cast<INT64>(2 * static_cast<INT32>(ef_elem_digits10));
- }
- else if(data_med != static_cast<UINT32>(0u))
- {
- data[0] = data_med;
- data[1] = data_lo;
- exp = static_cast<INT64>(ef_elem_digits10);
- }
- else
- {
- data[0] = data_lo;
- exp = static_cast<INT64>(0);
- }
+ std::size_t i = 0u;
+
+ unsigned long long uu = u;
+
+ UINT32 temp[(std::numeric_limits<unsigned long long>::digits10 / static_cast<int>(ef_elem_digits10)) + 3] = { static_cast<UINT32>(0u) };
+
+ while(uu != static_cast<unsigned long long>(0u))
+ {
+ temp[i] = static_cast<UINT32>(uu % static_cast<unsigned long long>(ef_elem_mask));
+ uu = static_cast<unsigned long long>(uu / static_cast<unsigned long long>(ef_elem_mask));
+ ++i;
}
- else
+
+ if(i > static_cast<std::size_t>(1u))
{
- exp = static_cast<INT64>(0);
+ exp += static_cast<INT64>((i - 1u) * static_cast<std::size_t>(ef_elem_digits10));
}
+
+ std::reverse(temp, temp + i);
+ std::copy(temp, temp + (std::min)(i, static_cast<std::size_t>(ef_elem_number)), data.begin());
}
void efx::e_float::mul_loop_uv(const UINT32* const u, const UINT32* const v, UINT32* const w, const INT32 p)
Modified: sandbox/e_float/libs/e_float/src/functions/elementary/elementary_math.cpp
==============================================================================
--- sandbox/e_float/libs/e_float/src/functions/elementary/elementary_math.cpp (original)
+++ sandbox/e_float/libs/e_float/src/functions/elementary/elementary_math.cpp 2011-08-04 13:27:30 EDT (Thu, 04 Aug 2011)
@@ -20,16 +20,16 @@
{
if(!ef::isfinite(x) || ef::isint(x)) { return x; }
- return ef::isneg(x) ? ef::integer_part(x - ef::one())
- : ef::integer_part(x);
+ return (ef::isneg(x) ? ef::integer_part(x - ef::one())
+ : ef::integer_part(x));
}
e_float ef::ceil(const e_float& x)
{
if(!ef::isfinite(x) || ef::isint(x)) { return x; }
- return ef::isneg(x) ? ef::integer_part(x)
- : ef::integer_part(x + ef::one());
+ return (ef::isneg(x) ? ef::integer_part(x)
+ : ef::integer_part(x + ef::one()));
}
INT32 ef::sgn(const e_float& x)
@@ -44,6 +44,30 @@
}
}
+e_float ldexp(const e_float& v, int e)
+{
+ return v * ef::pow2(e);
+}
+
+e_float ef::frexp(const e_float& v, int* expon)
+{
+ double d;
+ INT64 i;
+
+ v.extract_parts(d, i);
+
+ *expon = static_cast<int>(i);
+
+ return v * ef::pow2(static_cast<INT64>(-i));
+}
+
+e_float ef::fmod(const e_float& v1, const e_float& v2)
+{
+ const e_float n = (ef::isneg(v1) ? ef::ceil(v1 / v2) : ef::floor(v1 / v2));
+
+ return v1 - (n * v2);
+}
+
bool ef::isfinite(const double x) { return static_cast<INT32>(::_finite(x)) == static_cast<INT32>(1); }
bool ef::isnan (const double x) { return static_cast<INT32>(::_isnan (x)) == static_cast<INT32>(1); }
@@ -134,7 +158,7 @@
static const INT64 lim_n = static_cast<INT64>(lim_d);
static const INT64 lim = (lim_n < 6 ? 6 : lim_n);
- return x.order() < -lim;
+ return (x.order() < static_cast<INT64>(-lim));
}
bool ef::small_arg(const ef_complex& z)
@@ -148,7 +172,7 @@
static const double small_tol = ::pow(std::numeric_limits<double>::epsilon(), one_sixth);
static const double large_tol = 1.0 / small_tol;
- return ::fabs(x) > large_tol;
+ return (::fabs(x) > large_tol);
}
bool ef::large_arg(const e_float& x)
@@ -157,7 +181,7 @@
static const INT64 lim_n = static_cast<INT64>(lim_d);
static const INT64 lim = (lim_n < 6 ? 6 : lim_n);
- return x.order() > lim;
+ return (x.order() > lim);
}
bool ef::large_arg(const ef_complex& z) { return ef::large_arg(z.real()); }
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