Skip to content

Commit 8e537a3

Browse files
committed
fix: the estimate for jmax in SimpleDelta and SimpleDeltaC could be wrong and even be negative.
- It is now increased iteratively until it meets the required precision. - This also fixes the remaining rounding issues in the euler_ and mzvhalf_ tests (see PR699). - furthermore, the raw form in the Float_1 test has been slightly adjusted.
1 parent 17cdc98 commit 8e537a3

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

check/features.frm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,13 +662,13 @@ assert stdout =~ exact_pattern(<<'EOF')
662662
G1 =
663663
float_(10,10,1,225649930152063087544280124519603661924016376904153173222\
664664
961313295752588365049496190204609112667217257624737508104376810254484309\
665-
3830597279756558899541412580219255737022507716035);
665+
3830597279756558899541412586941038636793415360118);
666666
EOF
667667
assert stdout =~ exact_pattern(<<'EOF')
668668
G2 =
669669
float_(10,10,1,247337966873870703631573653423368526098272821023387457752\
670670
643030990710929556575503489173572446024607642191456056189912528713904095\
671-
704444384800390830056125051605311704862654126);
671+
704444384800390830056125051897088334731440434);
672672
EOF
673673
*--#] Float_1 :
674674
*--#[ evaluate_symbol :
@@ -919,7 +919,7 @@ assert result("EULER3") =~ expr("
919919
- 3.888958461681063290997e-01*euler(-1,-2)
920920
+ 2.140723708667062274342e-01*euler(-1,-1,-1)
921921
- 5.372131936080402009406e-01*euler(-1,-1,1)
922-
+ 9.475300423012770572182e-02*euler(-1,1,-1)
922+
+ 9.475300423012770572183e-02*euler(-1,1,-1)
923923
- 5.550410866482157995314e-02*euler(-1,1,1)
924924
+ 2.695764795315278073874e-01*euler(-1,2)
925925
- 5.082152128046848508121e-01*euler(2,-1)
@@ -993,7 +993,7 @@ assert result("MZVHALF1") =~ expr("
993993
+6.931471805599453094172e-01*mzvhalf(1)
994994
")
995995
assert result("MZVHALF2") =~ expr("
996-
+2.402265069591007123335e-01*mzvhalf(1,1)
996+
+2.402265069591007123336e-01*mzvhalf(1,1)
997997
+ 5.822405264650125059027e-01*mzvhalf(2)
998998
")
999999
assert result("MZVHALF3") =~ expr("

sources/float.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,18 @@ void SimpleDelta(mpf_t sum, int m)
19201920
*/
19211921
n--;
19221922
jmax = (int)((int)xprec - (n-1)*m);
1923+
/*
1924+
For small prec and large m, the estimate can be wrong and even be negative,
1925+
so we increase jmax until jmax + m*log2(jmax) > prec
1926+
*/
1927+
if ( jmax < 0 ) jmax = 1;
1928+
do {
1929+
n = 0;
1930+
x = (unsigned long)jmax;
1931+
while (x) { x >>= 1; n++; }
1932+
n--; // floor(log2(jmax))
1933+
jmax++;
1934+
} while ( jmax + m * n <= prec );
19231935
mpf_set_ui(sum,0);
19241936
for ( j = 1; j <= jmax; j++ ) {
19251937
#ifdef WITHCUTOFF
@@ -1966,6 +1978,18 @@ void SimpleDeltaC(mpf_t sum, int m)
19661978
*/
19671979
n--;
19681980
jmax = (int)((int)xprec - (n-1)*m);
1981+
/*
1982+
For small prec and large m, the estimate can be wrong and even be negative,
1983+
so we increase jmax until jmax + m*log2(jmax) > prec
1984+
*/
1985+
if ( jmax < 0 ) jmax = 1;
1986+
do {
1987+
n = 0;
1988+
x = (unsigned long)jmax;
1989+
while (x) { x >>= 1; n++; }
1990+
n--; // floor(log2(jmax))
1991+
jmax++;
1992+
} while ( jmax + m * n <= prec );
19691993
if ( s < 0 ) jmax /= 2;
19701994
mpf_set_si(sum,0L);
19711995
for ( j = 1; j <= jmax; j++ ) {

0 commit comments

Comments
 (0)