diff --git a/check/features.frm b/check/features.frm index d729bfd7..a1b91032 100644 --- a/check/features.frm +++ b/check/features.frm @@ -662,13 +662,13 @@ assert stdout =~ exact_pattern(<<'EOF') G1 = float_(10,10,1,225649930152063087544280124519603661924016376904153173222\ 961313295752588365049496190204609112667217257624737508104376810254484309\ - 3830597279756558899541412580219255737022507716035); + 3830597279756558899541412586941038636793415360118); EOF assert stdout =~ exact_pattern(<<'EOF') G2 = float_(10,10,1,247337966873870703631573653423368526098272821023387457752\ 643030990710929556575503489173572446024607642191456056189912528713904095\ - 704444384800390830056125051605311704862654126); + 704444384800390830056125051897088334731440434); EOF *--#] Float_1 : *--#[ evaluate_symbol : @@ -766,7 +766,7 @@ L F = mzv_(2); .sort Hide; -#do digits=1,20 +#do digits=1,10 #StartFloat `digits'd,MZV=2 Local F`digits' = F; Evaluate mzv_; @@ -775,6 +775,16 @@ Hide; Hide; #endfloat #enddo +* The following checks that a new StartFloat without a previous +* EndFloat causes no problems. +#do digits=11,20 + #StartFloat `digits'd,MZV=2 + Local F`digits' = F; + Evaluate mzv_; + Print; + .sort + Hide; +#enddo .end #pend_if wordsize == 2 assert result("F1") =~ expr("2e+00") @@ -909,7 +919,7 @@ assert result("EULER3") =~ expr(" - 3.888958461681063290997e-01*euler(-1,-2) + 2.140723708667062274342e-01*euler(-1,-1,-1) - 5.372131936080402009406e-01*euler(-1,-1,1) - + 9.475300423012770572182e-02*euler(-1,1,-1) + + 9.475300423012770572183e-02*euler(-1,1,-1) - 5.550410866482157995314e-02*euler(-1,1,1) + 2.695764795315278073874e-01*euler(-1,2) - 5.082152128046848508121e-01*euler(2,-1) @@ -983,7 +993,7 @@ assert result("MZVHALF1") =~ expr(" +6.931471805599453094172e-01*mzvhalf(1) ") assert result("MZVHALF2") =~ expr(" - +2.402265069591007123335e-01*mzvhalf(1,1) + +2.402265069591007123336e-01*mzvhalf(1,1) + 5.822405264650125059027e-01*mzvhalf(2) ") assert result("MZVHALF3") =~ expr(" @@ -1453,7 +1463,7 @@ assert result("ATANH") =~ expr(" - 6.08698087464190136361e-01*atanh( - 5.4321e-01) ") *--#] evaluate_atanh : -*--#[ strictrounding : +*--#[ strictrounding_1 : #StartFloat 6d CFunction f; Local F1 = 1.23456789e-4+f(1.0)+f(1.0000001); @@ -1472,7 +1482,37 @@ Print; assert succeeded? assert result("F1") =~ expr("1.23457e-04 + f(1.0e+00) + f(1.0e+00)") assert result("F2") =~ expr("1.235e-04 + 2*f(1.0e+00)") -*--#] strictrounding : +*--#] strictrounding_1 : +*--#[ strictrounding_2 : +#StartFloat 20b +CFunction f; +Local F = 1.1e-4; +StrictRounding 5b; +.sort + +#EndFloat +#StartFloat 40d +Print; +.end +#pend_if wordsize == 2 +assert succeeded? +assert result("F") =~ expr("1.10626220703125e-04") +*--#] strictrounding_2 : +*--#[ strictrounding_error: +#- +StrictRounding; +#StartFloat 10d +StrictRounding 5; +StrictRounding d5; +StrictRounding 5 d; +.end +#pend_if wordsize == 2 +runtime_error?("Illegal attempt for strict rounding without activating floating point numbers.") +runtime_error?("Forgotten #startfloat instruction?") +runtime_error?("Illegal argument(s) in StrictRounding statement: ''") +runtime_error?("Illegal argument(s) in StrictRounding statement: 'd5'") +runtime_error?("Illegal argument(s) in StrictRounding statement: ',d'") +*--#] strictrounding_error : *--#[ chop : #StartFloat 15d #StartFloat 15d @@ -1628,6 +1668,177 @@ 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 : +*--#[ float_extremes : +#StartFloat 10d +CFunction f; +#do i = 0,62 + Local F`i' = 1.`i'e{2^`i'}*f({2^`i'}); + Local G`i' = 1.`i'e{-2^`i'}*f({2^`i'}); +#enddo +Print; +.end +#pend_if wordsize == 2 +assert succeeded? +assert result("F0") =~ expr("1.0e+01*f(1)") +assert result("G0") =~ expr("1.0e-01*f(1)") +assert result("F1") =~ expr("1.1e+02*f(2)") +assert result("G1") =~ expr("1.1e-02*f(2)") +assert result("F2") =~ expr("1.2e+04*f(4)") +assert result("G2") =~ expr("1.2e-04*f(4)") +assert result("F3") =~ expr("1.3e+08*f(8)") +assert result("G3") =~ expr("1.3e-08*f(8)") +assert result("F4") =~ expr("1.4e+16*f(16)") +assert result("G4") =~ expr("1.4e-16*f(16)") +assert result("F5") =~ expr("1.5e+32*f(32)") +assert result("G5") =~ expr("1.5e-32*f(32)") +assert result("F6") =~ expr("1.6e+64*f(64)") +assert result("G6") =~ expr("1.6e-64*f(64)") +assert result("F7") =~ expr("1.7e+128*f(128)") +assert result("G7") =~ expr("1.7e-128*f(128)") +assert result("F8") =~ expr("1.8e+256*f(256)") +assert result("G8") =~ expr("1.8e-256*f(256)") +assert result("F9") =~ expr("1.9e+512*f(512)") +assert result("G9") =~ expr("1.9e-512*f(512)") +assert result("F10") =~ expr("1.1e+1024*f(1024)") +assert result("G10") =~ expr("1.1e-1024*f(1024)") +assert result("F11") =~ expr("1.11e+2048*f(2048)") +assert result("G11") =~ expr("1.11e-2048*f(2048)") +assert result("F12") =~ expr("1.12e+4096*f(4096)") +assert result("G12") =~ expr("1.12e-4096*f(4096)") +assert result("F13") =~ expr("1.13e+8192*f(8192)") +assert result("G13") =~ expr("1.13e-8192*f(8192)") +assert result("F14") =~ expr("1.14e+16384*f(16384)") +assert result("G14") =~ expr("1.14e-16384*f(16384)") +assert result("F15") =~ expr("1.15e+32768*f(32768)") +assert result("G15") =~ expr("1.15e-32768*f(32768)") +assert result("F16") =~ expr("1.16e+65536*f(65536)") +assert result("G16") =~ expr("1.16e-65536*f(65536)") +assert result("F17") =~ expr("1.17e+131072*f(131072)") +assert result("G17") =~ expr("1.17e-131072*f(131072)") +assert result("F18") =~ expr("1.18e+262144*f(262144)") +assert result("G18") =~ expr("1.18e-262144*f(262144)") +assert result("F19") =~ expr("1.19e+524288*f(524288)") +assert result("G19") =~ expr("1.19e-524288*f(524288)") +assert result("F20") =~ expr("1.2e+1048576*f(1048576)") +assert result("G20") =~ expr("1.2e-1048576*f(1048576)") +assert result("F21") =~ expr("1.21e+2097152*f(2097152)") +assert result("G21") =~ expr("1.21e-2097152*f(2097152)") +assert result("F22") =~ expr("1.22e+4194304*f(4194304)") +assert result("G22") =~ expr("1.22e-4194304*f(4194304)") +assert result("F23") =~ expr("1.23e+8388608*f(8388608)") +assert result("G23") =~ expr("1.23e-8388608*f(8388608)") +assert result("F24") =~ expr("1.24e+16777216*f(16777216)") +assert result("G24") =~ expr("1.24e-16777216*f(16777216)") +assert result("F25") =~ expr("1.25e+33554432*f(33554432)") +assert result("G25") =~ expr("1.25e-33554432*f(33554432)") +assert result("F26") =~ expr("1.26e+67108864*f(67108864)") +assert result("G26") =~ expr("1.26e-67108864*f(67108864)") +assert result("F27") =~ expr("1.27e+134217728*f(134217728)") +assert result("G27") =~ expr("1.27e-134217728*f(134217728)") +assert result("F28") =~ expr("1.28e+268435456*f(268435456)") +assert result("G28") =~ expr("1.28e-268435456*f(268435456)") +assert result("F29") =~ expr("1.29e+536870912*f(536870912)") +assert result("G29") =~ expr("1.29e-536870912*f(536870912)") +assert result("F30") =~ expr("1.3e+1073741824*f(1073741824)") +assert result("G30") =~ expr("1.3e-1073741824*f(1073741824)") +assert result("F31") =~ expr("1.31e+2147483648*f(2147483648)") +assert result("G31") =~ expr("1.31e-2147483648*f(2147483648)") +assert result("F32") =~ expr("1.32e+4294967296*f(4294967296)") +assert result("G32") =~ expr("1.32e-4294967296*f(4294967296)") +assert result("F33") =~ expr("1.33e+8589934592*f(8589934592)") +assert result("G33") =~ expr("1.33e-8589934592*f(8589934592)") +assert result("F34") =~ expr("1.34e+17179869184*f(17179869184)") +assert result("G34") =~ expr("1.34e-17179869184*f(17179869184)") +assert result("F35") =~ expr("1.35e+34359738368*f(34359738368)") +assert result("G35") =~ expr("1.35e-34359738368*f(34359738368)") +assert result("F36") =~ expr("1.36e+68719476736*f(68719476736)") +assert result("G36") =~ expr("1.36e-68719476736*f(68719476736)") +assert result("F37") =~ expr("1.37e+137438953472*f(137438953472)") +assert result("G37") =~ expr("1.37e-137438953472*f(137438953472)") +assert result("F38") =~ expr("1.38e+274877906944*f(274877906944)") +assert result("G38") =~ expr("1.38e-274877906944*f(274877906944)") +assert result("F39") =~ expr("1.39e+549755813888*f(549755813888)") +assert result("G39") =~ expr("1.39e-549755813888*f(549755813888)") +assert result("F40") =~ expr("1.4e+1099511627776*f(1099511627776)") +assert result("G40") =~ expr("1.4e-1099511627776*f(1099511627776)") +assert result("F41") =~ expr("1.41e+2199023255552*f(2199023255552)") +assert result("G41") =~ expr("1.41e-2199023255552*f(2199023255552)") +assert result("F42") =~ expr("1.42e+4398046511104*f(4398046511104)") +assert result("G42") =~ expr("1.42e-4398046511104*f(4398046511104)") +assert result("F43") =~ expr("1.43e+8796093022208*f(8796093022208)") +assert result("G43") =~ expr("1.43e-8796093022208*f(8796093022208)") +assert result("F44") =~ expr("1.44e+17592186044416*f(17592186044416)") +assert result("G44") =~ expr("1.44e-17592186044416*f(17592186044416)") +assert result("F45") =~ expr("1.45e+35184372088832*f(35184372088832)") +assert result("G45") =~ expr("1.45e-35184372088832*f(35184372088832)") +assert result("F46") =~ expr("1.46e+70368744177664*f(70368744177664)") +assert result("G46") =~ expr("1.46e-70368744177664*f(70368744177664)") +assert result("F47") =~ expr("1.47e+140737488355328*f(140737488355328)") +assert result("G47") =~ expr("1.47e-140737488355328*f(140737488355328)") +assert result("F48") =~ expr("1.48e+281474976710656*f(281474976710656)") +assert result("G48") =~ expr("1.48e-281474976710656*f(281474976710656)") +assert result("F49") =~ expr("1.49e+562949953421312*f(562949953421312)") +assert result("G49") =~ expr("1.49e-562949953421312*f(562949953421312)") +assert result("F50") =~ expr("1.5e+1125899906842624*f(1125899906842624)") +assert result("G50") =~ expr("1.5e-1125899906842624*f(1125899906842624)") +assert result("F51") =~ expr("1.51e+2251799813685248*f(2251799813685248)") +assert result("G51") =~ expr("1.51e-2251799813685248*f(2251799813685248)") +assert result("F52") =~ expr("1.52e+4503599627370496*f(4503599627370496)") +assert result("G52") =~ expr("1.52e-4503599627370496*f(4503599627370496)") +assert result("F53") =~ expr("1.53e+9007199254740992*f(9007199254740992)") +assert result("G53") =~ expr("1.53e-9007199254740992*f(9007199254740992)") +assert result("F54") =~ expr("1.54e+18014398509481984*f(18014398509481984)") +assert result("G54") =~ expr("1.54e-18014398509481984*f(18014398509481984)") +assert result("F55") =~ expr("1.55e+36028797018963968*f(36028797018963968)") +assert result("G55") =~ expr("1.55e-36028797018963968*f(36028797018963968)") +assert result("F56") =~ expr("1.56e+72057594037927936*f(72057594037927936)") +assert result("G56") =~ expr("1.56e-72057594037927936*f(72057594037927936)") +assert result("F57") =~ expr("1.57e+144115188075855872*f(144115188075855872)") +assert result("G57") =~ expr("1.57e-144115188075855872*f(144115188075855872)") +assert result("F58") =~ expr("1.58e+288230376151711744*f(288230376151711744)") +assert result("G58") =~ expr("1.58e-288230376151711744*f(288230376151711744)") +assert result("F59") =~ expr("1.59e+576460752303423488*f(576460752303423488)") +assert result("G59") =~ expr("1.59e-576460752303423488*f(576460752303423488)") +assert result("F60") =~ expr("1.6e+1152921504606846976*f(1152921504606846976)") +assert result("G60") =~ expr("1.6e-1152921504606846976*f(1152921504606846976)") +assert result("F61") =~ expr("1.61e+2305843009213693952*f(2305843009213693952)") +assert result("G61") =~ expr("1.61e-2305843009213693952*f(2305843009213693952)") +assert result("F62") =~ expr("1.62e+4611686018427387904*f(4611686018427387904)") +assert result("G62") =~ expr("1.62e-4611686018427387904*f(4611686018427387904)") +*--#] float_extremes : +*--#[ 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; diff --git a/sources/evaluate.c b/sources/evaluate.c index eef7e8a6..936a4f40 100644 --- a/sources/evaluate.c +++ b/sources/evaluate.c @@ -89,14 +89,6 @@ void SetfFloatPrecision(LONG prec) #ifdef WITHSORTBOTS totnum = MaX(2*AM.totalnumberofthreads-3,AM.totalnumberofthreads); #endif - if ( AB[0]->T.auxr_ ) { - for ( id = 0; id < totnum; id++ ) { - a = (mpfr_t *)AB[id]->T.auxr_; - mpfr_clears(a[0],a[1],a[2],a[3],a[4],(mpfr_ptr)0); - M_free(AB[id]->T.auxr_,"AB[id]->T.auxr_"); - AB[id]->T.auxr_ = 0; - } - } for ( id = 0; id < totnum; id++ ) { AB[id]->T.auxr_ = (void *)Malloc1(sizeof(mpfr_t)*5,"AB[id]->T.auxr_"); a = (mpfr_t *)AB[id]->T.auxr_; @@ -107,11 +99,6 @@ void SetfFloatPrecision(LONG prec) mpfr_inits2(fprec,a[0],a[1],a[2],a[3],a[4],(mpfr_ptr)0); } #else - if ( AT.auxr_ ) { - mpfr_clears(auxr1,auxr2,auxr3,auxr4,auxr5,(mpfr_ptr)0); - M_free(AT.auxr_,"AT.auxr_"); - AT.auxr_ = 0; - } AT.auxr_ = (void *)Malloc1(sizeof(mpfr_t)*5,"AT.auxr_"); mpfr_inits2(fprec,auxr1,auxr2,auxr3,auxr4,auxr5,(mpfr_ptr)0); #endif @@ -137,10 +124,6 @@ void ClearfFloat(void) M_free(AB[id]->T.auxr_,"AB[id]->T.auxr_"); AB[id]->T.auxr_ = 0; } -/* - M_free(AB[0]->T.auxr_,"AB[0]->T.auxr_"); - AB[0]->T.auxr_ = 0; -*/ } #else if ( AT.auxr_ ) { @@ -149,12 +132,6 @@ void ClearfFloat(void) AT.auxr_ = 0; } #endif -/* - if ( AS.delta_1 ) { - mpf_clear(ln2); - AS.delta_1 = 0; - } -*/ } /* @@ -392,9 +369,9 @@ int EvaluateFun(PHEAD WORD *term, WORD level, WORD *pars) mpfr_pow_si(auxr3,auxr3,ti[1],RND); mpfr_mul(auxr2,auxr2,auxr3,RND); ti[1] = 0; + first = 0; } } - first = 0; goto nextfun; } if ( tt != tnext && *t != AGMFUNCTION && *t != ATAN2FUNCTION) goto nextfun; @@ -677,12 +654,8 @@ int EvaluateFun(PHEAD WORD *term, WORD level, WORD *pars) case MZV: case EULER: case MZVHALF: - goto nextfun; default: - MLOCK(ErrorMessageLock); - MesPrint("Function in evaluate statement not yet implemented."); - MUNLOCK(ErrorMessageLock); - break; + goto nextfun; } } else goto nextfun; diff --git a/sources/float.c b/sources/float.c index 87359dbe..06a2ac80 100644 --- a/sources/float.c +++ b/sources/float.c @@ -408,11 +408,11 @@ int UnpackFloat(mpf_t outfloat,WORD *fun) f += ARGHEAD+6; if ( f[-1] == -5 ) { outfloat->_mp_exp = - -(mp_exp_t)((((ULONG)(f[-4]))<_mp_exp = - (mp_exp_t)((((ULONG)(f[-4]))<T.mpf_tab1 ) { - a = (mpf_t *)AB[id]->T.mpf_tab1; - for ( i = 0; i <=Nw; i++ ) { - mpf_clear(a[i]); - } - M_free(AB[id]->T.mpf_tab1,"mpftab1"); - } AB[id]->T.mpf_tab1 = (void *)Malloc1((N+2)*sizeof(mpf_t),"mpftab1"); a = (mpf_t *)AB[id]->T.mpf_tab1; for ( i = 0; i <=Nw; i++ ) { @@ -1117,13 +1110,6 @@ void SetupMZVTables(void) */ mpf_init(a[i]); } - if ( AB[id]->T.mpf_tab2 ) { - a = (mpf_t *)AB[id]->T.mpf_tab2; - for ( i = 0; i <=Nw; i++ ) { - mpf_clear(a[i]); - } - M_free(AB[id]->T.mpf_tab2,"mpftab2"); - } AB[id]->T.mpf_tab2 = (void *)Malloc1((N+2)*sizeof(mpf_t),"mpftab2"); a = (mpf_t *)AB[id]->T.mpf_tab2; for ( i = 0; i <=Nw; i++ ) { @@ -1135,12 +1121,6 @@ void SetupMZVTables(void) size_t N; Nw = AC.DefaultPrecision; N = (size_t)Nw; - if ( AT.mpf_tab1 ) { - for ( i = 0; i <= Nw; i++ ) { - mpf_clear(mpftab1[i]); - } - M_free(AT.mpf_tab1,"mpftab1"); - } AT.mpf_tab1 = (void *)Malloc1((N+2)*sizeof(mpf_t),"mpftab1"); for ( i = 0; i <= Nw; i++ ) { /* @@ -1149,34 +1129,21 @@ void SetupMZVTables(void) */ mpf_init(mpftab1[i]); } - if ( AT.mpf_tab2 ) { - for ( i = 0; i <= Nw; i++ ) { - mpf_clear(mpftab2[i]); - } - M_free(AT.mpf_tab2,"mpftab2"); - } AT.mpf_tab2 = (void *)Malloc1((N+2)*sizeof(mpf_t),"mpftab2"); for ( i = 0; i <= Nw; i++ ) { mpf_init(mpftab2[i]); } #endif - if ( AS.delta_1 ) { - mpf_clear(mpfdelta1); - M_free(AS.delta_1,"delta1"); - } AS.delta_1 = (void *)Malloc1(sizeof(mpf_t),"delta1"); mpf_init(mpfdelta1); SimpleDelta(mpfdelta1,1); /* this can speed up things. delta1 = ln(2) */ -/* - Finally the character buffer for printing - if ( AO.floatspace ) M_free(AO.floatspace,"floatspace"); - AO.floatspace = (UBYTE *)Malloc1(((10*AC.DefaultPrecision)/33+40)*sizeof(UBYTE),"floatspace"); -*/ } /* #] SetupMZVTables : #[ SetupMPFTables : + + Allocates the aux variables */ void SetupMPFTables(void) @@ -1184,22 +1151,14 @@ void SetupMPFTables(void) #ifdef WITHPTHREADS int id, totnum; mpf_t *a; -/* - Now the aux variables -*/ #ifdef WITHSORTBOTS totnum = MaX(2*AM.totalnumberofthreads-3,AM.totalnumberofthreads); #endif for ( id = 0; id < totnum; id++ ) { - if ( AB[id]->T.aux_ ) { /* - We work here with a[0] etc because the aux1 etc contain B which - in the current routine would be AB[0] only + We work here with a[0] etc because the aux1 etc contain B which + in the current routine would be AB[0] only */ - a = (mpf_t *)AB[id]->T.aux_; - mpf_clears(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],(mpf_ptr)0); - M_free(AB[id]->T.aux_,"AB[id]->T.aux_"); - } AB[id]->T.aux_ = (void *)Malloc1(sizeof(mpf_t)*8,"AB[id]->T.aux_"); a = (mpf_t *)AB[id]->T.aux_; mpf_inits(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],(mpf_ptr)0); @@ -1208,24 +1167,12 @@ void SetupMPFTables(void) AB[id]->T.indi2 = AB[id]->T.indi1 + AC.MaxWeight; } #else -/* - Now the aux variables -*/ - if ( AT.aux_ ) { - mpf_clears(aux1,aux2,aux3,aux4,aux5,auxjm,auxjjm,auxsum,(mpf_ptr)0); - M_free(AT.aux_,"AT.aux"); - } AT.aux_ = (void *)Malloc1(sizeof(mpf_t)*8,"AT.aux_"); mpf_inits(aux1,aux2,aux3,aux4,aux5,auxjm,auxjjm,auxsum,(mpf_ptr)0); if ( AT.indi1 ) M_free(AT.indi1,"indi1"); AT.indi1 = (WORD *)Malloc1(sizeof(WORD)*AC.MaxWeight*2,"indi1"); AT.indi2 = AT.indi1 + AC.MaxWeight; #endif -/* - Finally the character buffer for printing - if ( AO.floatspace ) M_free(AO.floatspace,"floatspace"); - AO.floatspace = (UBYTE *)Malloc1(((10*AC.DefaultPrecision)/33+40)*sizeof(UBYTE),"floatspace"); -*/ } /* @@ -1373,15 +1320,17 @@ int CoStrictRounding(UBYTE *s) if ( *s == 0 ) { /* No subkey, which means round to default precision */ x = AC.DefaultPrecision - AC.MaxWeight - 1; - Add4Com(TYPESTRICTROUNDING,x,2); - return(0); + base = 2; } - if ( FG.cTable[*s] == 1 ) { /* number */ + else if ( FG.cTable[*s] == 1 ) { /* number */ ParseNumber(x,s) if ( tolower(*s) == 'd' ) { base = 10; s++; } /* decimal base */ else if ( tolower(*s) == 'b' ){ base = 2; s++; } /* binary base */ else goto IllPar; /* invalid base specification */ } + else { + goto IllPar; + } while ( *s == ' ' || *s == ',' || *s == '\t' ) s++; /* Check for invalid arguments */ @@ -1838,7 +1787,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); @@ -1899,8 +1848,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; @@ -1912,25 +1861,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"); @@ -1980,6 +1922,18 @@ void SimpleDelta(mpf_t sum, int m) */ n--; jmax = (int)((int)xprec - (n-1)*m); +/* + For small prec and large m, the estimate can be wrong and even be negative, + so we increase jmax until jmax + m*log2(jmax) > prec +*/ + if ( jmax < 0 ) jmax = 1; + do { + n = 0; + x = (unsigned long)jmax; + while (x) { x >>= 1; n++; } + n--; // floor(log2(jmax)) + jmax++; + } while ( jmax + m * n <= prec ); mpf_set_ui(sum,0); for ( j = 1; j <= jmax; j++ ) { #ifdef WITHCUTOFF @@ -2026,6 +1980,18 @@ void SimpleDeltaC(mpf_t sum, int m) */ n--; jmax = (int)((int)xprec - (n-1)*m); +/* + For small prec and large m, the estimate can be wrong and even be negative, + so we increase jmax until jmax + m*log2(jmax) > prec +*/ + if ( jmax < 0 ) jmax = 1; + do { + n = 0; + x = (unsigned long)jmax; + while (x) { x >>= 1; n++; } + n--; // floor(log2(jmax)) + jmax++; + } while ( jmax + m * n <= prec ); if ( s < 0 ) jmax /= 2; mpf_set_si(sum,0L); for ( j = 1; j <= jmax; j++ ) { diff --git a/sources/ftypes.h b/sources/ftypes.h index 4b101900..62526584 100644 --- a/sources/ftypes.h +++ b/sources/ftypes.h @@ -468,7 +468,6 @@ typedef int (*TFUN1)(); #define BLOCK 113 #define ONEPI 114 #define PHI 115 -#ifdef WITHFLOAT #define FLOATFUN 116 #define TOFLOAT 117 #define TORAT 118 @@ -481,9 +480,6 @@ typedef int (*TFUN1)(); #define HPLFUNCTION 125 #define MPLFUNCTION 126 #define MAXBUILTINFUNCTION 126 -#else -#define MAXBUILTINFUNCTION 115 -#endif #define FIRSTUSERFUNCTION 150 diff --git a/sources/inivar.h b/sources/inivar.h index 892f0b69..9a15b089 100644 --- a/sources/inivar.h +++ b/sources/inivar.h @@ -243,7 +243,6 @@ static struct fixedfun { ,{"block_" ,0 ,0 ,0 ,0} /* BLOCK */ ,{"onepi_" ,0 ,0 ,0 ,0} /* ONEPI */ ,{"phi_" ,0 ,VERTEXFUNCTION,0 ,0} /* PHI */ -#ifdef WITHFLOAT ,{"float_" ,0 ,0 ,0 ,0} /* FLOATFUN */ ,{"tofloat_" ,0 ,0 ,0 ,0} /* TOFLOAT */ ,{"torat_" ,0 ,0 ,0 ,0} /* TORAT */ @@ -255,7 +254,6 @@ static struct fixedfun { ,{"eexp_" ,0 ,0 ,0 ,0} /* EXPFUNCTION */ ,{"hpl_" ,0 ,0 ,0 ,0} /* HPLFUNCTION */ ,{"mpl_" ,0 ,0 ,0 ,0} /* MPLFUNCTION */ -#endif }; FIXEDSET fixedsets[] = { diff --git a/sources/pre.c b/sources/pre.c index 524cc834..42ba41b5 100644 --- a/sources/pre.c +++ b/sources/pre.c @@ -7769,6 +7769,10 @@ int DoStartFloat(UBYTE *s) MesPrint("@Simultaneous use of floating point and modulus arithmetic makes no sense."); error = 1; } + if ( AT.aux_ ) { // First, we clean up any previous floating point system. + ClearfFloat(); + ClearMZVTables(); + } while ( *s == ',' || *s == ' ' || *s == '\t' ) s++; /* The first parameter is the float precision