Skip to content

Commit

Permalink
resolving all the missing inline keywords on the dd and qd math funct…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
Ravenwater committed Aug 28, 2024
1 parent 4efbc00 commit 94481da
Show file tree
Hide file tree
Showing 45 changed files with 457 additions and 411 deletions.
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -622,13 +622,16 @@ if(BUILD_ALL)
set(BUILD_VALIDATION_HW ON)
endif(BUILD_ALL)

# set the grouped components to build (will trigger builds when tested)
# set the grouped components to build Continuous Integration regression suite
# we are disabling COMPLEX because we need a solution to the
# disappearing support of complex<> for user-defined types
if(BUILD_CI)
set(BUILD_NUMBERS ON)
set(BUILD_DEMONSTRATION OFF)
set(BUILD_NUMERICS OFF)
set(BUILD_MIXEDPRECISION_SDK OFF)
set(BUILD_APP_ENVIRONMENT ON)
set(BUILD_COMPLEX OFF)
endif(BUILD_CI)

# core demonstration example applications that use the library
Expand All @@ -639,8 +642,16 @@ if(BUILD_DEMONSTRATION)
set(BUILD_PLAYGROUND ON)
endif(BUILD_DEMONSTRATION)

# enable complex environment components
if(BUILD_COMPLEX)

# right now, the complex arithmetic and math functions (imag, real, conj)
# are maintained in the individual number system regression suites.
# Their respective build systems will use BUILD_COMPLEX to add/remove
# the complex<> regression suites.

# I am leaving this segment here as a pattern that might drive the development
# of a complex<> replacement that might need its own regression suite
# independent of user-defined types.
endif(BUILD_COMPLEX)

if(BUILD_NUMBERS)
Expand Down
8 changes: 4 additions & 4 deletions include/universal/number/dd/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace sw { namespace universal {
}

// generate the maxneg through maxpos value range of a double-double configuration
std::string dd_range() {
inline std::string dd_range() {
dd v;
std::stringstream s;
s << std::setw(80) << type_tag(v) << " : [ "
Expand Down Expand Up @@ -47,17 +47,17 @@ namespace sw { namespace universal {
}
*/

int minpos_scale(const dd& b) {
inline int minpos_scale(const dd& b) {
dd c(b);
return c.minpos().scale();
}

int maxpos_scale(const dd& b) {
inline int maxpos_scale(const dd& b) {
dd c(b);
return c.maxpos().scale();
}

int max_negative_scale(const dd& b) {
inline int max_negative_scale(const dd& b) {
dd c(b);
return c.maxneg().scale();
}
Expand Down
32 changes: 19 additions & 13 deletions include/universal/number/dd/dd_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ namespace sw { namespace universal {
// this is debug infrastructure: TODO: remove when decimal conversion is solved reliably
constexpr bool bTraceDecimalConversion = false;
constexpr bool bTraceDecimalRounding = false;
std::ostream& operator<<(std::ostream& ostr, const std::vector<char>& s) {
inline std::ostream& operator<<(std::ostream& ostr, const std::vector<char>& s) {
for (auto c : s) {
ostr << c;
}
return ostr;
}

// fwd references to free functions
dd operator-(const dd&, const dd&);
dd operator*(const dd&, const dd&);
dd operator/(const dd&, const dd&);
std::ostream& operator<<(std::ostream&, const dd&);
bool signbit(const dd&);
dd pown(const dd&, int);
dd frexp(const dd&, int*);
dd ldexp(const dd&, int);
inline dd operator-(const dd&, const dd&);
inline dd operator*(const dd&, const dd&);
inline dd operator/(const dd&, const dd&);
inline std::ostream& operator<<(std::ostream&, const dd&);
inline bool signbit(const dd&);
inline dd pown(const dd&, int);
inline dd frexp(const dd&, int*);
inline dd ldexp(const dd&, int);

// dd is an unevaluated pair of IEEE-754 doubles that provides a (1,11,106) floating-point triple
class dd {
Expand Down Expand Up @@ -1184,7 +1184,7 @@ inline dd mul_pwr2(const dd& a, double b) {
// quad-double operators

// quad-double + double-double
void qd_add(double const a[4], const dd& b, double s[4]) {
inline void qd_add(double const a[4], const dd& b, double s[4]) {
double t[5];
s[0] = two_sum(a[0], b.high(), t[0]); // s0 - O( 1 ); t0 - O( e )
s[1] = two_sum(a[1], b.low(), t[1]); // s1 - O( e ); t1 - O( e^2 )
Expand All @@ -1201,7 +1201,7 @@ void qd_add(double const a[4], const dd& b, double s[4]) {
}

// quad-double = double-double * double-double
void qd_mul(const dd& a, const dd& b, double p[4]) {
inline void qd_mul(const dd& a, const dd& b, double p[4]) {
double p4, p5, p6, p7;

// powers of e - 0, 1, 1, 1, 2, 2, 2, 3
Expand Down Expand Up @@ -1278,7 +1278,13 @@ inline dd reciprocal(const dd& a) {
/////////////////////////////////////////////////////////////////////////////
// power functions

dd cbrt(const dd& a) {
/// <summary>
/// cbrt is cube root function, that is, x^1/3
/// </summary>
/// <param name="a">input</param>
/// <returns>cube root of a</returns>
inline dd cbrt(const dd& a) {
using std::pow;
if (!a.isfinite() || a.iszero())
return a; // NaN returns NaN; +/-Inf returns +/-Inf, +/-0.0 returns +/-0.0

Expand Down Expand Up @@ -1377,7 +1383,7 @@ inline std::istream& operator>>(std::istream& istr, dd& v) {
////////////////// string operators

// parse a decimal ASCII floating-point format and make a doubledouble (dd) out of it
bool parse(const std::string& number, dd& value) {
inline bool parse(const std::string& number, dd& value) {
char const* p = number.c_str();

// Skip any leading spaces
Expand Down
4 changes: 2 additions & 2 deletions include/universal/number/dd/manipulators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
namespace sw { namespace universal {

// Generate a type tag for a doubledouble
std::string type_tag(const dd& = {}) {
inline std::string type_tag(const dd& = {}) {
return std::string("double-double");
}

// generate a binary, color-coded representation of the doubledouble
std::string color_print(const dd& r, bool nibbleMarker = false) {
inline std::string color_print(const dd& r, bool nibbleMarker = false) {
std::stringstream s;
double high = r.high();
double low = r.low();
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/dd/math/classify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace sw { namespace universal {

// STD LIB function for IEEE floats: Categorizes floating point value arg into the following categories: zero, subnormal, normal, infinite, NAN, or implementation-defined category.
int fpclassify(const dd& a) {
inline int fpclassify(const dd& a) {
return (std::fpclassify(a.high()));
}

Expand Down
4 changes: 2 additions & 2 deletions include/universal/number/dd/math/error_and_gamma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
namespace sw { namespace universal {

// Compute the error function erf(x) = 2 over sqrt(PI) times Integral from 0 to x of e ^ (-t)^2 dt
dd erf(dd x) {
inline dd erf(dd x) {
return dd(std::erf(double(x.high())));
}

// Compute the complementary error function: 1 - erf(x)
dd erfc(dd x) {
inline dd erfc(dd x) {
return dd(std::erfc(double(x.high())));
}

Expand Down
50 changes: 25 additions & 25 deletions include/universal/number/dd/math/exponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@
namespace sw { namespace universal {

// fwd reference
dd ldexp(dd const&, int);

static const int n_inv_fact = 15;
static const double inv_fact[n_inv_fact][2] = {
{ 1.66666666666666657e-01, 9.25185853854297066e-18}, // 1/3!
{ 4.16666666666666644e-02, 2.31296463463574266e-18}, // 1/4!
{ 8.33333333333333322e-03, 1.15648231731787138e-19}, // 1/5!
{ 1.38888888888888894e-03, -5.30054395437357706e-20}, // 1/6!
{ 1.98412698412698413e-04, 1.72095582934207053e-22}, // 1/7!
{ 2.48015873015873016e-05, 2.15119478667758816e-23}, // 1/8!
{ 2.75573192239858925e-06, -1.85839327404647208e-22}, // 1/9!
{ 2.75573192239858883e-07, 2.37677146222502973e-23}, // 1/10!
{ 2.50521083854417202e-08, -1.44881407093591197e-24}, // 1/11!
{ 2.08767569878681002e-09, -1.20734505911325997e-25}, // 1/12!
{ 1.60590438368216133e-10, 1.25852945887520981e-26}, // 1/13!
{ 1.14707455977297245e-11, 2.06555127528307454e-28}, // 1/14!
{ 7.64716373181981641e-13, 7.03872877733453001e-30}, // 1/15!
{ 4.77947733238738525e-14, 4.39920548583408126e-31}, // 1/16!
{ 2.81145725434552060e-15, 1.65088427308614326e-31} // 1/17!
inline dd ldexp(const dd&, int);

static const int dd_inverse_factorial_table_size = 15;
static const dd dd_inverse_factorial[dd_inverse_factorial_table_size] = {
dd(1.66666666666666657e-01, 9.25185853854297066e-18), // 1/3!
dd(4.16666666666666644e-02, 2.31296463463574266e-18), // 1/4!
dd(8.33333333333333322e-03, 1.15648231731787138e-19), // 1/5!
dd(1.38888888888888894e-03, -5.30054395437357706e-20), // 1/6!
dd(1.98412698412698413e-04, 1.72095582934207053e-22), // 1/7!
dd(2.48015873015873016e-05, 2.15119478667758816e-23), // 1/8!
dd(2.75573192239858925e-06, -1.85839327404647208e-22), // 1/9!
dd(2.75573192239858883e-07, 2.37677146222502973e-23), // 1/10!
dd(2.50521083854417202e-08, -1.44881407093591197e-24), // 1/11!
dd(2.08767569878681002e-09, -1.20734505911325997e-25), // 1/12!
dd(1.60590438368216133e-10, 1.25852945887520981e-26), // 1/13!
dd(1.14707455977297245e-11, 2.06555127528307454e-28), // 1/14!
dd(7.64716373181981641e-13, 7.03872877733453001e-30), // 1/15!
dd(4.77947733238738525e-14, 4.39920548583408126e-31), // 1/16!
dd(2.81145725434552060e-15, 1.65088427308614326e-31) // 1/17!
};

// Base-e exponential function
dd exp(const dd& a) {
inline dd exp(const dd& a) {
/* Strategy: We first reduce the size of x by noting that
exp(kr + m * log(2)) = 2^m * exp(r)^k
Expand Down Expand Up @@ -61,13 +61,13 @@ dd exp(const dd& a) {
p = sqr(r);
s = r + mul_pwr2(p, 0.5);
p *= r;
t = p * dd(inv_fact[0][0], inv_fact[0][1]);
t = p * dd_inverse_factorial[0];
int i = 0;
do {
s += t;
p *= r;
++i;
t = p * dd(inv_fact[i][0], inv_fact[i][1]);
t = p * dd_inverse_factorial[i];
} while (std::abs(double(t)) > inv_k * dd_eps && i < 5);

s += t;
Expand All @@ -87,17 +87,17 @@ dd exp(const dd& a) {
}

// Base-2 exponential function
dd exp2(dd x) {
inline dd exp2(dd x) {
return dd(std::exp2(double(x)));
}

// Base-10 exponential function
dd exp10(dd x) {
inline dd exp10(dd x) {
return dd(std::pow(10.0, double(x)));
}

// Base-e exponential function exp(x)-1
dd expm1(dd x) {
inline dd expm1(dd x) {
return dd(std::expm1(double(x)));
}

Expand Down
4 changes: 2 additions & 2 deletions include/universal/number/dd/math/fractional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
namespace sw { namespace universal {

// fmod retuns x - n*y where n = x/y with the fractional part truncated
dd fmod(dd x, dd y) {
inline dd fmod(dd x, dd y) {
return dd(std::fmod(double(x), double(y)));
}

// shim to stdlib
dd remainder(dd x, dd y) {
inline dd remainder(dd x, dd y) {
return dd(std::remainder(double(x), double(y)));
}

Expand Down
12 changes: 6 additions & 6 deletions include/universal/number/dd/math/hyperbolic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@
namespace sw { namespace universal {

// hyperbolic sine of an angle of x radians
dd sinh(dd x) {
inline dd sinh(dd x) {
return dd(std::sinh(double(x)));
}

// hyperbolic cosine of an angle of x radians
dd cosh(dd x) {
inline dd cosh(dd x) {
return dd(std::cosh(double(x)));
}

// hyperbolic tangent of an angle of x radians
dd tanh(dd x) {
inline dd tanh(dd x) {
return dd(std::tanh(double(x)));
}

// hyperbolic cotangent of an angle of x radians
dd atanh(dd x) {
inline dd atanh(dd x) {
return dd(std::atanh(double(x)));
}

// hyperbolic cosecant of an angle of x radians
dd acosh(dd x) {
inline dd acosh(dd x) {
return dd(std::acosh(double(x)));
}

// hyperbolic secant of an angle of x radians
dd asinh(dd x) {
inline dd asinh(dd x) {
return dd(std::asinh(double(x)));
}

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/dd/math/hypot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace sw { namespace universal {

dd hypot(dd x, dd y) {
inline dd hypot(dd x, dd y) {
return dd(std::hypot(double(x), double(y)));
}

Expand Down
Loading

0 comments on commit 94481da

Please sign in to comment.