diff --git a/check/features.frm b/check/features.frm index a1b91032..b5d76612 100644 --- a/check/features.frm +++ b/check/features.frm @@ -1678,7 +1678,19 @@ Print; .end #pend_if wordsize == 2 assert succeeded? -assert result("F") =~ expr("1") +assert result("F") =~ expr("1 + 0.0e+00*x4 + 0.0e+00*x4^2 + 0.0e+00*x4^3 + 0.0e+00*x4^4 + 0.0e+00* + x4^5 + 0.0e+00*x3*x4 + 0.0e+00*x3*x4^2 + 0.0e+00*x3*x4^3 + 0.0e+00*x3* + x4^4 + 0.0e+00*x3^2*x4 + 0.0e+00*x3^2*x4^2 + 0.0e+00*x3^2*x4^3 + 0.0e+00 + *x3^3*x4 + 0.0e+00*x3^3*x4^2 + 0.0e+00*x3^4*x4 + 0.0e+00*x2 + 0.0e+00*x2 + *x4 + 0.0e+00*x2*x4^2 + 0.0e+00*x2*x4^3 + 0.0e+00*x2*x4^4 + 0.0e+00*x2* + x3 + 0.0e+00*x2*x3*x4 + 0.0e+00*x2*x3*x4^2 + 0.0e+00*x2*x3*x4^3 + + 0.0e+00*x2*x3^2 + 0.0e+00*x2*x3^2*x4 + 0.0e+00*x2*x3^2*x4^2 + 0.0e+00*x2 + *x3^3 + 0.0e+00*x2*x3^3*x4 + 0.0e+00*x2*x3^4 + 0.0e+00*x2^2 + 0.0e+00* + x2^2*x4 + 0.0e+00*x2^2*x4^2 + 0.0e+00*x2^2*x4^3 + 0.0e+00*x2^2*x3 + + 0.0e+00*x2^2*x3*x4 + 0.0e+00*x2^2*x3*x4^2 + 0.0e+00*x2^2*x3^2 + 0.0e+00* + x2^2*x3^2*x4 + 0.0e+00*x2^2*x3^3 + 0.0e+00*x2^3 + 0.0e+00*x2^3*x4 + + 0.0e+00*x2^3*x4^2 + 0.0e+00*x2^3*x3 + 0.0e+00*x2^3*x3*x4 + 0.0e+00*x2^3* + x3^2 + 0.0e+00*x2^4 + 0.0e+00*x2^4*x4 + 0.0e+00*x2^4*x3 + 0.0e+00*x2^5") *--#] AddWithFloat : *--#[ float_extremes : #StartFloat 10d @@ -1834,11 +1846,34 @@ Print; .end #pend_if wordsize == 2 assert succeeded? -assert result("F") =~ expr("1") +assert result("F") =~ expr("1 + 0.0e+00*x4 + 0.0e+00*x4^2 + 0.0e+00*x4^3 + 0.0e+00*x4^4 + 0.0e+00* + x4^5 + 0.0e+00*x3*x4 + 0.0e+00*x3*x4^2 + 0.0e+00*x3*x4^3 + 0.0e+00*x3* + x4^4 + 0.0e+00*x3^2*x4 + 0.0e+00*x3^2*x4^2 + 0.0e+00*x3^2*x4^3 + 0.0e+00 + *x3^3*x4 + 0.0e+00*x3^3*x4^2 + 0.0e+00*x3^4*x4 + 0.0e+00*x2 + 0.0e+00*x2 + *x4 + 0.0e+00*x2*x4^2 + 0.0e+00*x2*x4^3 + 0.0e+00*x2*x4^4 + 0.0e+00*x2* + x3 + 0.0e+00*x2*x3*x4 + 0.0e+00*x2*x3*x4^2 + 0.0e+00*x2*x3*x4^3 + + 0.0e+00*x2*x3^2 + 0.0e+00*x2*x3^2*x4 + 0.0e+00*x2*x3^2*x4^2 + 0.0e+00*x2 + *x3^3 + 0.0e+00*x2*x3^3*x4 + 0.0e+00*x2*x3^4 + 0.0e+00*x2^2 + 0.0e+00* + x2^2*x4 + 0.0e+00*x2^2*x4^2 + 0.0e+00*x2^2*x4^3 + 0.0e+00*x2^2*x3 + + 0.0e+00*x2^2*x3*x4 + 0.0e+00*x2^2*x3*x4^2 + 0.0e+00*x2^2*x3^2 + 0.0e+00* + x2^2*x3^2*x4 + 0.0e+00*x2^2*x3^3 + 0.0e+00*x2^3 + 0.0e+00*x2^3*x4 + + 0.0e+00*x2^3*x4^2 + 0.0e+00*x2^3*x3 + 0.0e+00*x2^3*x3*x4 + 0.0e+00*x2^3* + x3^2 + 0.0e+00*x2^4 + 0.0e+00*x2^4*x4 + 0.0e+00*x2^4*x3 + 0.0e+00*x2^5") 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_zero : +#StartFloat 10d +CFunction f; +Local FloatZero = f(0.0,0.0-123,000.000000,0.0e-13,.0e+4,0e1,0.,0.e+2,0e-10); +Print; +.end +#pend_if wordsize == 2 +assert succeeded? +assert result("FloatZero") =~ expr("f(0.0e+00, - 1.23e+02,0.0e+00,0.0e+00,0.0e+00,0.0e+00,0.0e+00,0.0e+00, + 0.0e+00)") +*--#] float_zero : *--#[ float_error : Evaluate; ToFloat; diff --git a/sources/compcomm.c b/sources/compcomm.c index 781be599..440ea9c1 100644 --- a/sources/compcomm.c +++ b/sources/compcomm.c @@ -4285,19 +4285,17 @@ int CoIf(UBYTE *inp) pp = CheckFloat(p,&spec); if ( pp > p ) { /* Got one */ HaveFloat: - if ( spec == 1 ) { /* is zero */ - *w++ = LONGNUMBER; *w++ = 3; *w++ = 0; - } - else if ( spec == -1 ) { + if ( spec == -1 ) { MesPrint("&The floating point system has not been started: %s",p); if ( !error ) error = 1; } else { WORD *ow = AT.WorkPointer; AT.WorkPointer = w; - c = *pp; c = 0; + c = *pp; *pp = 0; ReadFloat((SBYTE *)p); /* Is now at AT.WorkPointer */ *pp = c; + p = pp; AT.WorkPointer[0] = IFFLOATNUMBER; w = AT.WorkPointer + AT.WorkPointer[1]; AT.WorkPointer = ow; diff --git a/sources/float.c b/sources/float.c index 06a2ac80..c496dc30 100644 --- a/sources/float.c +++ b/sources/float.c @@ -46,6 +46,7 @@ #define GMPSPREAD (GMP_LIMB_BITS/BITSINWORD) + void Form_mpf_init(mpf_t t); void Form_mpf_clear(mpf_t t); void Form_mpf_set_prec_raw(mpf_t t,ULONG newprec); @@ -273,7 +274,6 @@ int PackFloat(WORD *fun,mpf_t infloat) mp_limb_t *d = infloat->_mp_d; /* Pointer to the limbs. */ int i; long e = infloat->_mp_exp; - t = fun; *t++ = FLOATFUN; t++; @@ -316,6 +316,8 @@ int PackFloat(WORD *fun,mpf_t infloat) */ nlimbs = infloat->_mp_size < 0 ? -infloat->_mp_size: infloat->_mp_size; if ( nlimbs == 0 ) { + *t++ = -SNUMBER; + *t++ = 0; } else if ( nlimbs == 1 && (ULONG)(*d) < ((ULONG)1)<<(BITSINWORD-1) ) { *t++ = -SNUMBER; @@ -849,31 +851,19 @@ UBYTE *CheckFloat(UBYTE *ss, int *spec) { GETIDENTITY UBYTE *s = ss; - int zero = 1, gotdot = 0; + int gotdot = 0; + /* A single dot is not a valid float */ + if ( *s == '.' && FG.cTable[s[-1]] != 1 && FG.cTable[s[1]] != 1 ) return(ss); while ( FG.cTable[s[-1]] == 1 ) s--; + /* This cannot be a valid float */ + if ( *s != '.' && FG.cTable[*s] != 1 ) return(ss); *spec = 0; - if ( FG.cTable[*s] == 1 ) { - while ( *s == '0' ) s++; - if ( FG.cTable[*s] == 1 ) { - s++; - while ( FG.cTable[*s] == 1 ) s++; - zero = 0; - } - if ( *s == '.' ) { goto dot; } - } - else if ( *s == '.' ) { -dot: + while ( FG.cTable[*s] == 1 ) s++; + if ( *s == '.' ) { gotdot = 1; s++; - if ( FG.cTable[*s] != 1 && zero == 1 ) return(ss); - while ( *s == '0' ) s++; - if ( FG.cTable[*s] == 1 ) { - s++; - while ( FG.cTable[*s] == 1 ) s++; - zero = 0; - } + while ( FG.cTable[*s] == 1 ) s++; } - else return(ss); /* Now we have had the mantissa part, which may be zero. Check for an exponent. @@ -887,12 +877,11 @@ UBYTE *CheckFloat(UBYTE *ss, int *spec) } else { return(ss); } } - else if ( gotdot == 0 ) return(ss); + else if ( gotdot == 0 ) return(ss); /* No radix point and no exponent */ if ( AT.aux_ == 0 ) { /* no floating point system */ *spec = -1; return(s); } - if ( zero ) *spec = 1; return(s); } @@ -1386,24 +1375,14 @@ int CoChop(UBYTE *s) ss = CheckFloat(s, &spec); if ( ss > s ) { /* CheckFloat found a valid float */ - if ( spec == 1 ) { /* Zero */ - MesPrint("&The argument in Chop needs to be larger than 0."); - return(1); - } - else if ( spec == -1 ) { - MesPrint("&The floating point system has not been started."); - return(1); - } - else { - AT.WorkPointer = w; - /* - Reads the floating point number and outputs it at AT.WorkPointer as if it were a float_ - function with its arguments. - */ - ReadFloat((SBYTE *)s); - s = ss; - w += w[1]; - } + AT.WorkPointer = w; + /* + Reads the floating point number and outputs it at AT.WorkPointer as if it were a float_ + function with its arguments. + */ + ReadFloat((SBYTE *)s); + s = ss; + w += w[1]; } else { /* 2: CheckFloat didn't find a float, we now try for rationals and powers */ @@ -1412,10 +1391,6 @@ int CoChop(UBYTE *s) ParseNumber(x,s) mpf_set_ui(aux1,x); } - if ( mpf_sgn(aux1) == 0 ) { - MesPrint("&The argument in Chop needs to be larger than 0."); - return(1); - } while ( *s == ' ' || *s == '\t' ) s++; /* Check for rational number or power*/ if ( *s == '/' || *s == '^' ) { @@ -1703,9 +1678,6 @@ int AddWithFloat(PHEAD WORD **ps1, WORD **ps2) } mpf_add(aux3,aux1,aux2); sign3 = mpf_sgn(aux3); - if ( sign3 == 0 ) { /* May be rare! */ - *ps1 = 0; *ps2 = 0; AT.SortFloatMode = 0; return(0); - } if ( sign3 < 0 ) mpf_neg(aux3,aux3); fun3 = TermMalloc("AddWithFloat"); PackFloat(fun3,aux3); @@ -1822,9 +1794,6 @@ int MergeWithFloat(PHEAD WORD **interm1, WORD **interm2) } mpf_add(aux3,aux1,aux2); sign3 = mpf_sgn(aux3); - if ( sign3 == 0 ) { /* May be very rare! */ - AT.SortFloatMode = 0; return(0); - } /* Now check whether we can park the result on top of one of the input terms. */ diff --git a/sources/token.c b/sources/token.c index 79054ed9..db13575a 100644 --- a/sources/token.c +++ b/sources/token.c @@ -199,10 +199,7 @@ donumber: i = 0; #ifdef WITHFLOAT in2 = CheckFloat(in,&spec); if ( in2 > in ) { - if ( spec == 1 ) { - *out++ = TNUMBER; *out++ = 0; s = in2; - } - else if ( spec == -1 ) { + if ( spec == -1 ) { MesPrint("&The floating point system has not been started: %s",in); if ( !error ) error = 1; } @@ -312,11 +309,7 @@ donumber: i = 0; int spec; s = CheckFloat(in,&spec); if ( s > in ) { - if ( spec == 1 ) { - *out++ = TNUMBER; *out++ = 0; - object = 2; in = s; - } - else if ( spec == -1 ) { + if ( spec == -1 ) { MesPrint("&The floating point system has not been started: %s",in); if ( !error ) error = 1; in++;