diff --git a/check/features.frm b/check/features.frm index 29301752..834a2d62 100644 --- a/check/features.frm +++ b/check/features.frm @@ -1415,6 +1415,16 @@ assert result("ATANH") =~ expr(" - 6.08698087464190136361e-01*atanh( - 5.4321e-01) ") *--#] evaluate_atanh : +*--#[ 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,-123,0,0,0,0,0,0,0)") +*--#] float_zero : *--#[ float_error : Evaluate; ToFloat; diff --git a/sources/float.c b/sources/float.c index 748de185..7a00439b 100644 --- a/sources/float.c +++ b/sources/float.c @@ -46,6 +46,8 @@ #define GMPSPREAD (GMP_LIMB_BITS/BITSINWORD) +// #define DEBUG + 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 +275,20 @@ 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; - +#ifdef DEBUG + printf("DEBUG: mpf_t internal structure:\n"); + printf(" _mp_prec: %d\n", infloat->_mp_prec); + printf(" _mp_size: %d\n", infloat->_mp_size); + printf(" _mp_exp: %ld\n", infloat->_mp_exp); + printf(" _mp_d: %p\n", (void*)infloat->_mp_d); + printf(" Limb values: "); + nlimbs = infloat->_mp_size < 0 ? -infloat->_mp_size: infloat->_mp_size; + for (i = 0; i < nlimbs; i++) { + printf("%ld ", (unsigned long)infloat->_mp_d[i]); + } + printf("\n Actual value: "); + gmp_printf("%.10Fe\n", infloat); +#endif t = fun; *t++ = FLOATFUN; t++; @@ -316,6 +331,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; @@ -850,6 +867,7 @@ UBYTE *CheckFloat(UBYTE *ss, int *spec) GETIDENTITY UBYTE *s = ss; int zero = 1, gotdot = 0; + if ( *s == '.' && FG.cTable[s[-1]] != 1 && FG.cTable[s[1]] != 1 ) return(ss); while ( FG.cTable[s[-1]] == 1 ) s--; *spec = 0; if ( FG.cTable[*s] == 1 ) { @@ -865,7 +883,7 @@ UBYTE *CheckFloat(UBYTE *ss, int *spec) dot: gotdot = 1; s++; - if ( FG.cTable[*s] != 1 && zero == 1 ) return(ss); + // if ( FG.cTable[*s] != 1 && zero == 1 ) return(ss); while ( *s == '0' ) s++; if ( FG.cTable[*s] == 1 ) { s++; diff --git a/sources/token.c b/sources/token.c index c87307f0..40f0e020 100644 --- a/sources/token.c +++ b/sources/token.c @@ -200,7 +200,7 @@ donumber: i = 0; in2 = CheckFloat(in,&spec); if ( in2 > in ) { if ( spec == 1 ) { - *out++ = TNUMBER; *out++ = 0; s = in2; + *out++ = TNUMBER; *out++ = 0; in = in2; } else if ( spec == -1 ) { MesPrint("&The floating point system has not been started: %s",in);