Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: fixed a few small bugs in MergeWithFloat.
test: added two tests for MergeWithFloat and AddWithFloat.
  • Loading branch information
cbmarini committed Dec 9, 2025
commit 16a289e7ce1eb57995b1881211b5f6922edc64e4
33 changes: 33 additions & 0 deletions check/features.frm
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,39 @@ Print;
assert succeeded?
assert result("F") =~ expr("1.0e+00 + f(a,b,d,3.14e+01) + 2.0e+00*f(30,c,d,-50,b,d,-10,a,d)")
*--#] argument_float :
*--#[ AddWithFloat :
* This tests AddWithFloat in float.c
#StartFloat 10d
Symbol x1,...,x4;
Local F = (x1+1.0*x2+x3+1.0*x4)^5;
id x1 = 1-x2-x3-x4;
Print;
.end
#pend_if wordsize == 2
assert succeeded?
assert result("F") =~ expr("1")
*--#] AddWithFloat :
*--#[ MergeWithFloat :
* This tests MergeWithFloat in float.c
#: termsinsmall 16
On fewerstats 1;
#StartFloat 10d
Auto Symbol x;
* This tests most cases of MergeWithFloat
Local F = (x1+1.0*x2+x3+1.0*x4)^5;
id x1 = 1-x2-x3-x4;
.sort
* This tests a corncer case of MergeWithFloat
Local G = x1+...+x15+1.0*x16+2^320*x16;
Print;
.end
#pend_if wordsize == 2
assert succeeded?
assert result("F") =~ expr("1")
assert result("G") =~ expr("
2.135987036e+96*x16 + x15 + x14 + x13 + x12 + x11 + x10 + x9 + x8 + x7
+ x6 + x5 + x4 + x3 + x2 + x1")
*--#] MergeWithFloat :
*--#[ float_error :
Evaluate;
ToFloat;
Expand Down
31 changes: 12 additions & 19 deletions sources/float.c
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,7 @@ int MergeWithFloat(PHEAD WORD **interm1, WORD **interm2)
{
GETBIDENTITY
WORD *coef1, *coef2, size1, size2, *fun1, *fun2, *fun3, *tt;
WORD sign3,j,jj, *t1, *t2, i, *term1 = *interm1, *term2 = *interm2;
WORD sign3,jj, *t1, *t2, i, *term1 = *interm1, *term2 = *interm2;
int retval = 0;
coef1 = term1+*term1; size1 = coef1[-1]; coef1 -= ABS(size1);
coef2 = term2+*term2; size2 = coef2[-1]; coef2 -= ABS(size2);
Expand Down Expand Up @@ -1899,8 +1899,8 @@ Shift1: t2 = term1 + *term1; tt = t2;
retval = 1;
}
else { /* Here we have to move term1 to the left to make room. */
Over1: jj = fun3[1]-fun1[1]+3-ABS(size1); /* This is positive */
t2 = term1-jj; t1 = term1;
jj = fun3[1]-fun1[1]+3-ABS(size1); /* This is positive */
Over1: t2 = term1-jj; t1 = term1;
while ( t1 < fun1 ) *t2++ = *t1++;
term1 -= jj;
*term1 += jj;
Expand All @@ -1912,25 +1912,18 @@ Over1: jj = fun3[1]-fun1[1]+3-ABS(size1); /* This is positive */
else if ( AT.SortFloatMode == 1 ) {
if ( fun1[1] + ABS(size1) == fun3[1] + 3 ) goto OnTopOf1;
else if ( fun1[1] + ABS(size1) > fun3[1] + 3 ) goto Shift1;
else goto Over1;
else {
jj = fun3[1]-fun1[1]+3-ABS(size1); /* This is positive */
goto Over1;
}
}
else { /* Can only be 2, based on previous tests */
if ( fun3[1] + 3 == ABS(size1) ) {
t2 = coef1; t1 = fun3;
for ( i = 0; i < fun3[1]; i++ ) *t2++ = *t1++;
*t2++ = 1; *t2++ = 1; *t2++ = sign3 < 0 ? -3: 3;
retval = 1;
}
else if ( fun3[1] + 3 < ABS(size1) ) {
j = ABS(size1) - fun3[1] - 3;
t2 = term1 + *term1; tt = t2;
*--t2 = sign3 < 0 ? -3: 3; *--t2 = 1; *--t2 = 1;
t2 -= fun3[1]; t1 = t2-j;
while ( t2 > term1 ) *--t2 = *--t1;
*t2 = tt-t2; term1 = t2;
retval = 1;
if ( fun3[1] + 3 == ABS(size1) ) goto OnTopOf1;
else if ( fun3[1] + 3 < ABS(size1) ) goto Shift1;
else {
jj = fun3[1]+3-ABS(size1); /* This is positive */
goto Over1;
}
else goto Over1;
}
*interm1 = term1;
TermFree(fun3,"MergeWithFloat");
Expand Down