Skip to content

Commit 0fc68ab

Browse files
committed
Avoid loosing decimal float precision, scale and/or sign info when sorting
1 parent 0227ec9 commit 0fc68ab

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/common/DecFloat.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,17 @@ void make(unsigned int* key,
140140
unsigned dig = digits(pMax, coeff, exp);
141141

142142
// exponent bias and sign
143-
exp += (bias + 2);
144143
if (!dig)
145-
exp = 1;
146-
if (sign)
147-
exp = -exp;
144+
{
145+
exp = 0;
146+
sign = 0;
147+
}
148+
else
149+
{
150+
exp += (bias + 2);
151+
if (sign)
152+
exp = -exp;
153+
}
148154
*key++ = exp;
149155

150156
// convert to SLONG
@@ -171,9 +177,7 @@ void grab(unsigned int* key,
171177
sign = DECFLOAT_Sign;
172178
exp = -exp;
173179
}
174-
if (exp == 1)
175-
exp = 0;
176-
else
180+
if (exp != 0)
177181
exp -= (bias + 2);
178182

179183
// convert from SLONG

src/jrd/opt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2453,7 +2453,8 @@ SortedStream* OPT_gen_sort(thread_db* tdbb, CompilerScratch* csb, const StreamLi
24532453
fieldNode->getDesc(tdbb, csb, desc);
24542454

24552455
// International type text has a computed key
2456-
if (IS_INTL_DATA(desc))
2456+
// Different decimal float values sometimes have same keys
2457+
if (IS_INTL_DATA(desc) || desc->isDecFloat())
24572458
break;
24582459

24592460
--items;

src/jrd/recsrc/SortedStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ void SortedStream::mapData(thread_db* tdbb, jrd_req* request, UCHAR* data) const
339339
// a sort key, there is a later nod_field in the item
340340
// list that contains the data to send back
341341

342-
if (IS_INTL_DATA(&item->desc) &&
342+
if ((IS_INTL_DATA(&item->desc) || item->desc.isDecFloat()) &&
343343
(ULONG)(IPTR) item->desc.dsc_address < m_map->keyLength)
344344
{
345345
continue;

0 commit comments

Comments
 (0)