Skip to content

Commit

Permalink
code hygiene double-double
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Aug 12, 2024
1 parent 39ff10d commit b4aa6df
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 70 deletions.
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ option(BUILD_NUMBER_FIXPNTS "Set to ON to build static fixed-point
option(BUILD_NUMBER_BFLOATS "Set to ON to build static bfloat tests" OFF)
option(BUILD_NUMBER_CFLOATS "Set to ON to build static cfloat tests" OFF)
option(BUILD_NUMBER_DFLOATS "Set to ON to build static dfloat tests" OFF)
option(BUILD_NUMBER_DDS "Set to ON to build static double-double tests" OFF)
option(BUILD_NUMBER_QDS "Set to ON to build static quad-double tests" OFF)
option(BUILD_NUMBER_DOUBLE_DOUBLE "Set to ON to build static double-double tests" OFF)
option(BUILD_NUMBER_QUAD_DOUBLE "Set to ON to build static quad-double tests" OFF)
option(BUILD_NUMBER_AREALS "Set to ON to build static areal tests" OFF)
option(BUILD_NUMBER_UNUM1S "Set to ON to build static unum type 1 tests" OFF)
option(BUILD_NUMBER_UNUM2S "Set to ON to build static unum type 2 tests" OFF)
Expand Down Expand Up @@ -662,8 +662,8 @@ if(BUILD_NUMBER_STATICS)
set(BUILD_NUMBER_BFLOATS ON)
set(BUILD_NUMBER_CFLOATS ON)
set(BUILD_NUMBER_DFLOATS ON)
set(BUILD_NUMBER_DDS ON)
set(BUILD_NUMBER_QDS ON)
set(BUILD_NUMBER_DOUBLE_DOUBLE ON)
set(BUILD_NUMBER_QUAD_DOUBLE ON)
set(BUILD_NUMBER_AREALS ON)
set(BUILD_NUMBER_UNUM1S ON)
set(BUILD_NUMBER_UNUM2S ON)
Expand Down Expand Up @@ -827,14 +827,14 @@ add_subdirectory("static/dfloat")
endif(BUILD_NUMBER_DFLOATS)

# double-double floats
if(BUILD_NUMBER_DDS)
if(BUILD_NUMBER_DOUBLE_DOUBLE)
add_subdirectory("static/dd")
endif(BUILD_NUMBER_DDS)
endif(BUILD_NUMBER_DOUBLE_DOUBLE)

# quad-double floats
if(BUILD_NUMBER_QDS)
if(BUILD_NUMBER_QUAD_DOUBLE)
add_subdirectory("static/qd")
endif(BUILD_NUMBER_QDS)
endif(BUILD_NUMBER_QUAD_DOUBLE)

# conversion tests suites
if(BUILD_NUMBER_CONVERSIONS)
Expand Down
8 changes: 4 additions & 4 deletions include/universal/number/dd/attributes.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
// attributes.hpp: information functions for decimal floating-point type and value attributes
// attributes.hpp: information functions for double-double (dd) floating-point type and value attributes
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
Expand All @@ -8,7 +8,7 @@

namespace sw { namespace universal {

// functions to provide details about the properties of a doubledouble (dd) configuration
// functions to provide details about the properties of a double-double (dd) configuration
inline bool sign(const dd& a) {
return a.sign();
}
Expand All @@ -17,7 +17,7 @@ namespace sw { namespace universal {
return a.scale();
}

// generate the maxneg through maxpos value range of a doubledouble configuration
// generate the maxneg through maxpos value range of a double-double configuration
std::string dd_range() {
dd v;
std::stringstream s;
Expand All @@ -31,7 +31,7 @@ namespace sw { namespace universal {
}

/*
// report dynamic range of a type, specialized for a doubledouble
// report dynamic range of a type, specialized for a double-double
std::string dynamic_range(const dd& a) {
std::stringstream s;
dd b(SpecificValue::maxneg), c(SpecificValue::minneg), d(SpecificValue::minpos), e(SpecificValue::maxpos);
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/dd/dd.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// arbitrary configuration decimal floating-point arithmetic standard header
// double-double floating-point arithmetic standard header
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/dd/dd_fwd.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
// dfloat_fwd.hpp : forward declarations of the decimal floating-point dfloat environment
// dd_fwd.hpp : forward declarations of the double-double (dd) floating-point environment
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
Expand Down
19 changes: 4 additions & 15 deletions include/universal/number/dd/exceptions.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
// exceptions.hpp: definition of arbitrary configuration doubledouble exceptions
// exceptions.hpp: definition of arbitrary configuration double-double exceptions
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
Expand All @@ -9,9 +9,9 @@

namespace sw { namespace universal {

// base class for doubledouble arithmetic exceptions
// base class for double-double arithmetic exceptions
struct dd_arithmetic_exception : public universal_arithmetic_exception {
dd_arithmetic_exception(const std::string& err) : universal_arithmetic_exception(std::string("doubledouble arithmetic exception: ") + err) {};
dd_arithmetic_exception(const std::string& err) : universal_arithmetic_exception(std::string("double-double arithmetic exception: ") + err) {};
};

//////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -57,19 +57,8 @@ struct dd_negative_nroot_arg : public dd_arithmetic_exception {
/// REAL INTERNAL OPERATION EXCEPTIONS

struct dd_internal_exception : public universal_internal_exception {
dd_internal_exception(const std::string& err) : universal_internal_exception(std::string("doubledouble internal exception: ") + err) {};
dd_internal_exception(const std::string& err) : universal_internal_exception(std::string("double-double internal exception: ") + err) {};
};

struct dd_shift_too_large : public dd_internal_exception {
dd_shift_too_large() : dd_internal_exception("shift value too large for given doubledouble") {}
};

struct dd_hpos_too_large : public dd_internal_exception {
dd_hpos_too_large() : dd_internal_exception("position of hidden bit too large for given doubledouble") {}
};

//struct dd_rbits_too_large : dd_internal_exception {
// dd_rbits_too_large(const std::string& error = "number of remaining bits too large for this fraction") :dd_internal_exception(error) {}
//};

}} // namespace sw::universal
12 changes: 6 additions & 6 deletions include/universal/number/dd/math/classify.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
// classify.hpp: classification functions for doubledouble (dd) floating-point
// classify.hpp: classification functions for double-double (dd) floating-point
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
Expand All @@ -14,31 +14,31 @@ int fpclassify(const dd& a) {
}

// STD LIB function for IEEE floats: Determines if the given floating point number arg is a cfloative or negative infinity.
// specialized for doubledouble (dd)
// specialized for double-double (dd)
inline bool isinf(const dd& a) {
return (std::fpclassify(a.high()) == FP_INFINITE);
}

// STD LIB function for IEEE floats: Determines if the given floating point number arg is a not-a-number (NaN) value.
// specialized for doubledouble (dd)
// specialized for double-double (dd)
inline bool isnan(const dd& a) {
return (std::fpclassify(a.high()) == FP_NAN);
}

// STD LIB function for IEEE floats: Determines if the given floating point number arg has finite value i.e. it is normal, subnormal or zero, but not infinite or NaN.
// specialized for doubledouble (dd)
// specialized for double-double (dd)
inline bool isfinite(const dd& a) {
return (std::fpclassify(a.high()) != FP_INFINITE) && (std::fpclassify(a.high()) != FP_NAN);
}

// STD LIB function for IEEE floats: Determines if the given floating point number arg is normal, i.e. is neither zero, subnormal, infinite, nor NaN.
// specialized for doubledouble (dd)
// specialized for double-double (dd)
inline bool isnormal(const dd& a) {
return (std::fpclassify(a.high()) == FP_NORMAL);
}

// STD LIB function for IEEE floats: Determines if the given floating point number arg is denormal, i.e. is neither zero, normal, infinite, nor NaN.
// specialized for doubledouble (dd)
// specialized for double-double (dd)
inline bool isdenorm(const dd& a) {
return (std::fpclassify(a.high()) == FP_SUBNORMAL);
}
Expand Down
8 changes: 7 additions & 1 deletion include/universal/number/dd/math/exponent.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
// exponent.hpp: exponent functions for double-double floating-point
// exponent.hpp: exponent functions for double-double (dd) floating-point
//
// algorithms courtesy Scibuilders, Jack Poulson
//
Expand Down Expand Up @@ -87,8 +87,14 @@ dd exp(const dd& a) {
}

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

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

// Base-e exponential function exp(x)-1
dd expm1(dd x) {
Expand Down
10 changes: 5 additions & 5 deletions include/universal/number/dd/math/logarithm.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
// logarithm.hpp: logarithm functions for doubledouble (dd) floating-point
// logarithm.hpp: logarithm functions for double-double (dd) floating-point
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
Expand Down Expand Up @@ -129,7 +129,7 @@ dd log(dd const& a) {
if (a.isone()) return 0.0;

if (a.sign()) {
// error("(dd::log): Non-positive argument.");
std::cerr << "log: non-positive argument\n";
errno = EDOM;
return std::numeric_limits< dd >::quiet_NaN();
}
Expand All @@ -149,7 +149,7 @@ dd log2(dd const& a)
if (a.isone()) return 0.0;

if (a.sign()) {
// error("(dd_real::log2): Non-positive argument.");
std::cerr << "log2: non-positive argument\n";
errno = EDOM;
return std::numeric_limits< dd >::quiet_NaN();
}
Expand All @@ -169,7 +169,7 @@ dd log10(dd const& a) {
if (a.isone()) return 0.0;

if (a.sign()) {
// error("(dd_real::log10): Non-positive argument.");
std::cerr << "log10: non-positive argument\n";
errno = EDOM;
return std::numeric_limits< dd >::quiet_NaN();
}
Expand All @@ -190,7 +190,7 @@ dd log1p(dd const& a)
if (a == -1.0) return -std::numeric_limits< dd >::infinity();

if (a < -1.0) {
// error("(dd_real::log): Non-positive argument.");
std::cerr << "log1p: non-positive argument\n";
errno = EDOM;
return std::numeric_limits< dd >::quiet_NaN();
}
Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/dd/math/next.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
// next.hpp: nextafter/nexttoward functions for doubledouble floating-point
// next.hpp: nextafter/nexttoward functions for double-double (dd) floating-point
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
Expand Down
80 changes: 54 additions & 26 deletions static/dd/arithmetic/arithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ namespace sw {
}
}

constexpr unsigned labelWidth = 15;
constexpr unsigned precision = 25;
constexpr unsigned gLabelWidth = 15;
constexpr unsigned gPrecision = 25;

double TwoSumTrace(double a, double b, double& r) {
double s = a + b;
Expand All @@ -90,10 +90,10 @@ void TraceTwoSum(double addend) {
b = addend;
s = two_sum(a, b, r);

ReportValue(a, "a", labelWidth, precision);
ReportValue(b, "b", labelWidth, precision);
ReportValue(s, "s", labelWidth, precision);
ReportValue(r, "r", labelWidth, precision);
ReportValue(a, "a", gLabelWidth, gPrecision);
ReportValue(b, "b", gLabelWidth, gPrecision);
ReportValue(s, "s", gLabelWidth, gPrecision);
ReportValue(r, "r", gLabelWidth, gPrecision);
}

void TraceTwoDiff(double differend) {
Expand All @@ -103,10 +103,10 @@ void TraceTwoDiff(double differend) {
b = differend;
s = two_diff(a, b, r);

ReportValue(a, "a", labelWidth, precision);
ReportValue(b, "b", labelWidth, precision);
ReportValue(s, "s", labelWidth, precision);
ReportValue(r, "r", labelWidth, precision);
ReportValue(a, "a", gLabelWidth, gPrecision);
ReportValue(b, "b", gLabelWidth, gPrecision);
ReportValue(s, "s", gLabelWidth, gPrecision);
ReportValue(r, "r", gLabelWidth, gPrecision);
}

void TraceTwoProd(double base, double multiplicant) {
Expand All @@ -116,10 +116,10 @@ void TraceTwoProd(double base, double multiplicant) {
b = multiplicant;
p = two_prod(a, b, r);

ReportValue(a, "a", labelWidth, precision);
ReportValue(b, "b", labelWidth, precision);
ReportValue(p, "p", labelWidth, precision);
ReportValue(r, "r", labelWidth, precision);
ReportValue(a, "a", gLabelWidth, gPrecision);
ReportValue(b, "b", gLabelWidth, gPrecision);
ReportValue(p, "p", gLabelWidth, gPrecision);
ReportValue(r, "r", gLabelWidth, gPrecision);
}

void TestArithmeticOp(const sw::universal::dd& a, sw::universal::RandomsOp op, const sw::universal::dd& b) {
Expand All @@ -143,13 +143,41 @@ void TestArithmeticOp(const sw::universal::dd& a, sw::universal::RandomsOp op, c
c = sqrt(a);
binaryOp = false;
break;
case RandomsOp::OPCODE_NOP:
case RandomsOp::OPCODE_ASSIGN:
case RandomsOp::OPCODE_IPA: // In Place Add
case RandomsOp::OPCODE_IPS: // In Place Sub
case RandomsOp::OPCODE_IPM: // In Place Mul
case RandomsOp::OPCODE_IPD: // In Place Div
case RandomsOp::OPCODE_EXP:
case RandomsOp::OPCODE_EXP2:
case RandomsOp::OPCODE_LOG:
case RandomsOp::OPCODE_LOG2:
case RandomsOp::OPCODE_LOG10:
case RandomsOp::OPCODE_SIN:
case RandomsOp::OPCODE_COS:
case RandomsOp::OPCODE_TAN:
case RandomsOp::OPCODE_ASIN:
case RandomsOp::OPCODE_ACOS:
case RandomsOp::OPCODE_ATAN:
case RandomsOp::OPCODE_SINH:
case RandomsOp::OPCODE_COSH:
case RandomsOp::OPCODE_TANH:
case RandomsOp::OPCODE_ASINH:
case RandomsOp::OPCODE_ACOSH:
case RandomsOp::OPCODE_ATANH:
case RandomsOp::OPCODE_POW:
case RandomsOp::OPCODE_HYPOT:
case RandomsOp::OPCODE_RAN:
std::cerr << "invalid operator: test ignored\n";
break;
default:
std::cerr << "unknown operator: test ignored\n";
break;
}
ReportValue(a, "a", labelWidth, precision);
if (binaryOp) ReportValue(b, "b", labelWidth, precision);
ReportValue(c, "c", labelWidth, precision);
ReportValue(a, "a", gLabelWidth, gPrecision);
if (binaryOp) ReportValue(b, "b", gLabelWidth, gPrecision);
ReportValue(c, "c", gLabelWidth, gPrecision);
}


Expand All @@ -161,9 +189,9 @@ namespace sw {

dd one(1.0);
dd error = one - a * oneOverA;
ReportValue(a, "a", labelWidth, precision);
ReportValue(oneOverA, "1/a", labelWidth, precision);
ReportValue(error, "error", labelWidth, precision);
ReportValue(a, "a", gLabelWidth, gPrecision);
ReportValue(oneOverA, "1/a", gLabelWidth, gPrecision);
ReportValue(error, "error", gLabelWidth, gPrecision);
}

void TestDivisionalIdentity(sw::universal::dd const& a) {
Expand All @@ -172,9 +200,9 @@ namespace sw {

dd one(1.0);
dd error = one - a * oneOverA;
ReportValue(a, "a", labelWidth, precision);
ReportValue(oneOverA, "1/a", labelWidth, precision);
ReportValue(error, "error", labelWidth, precision);
ReportValue(a, "a", gLabelWidth, gPrecision);
ReportValue(oneOverA, "1/a", gLabelWidth, gPrecision);
ReportValue(error, "error", gLabelWidth, gPrecision);
}

void TestRandomReciprocalIdentities(int nrRandoms = 10) {
Expand Down Expand Up @@ -254,9 +282,9 @@ try {

duble min_normal, max_normal;
min_normal.setbits(0x001F'FFFF'FFFF'FFFFull);
ReportValue(min_normal, "min-normal", labelWidth, precision);
ReportValue(min_normal, "min-normal", gLabelWidth, gPrecision);
max_normal.setbits(0x7FEF'FFFF'FFFF'FFFFull);
ReportValue(max_normal, "max-normal", labelWidth, precision);
ReportValue(max_normal, "max-normal", gLabelWidth, gPrecision);


dd a, b, c;
Expand All @@ -268,7 +296,7 @@ try {
TestArithmeticOp(a, RandomsOp::OPCODE_MUL, b);
TestArithmeticOp(a, RandomsOp::OPCODE_DIV, b);

ReportValue(1.0 / b.high(), "one over", labelWidth, precision);
ReportValue(1.0 / b.high(), "one over", gLabelWidth, gPrecision);

std::cout << "\n\n\n";
TestReciprocalIdentity(dd(1.0));
Expand Down
Loading

0 comments on commit b4aa6df

Please sign in to comment.