Skip to content

Commit 1313975

Browse files
committed
WIP: printing a double-double in fixed form destroys a leading zero
1 parent 673dffd commit 1313975

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

include/universal/number/dd/dd_impl.hpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,13 @@ class dd {
533533

534534
// trap for improper offset with large values
535535
// without this trap, output of values of the for 10^j - 1 fail for j > 28
536-
// and are output with the point in the wrong place, leading to a dramatically off value
536+
// and are output with the point in the wrong place, leading to a significant error
537537
if (fixed && (precision > 0)) {
538538
// make sure that the value isn't dramatically larger
539539
double from_string = atof(s.c_str());
540540

541541
// if this ratio is large, then we've got problems
542-
if (std::fabs(from_string / this->hi) > 3.0) {
542+
if (std::fabs(from_string / hi) > 3.0) {
543543

544544
// loop on the string, find the point, move it up one
545545
// don't act on the first character
@@ -550,11 +550,13 @@ class dd {
550550
break;
551551
}
552552
}
553+
// BUG: the loop above, in particular s[i-1] = '.', destroys the leading 0
554+
// in the fixed point representation if the point is located at i = 1;
553555

554556
from_string = atof(s.c_str());
555557
// if this ratio is large, then the string has not been fixed
556-
if (std::fabs(from_string / this->hi) > 3.0) {
557-
//error("Re-rounding unsuccessful in large number fixed point trap.");
558+
if (std::fabs(from_string / hi) > 3.0) {
559+
std::cerr << "re-rounding unsuccessful in large number fixed point trap\n";
558560
}
559561
}
560562
}

static/dd/api/api.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ namespace sw {
114114
from *= 10.0) {
115115
dd u = ulp(from);
116116
std::cout << "ulp(" << std::scientific << std::setprecision(0) << from
117-
<< ") gives " //<< to_binary(u) << " : "
118-
<< std::fixed << std::setprecision(6) << u
117+
<< ") gives "
118+
<< std::fixed << std::setprecision(6) << u
119119
<< '\n';
120120
}
121121
}
@@ -447,8 +447,6 @@ try {
447447
std::cout << std::setprecision(defaultPrecision);
448448
}
449449

450-
451-
452450
std::cout << "+--------- double-double subnormal behavior --------+\n";
453451
{
454452
constexpr double minpos = std::numeric_limits<double>::min();

0 commit comments

Comments
 (0)