allpatches 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977
  1. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  2. --- mpfr-4.1.0-a/PATCHES 2021-02-11 12:40:40.079363480 +0000
  3. +++ mpfr-4.1.0-b/PATCHES 2021-02-11 12:40:40.119363040 +0000
  4. @@ -0,0 +1 @@
  5. +decimal128-conv
  6. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  7. --- mpfr-4.1.0-a/VERSION 2020-07-10 11:52:33.000000000 +0000
  8. +++ mpfr-4.1.0-b/VERSION 2021-02-11 12:40:40.119363040 +0000
  9. @@ -1 +1 @@
  10. -4.1.0
  11. +4.1.0-p1
  12. diff -Naurd mpfr-4.1.0-a/src/get_d128.c mpfr-4.1.0-b/src/get_d128.c
  13. --- mpfr-4.1.0-a/src/get_d128.c 2020-04-08 22:39:35.000000000 +0000
  14. +++ mpfr-4.1.0-b/src/get_d128.c 2021-02-11 12:40:40.103363216 +0000
  15. @@ -40,22 +40,21 @@
  16. static _Decimal128
  17. get_decimal128_nan (void)
  18. {
  19. - return (_Decimal128) MPFR_DBL_NAN;
  20. + return 0.0dl / 0.0dl;
  21. }
  22. /* construct the decimal128 Inf with given sign */
  23. static _Decimal128
  24. get_decimal128_inf (int negative)
  25. {
  26. - return (_Decimal128) (negative ? MPFR_DBL_INFM : MPFR_DBL_INFP);
  27. + return negative ? - 1.0dl / 0.0dl : 1.0dl / 0.0dl;
  28. }
  29. /* construct the decimal128 zero with given sign */
  30. static _Decimal128
  31. get_decimal128_zero (int negative)
  32. {
  33. - _Decimal128 zero = 0;
  34. - return (_Decimal128) (negative ? -zero : zero);
  35. + return negative ? - 0.0dl : 0.0dl;
  36. }
  37. /* construct the decimal128 smallest non-zero with given sign:
  38. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  39. --- mpfr-4.1.0-a/src/mpfr.h 2020-07-10 11:52:33.000000000 +0000
  40. +++ mpfr-4.1.0-b/src/mpfr.h 2021-02-11 12:40:40.115363084 +0000
  41. @@ -27,7 +27,7 @@
  42. #define MPFR_VERSION_MAJOR 4
  43. #define MPFR_VERSION_MINOR 1
  44. #define MPFR_VERSION_PATCHLEVEL 0
  45. -#define MPFR_VERSION_STRING "4.1.0"
  46. +#define MPFR_VERSION_STRING "4.1.0-p1"
  47. /* User macros:
  48. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  49. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  50. --- mpfr-4.1.0-a/src/version.c 2020-07-10 11:52:33.000000000 +0000
  51. +++ mpfr-4.1.0-b/src/version.c 2021-02-11 12:40:40.119363040 +0000
  52. @@ -25,5 +25,5 @@
  53. const char *
  54. mpfr_get_version (void)
  55. {
  56. - return "4.1.0";
  57. + return "4.1.0-p1";
  58. }
  59. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  60. --- mpfr-4.1.0-a/PATCHES 2021-02-11 12:43:51.761257868 +0000
  61. +++ mpfr-4.1.0-b/PATCHES 2021-02-11 12:43:51.801257430 +0000
  62. @@ -0,0 +1 @@
  63. +random_deviate
  64. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  65. --- mpfr-4.1.0-a/VERSION 2021-02-11 12:40:40.119363040 +0000
  66. +++ mpfr-4.1.0-b/VERSION 2021-02-11 12:43:51.801257430 +0000
  67. @@ -1 +1 @@
  68. -4.1.0-p1
  69. +4.1.0-p2
  70. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  71. --- mpfr-4.1.0-a/src/mpfr.h 2021-02-11 12:40:40.115363084 +0000
  72. +++ mpfr-4.1.0-b/src/mpfr.h 2021-02-11 12:43:51.801257430 +0000
  73. @@ -27,7 +27,7 @@
  74. #define MPFR_VERSION_MAJOR 4
  75. #define MPFR_VERSION_MINOR 1
  76. #define MPFR_VERSION_PATCHLEVEL 0
  77. -#define MPFR_VERSION_STRING "4.1.0-p1"
  78. +#define MPFR_VERSION_STRING "4.1.0-p2"
  79. /* User macros:
  80. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  81. diff -Naurd mpfr-4.1.0-a/src/random_deviate.c mpfr-4.1.0-b/src/random_deviate.c
  82. --- mpfr-4.1.0-a/src/random_deviate.c 2020-01-08 18:11:13.000000000 +0000
  83. +++ mpfr-4.1.0-b/src/random_deviate.c 2021-02-11 12:43:51.789257562 +0000
  84. @@ -289,6 +289,7 @@
  85. mpfr_random_size_t p = mpfr_get_prec (z); /* Number of bits in result */
  86. mpz_t t;
  87. int inex;
  88. + mpfr_exp_t negxe;
  89. if (n == 0)
  90. {
  91. @@ -370,14 +371,22 @@
  92. mpz_setbit (t, 0); /* Set the trailing bit so result is always inexact */
  93. if (neg)
  94. mpz_neg (t, t);
  95. - /* Is -x->e representable as a mpfr_exp_t? */
  96. - MPFR_ASSERTN (x->e <= (mpfr_uexp_t)(-1) >> 1);
  97. + /* Portable version of the negation of x->e, with a check of overflow. */
  98. + if (MPFR_UNLIKELY (x->e > MPFR_EXP_MAX))
  99. + {
  100. + /* Overflow, except when x->e = MPFR_EXP_MAX + 1 = - MPFR_EXP_MIN. */
  101. + MPFR_ASSERTN (MPFR_EXP_MIN + MPFR_EXP_MAX == -1 &&
  102. + x->e == (mpfr_random_size_t) MPFR_EXP_MAX + 1);
  103. + negxe = MPFR_EXP_MIN;
  104. + }
  105. + else
  106. + negxe = - (mpfr_exp_t) x->e;
  107. /*
  108. * Let mpfr_set_z_2exp do all the work of rounding to the requested
  109. * precision, setting overflow/underflow flags, and returning the right
  110. * inexact value.
  111. */
  112. - inex = mpfr_set_z_2exp (z, t, -x->e, rnd);
  113. + inex = mpfr_set_z_2exp (z, t, negxe, rnd);
  114. mpz_clear (t);
  115. return inex;
  116. }
  117. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  118. --- mpfr-4.1.0-a/src/version.c 2021-02-11 12:40:40.119363040 +0000
  119. +++ mpfr-4.1.0-b/src/version.c 2021-02-11 12:43:51.801257430 +0000
  120. @@ -25,5 +25,5 @@
  121. const char *
  122. mpfr_get_version (void)
  123. {
  124. - return "4.1.0-p1";
  125. + return "4.1.0-p2";
  126. }
  127. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  128. --- mpfr-4.1.0-a/PATCHES 2021-02-11 12:46:49.075316772 +0000
  129. +++ mpfr-4.1.0-b/PATCHES 2021-02-11 12:46:49.115316335 +0000
  130. @@ -0,0 +1 @@
  131. +set_z_2exp-overflow
  132. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  133. --- mpfr-4.1.0-a/VERSION 2021-02-11 12:43:51.801257430 +0000
  134. +++ mpfr-4.1.0-b/VERSION 2021-02-11 12:46:49.115316335 +0000
  135. @@ -1 +1 @@
  136. -4.1.0-p2
  137. +4.1.0-p3
  138. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  139. --- mpfr-4.1.0-a/src/mpfr.h 2021-02-11 12:43:51.801257430 +0000
  140. +++ mpfr-4.1.0-b/src/mpfr.h 2021-02-11 12:46:49.115316335 +0000
  141. @@ -27,7 +27,7 @@
  142. #define MPFR_VERSION_MAJOR 4
  143. #define MPFR_VERSION_MINOR 1
  144. #define MPFR_VERSION_PATCHLEVEL 0
  145. -#define MPFR_VERSION_STRING "4.1.0-p2"
  146. +#define MPFR_VERSION_STRING "4.1.0-p3"
  147. /* User macros:
  148. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  149. diff -Naurd mpfr-4.1.0-a/src/set_z_exp.c mpfr-4.1.0-b/src/set_z_exp.c
  150. --- mpfr-4.1.0-a/src/set_z_exp.c 2020-01-08 18:11:13.000000000 +0000
  151. +++ mpfr-4.1.0-b/src/set_z_exp.c 2021-02-11 12:46:49.103316466 +0000
  152. @@ -28,10 +28,11 @@
  153. int
  154. mpfr_set_z_2exp (mpfr_ptr f, mpz_srcptr z, mpfr_exp_t e, mpfr_rnd_t rnd_mode)
  155. {
  156. - mp_size_t fn, zn, dif, en;
  157. + mp_size_t fn, zn, dif;
  158. int k, sign_z, inex;
  159. mp_limb_t *fp, *zp;
  160. - mpfr_exp_t exp;
  161. + mpfr_exp_t exp, nmax;
  162. + mpfr_uexp_t uexp;
  163. sign_z = mpz_sgn (z);
  164. if (MPFR_UNLIKELY (sign_z == 0)) /* ignore the exponent for 0 */
  165. @@ -43,10 +44,15 @@
  166. MPFR_ASSERTD (sign_z == MPFR_SIGN_POS || sign_z == MPFR_SIGN_NEG);
  167. zn = ABSIZ(z); /* limb size of z */
  168. - /* compute en = floor(e/GMP_NUMB_BITS) */
  169. - en = (e >= 0) ? e / GMP_NUMB_BITS : (e + 1) / GMP_NUMB_BITS - 1;
  170. MPFR_ASSERTD (zn >= 1);
  171. - if (MPFR_UNLIKELY (zn + en > MPFR_EMAX_MAX / GMP_NUMB_BITS + 1))
  172. + nmax = MPFR_EMAX_MAX / GMP_NUMB_BITS + 1;
  173. + /* Detect early overflow with zn + en > nmax,
  174. + where en = floor(e / GMP_NUMB_BITS).
  175. + This is checked without an integer overflow (even assuming some
  176. + future version of GMP, where limitations may be removed). */
  177. + if (MPFR_UNLIKELY (e >= 0 ?
  178. + zn > nmax - e / GMP_NUMB_BITS :
  179. + zn + (e + 1) / GMP_NUMB_BITS - 1 > nmax))
  180. return mpfr_overflow (f, rnd_mode, sign_z);
  181. /* because zn + en >= MPFR_EMAX_MAX / GMP_NUMB_BITS + 2
  182. implies (zn + en) * GMP_NUMB_BITS >= MPFR_EMAX_MAX + GMP_NUMB_BITS + 1
  183. @@ -64,8 +70,21 @@
  184. and exp = zn * GMP_NUMB_BITS + e - k
  185. <= (zn + en) * GMP_NUMB_BITS - k + GMP_NUMB_BITS - 1
  186. <= MPFR_EMAX_MAX + 2 * GMP_NUMB_BITS - 1 */
  187. - exp = (mpfr_prec_t) zn * GMP_NUMB_BITS + e - k;
  188. + /* We need to compute exp = zn * GMP_NUMB_BITS + e - k with well-defined
  189. + operations (no integer overflows / no implementation-defined results).
  190. + The mathematical result of zn * GMP_NUMB_BITS may be larger than
  191. + the largest value of mpfr_exp_t while exp could still be less than
  192. + __gmpfr_emax. Thanks to early overflow detection, we can compute the
  193. + result in modular arithmetic, using mpfr_uexp_t, and convert it to
  194. + mpfr_exp_t. */
  195. + uexp = (mpfr_uexp_t) zn * GMP_NUMB_BITS + (mpfr_uexp_t) e - k;
  196. +
  197. + /* Convert to signed in a portable way (see doc/README.dev).
  198. + On most platforms, this can be optimized to identity (no-op). */
  199. + exp = uexp > MPFR_EXP_MAX ? -1 - (mpfr_exp_t) ~uexp : (mpfr_exp_t) uexp;
  200. +
  201. /* The exponent will be exp or exp + 1 (due to rounding) */
  202. +
  203. if (MPFR_UNLIKELY (exp > __gmpfr_emax))
  204. return mpfr_overflow (f, rnd_mode, sign_z);
  205. if (MPFR_UNLIKELY (exp + 1 < __gmpfr_emin))
  206. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  207. --- mpfr-4.1.0-a/src/version.c 2021-02-11 12:43:51.801257430 +0000
  208. +++ mpfr-4.1.0-b/src/version.c 2021-02-11 12:46:49.115316335 +0000
  209. @@ -25,5 +25,5 @@
  210. const char *
  211. mpfr_get_version (void)
  212. {
  213. - return "4.1.0-p2";
  214. + return "4.1.0-p3";
  215. }
  216. diff -Naurd mpfr-4.1.0-a/tests/tset_z_exp.c mpfr-4.1.0-b/tests/tset_z_exp.c
  217. --- mpfr-4.1.0-a/tests/tset_z_exp.c 2020-01-08 18:11:13.000000000 +0000
  218. +++ mpfr-4.1.0-b/tests/tset_z_exp.c 2021-02-11 12:46:49.103316466 +0000
  219. @@ -97,49 +97,149 @@
  220. mpfr_get_si is a rather indirect test of a low level routine. */
  221. static void
  222. -check (long i, mpfr_rnd_t rnd)
  223. +check (long i, mpfr_rnd_t rnd, int reduced)
  224. {
  225. - mpfr_t f;
  226. + mpfr_t f1, f2, f3;
  227. mpz_t z;
  228. - mpfr_exp_t e;
  229. + mpfr_exp_t e, old_emin, old_emax;
  230. int inex;
  231. + mpfr_flags_t flags;
  232. +
  233. + old_emin = mpfr_get_emin ();
  234. + old_emax = mpfr_get_emax ();
  235. /* using CHAR_BIT * sizeof(long) bits of precision ensures that
  236. mpfr_set_z_2exp is exact below */
  237. - mpfr_init2 (f, CHAR_BIT * sizeof(long));
  238. + mpfr_inits2 (CHAR_BIT * sizeof(long), f1, f2, f3, (mpfr_ptr) 0);
  239. mpz_init (z);
  240. mpz_set_ui (z, i);
  241. /* the following loop ensures that no overflow occurs */
  242. do
  243. e = randexp ();
  244. while (e > mpfr_get_emax () - CHAR_BIT * sizeof(long));
  245. - inex = mpfr_set_z_2exp (f, z, e, rnd);
  246. - if (inex != 0)
  247. +
  248. + mpfr_clear_flags ();
  249. + inex = mpfr_set_z_2exp (f1, z, e, rnd);
  250. + flags = __gmpfr_flags;
  251. +
  252. + if (inex != 0 || flags != 0 ||
  253. + (mpfr_div_2si (f2, f1, e, rnd), mpfr_get_si (f2, MPFR_RNDZ) != i))
  254. {
  255. - printf ("Error in mpfr_set_z_2exp for i=%ld, e=%ld,"
  256. - " wrong ternary value\n", i, (long) e);
  257. - printf ("expected 0, got %d\n", inex);
  258. + printf ("Error in mpfr_set_z_2exp for i=%ld e=%" MPFR_EXP_FSPEC
  259. + "d rnd_mode=%d\n", i, (mpfr_eexp_t) e, rnd);
  260. + mpfr_set_si_2exp (f2, i, e, MPFR_RNDN);
  261. + printf ("expected "); mpfr_dump (f2);
  262. + printf ("with inex = %d and flags =", 0);
  263. + flags_out (0);
  264. + printf ("got "); mpfr_dump (f1);
  265. + printf ("with inex = %d and flags =", inex);
  266. + flags_out (flags);
  267. exit (1);
  268. }
  269. - mpfr_div_2si (f, f, e, rnd);
  270. - if (mpfr_get_si (f, MPFR_RNDZ) != i)
  271. +
  272. + if (reduced)
  273. {
  274. - printf ("Error in mpfr_set_z_2exp for i=%ld e=", i);
  275. - if (e < LONG_MIN)
  276. - printf ("(<LONG_MIN)");
  277. - else if (e > LONG_MAX)
  278. - printf ("(>LONG_MAX)");
  279. - else
  280. - printf ("%ld", (long) e);
  281. - printf (" rnd_mode=%d\n", rnd);
  282. - printf ("expected %ld\n", i);
  283. - printf ("got "); mpfr_dump (f);
  284. - exit (1);
  285. + mpfr_exp_t ef, emin, emax;
  286. + int inex2, inex3;
  287. + mpfr_flags_t flags2, flags3;
  288. +
  289. + ef = i == 0 ? 0 : mpfr_get_exp (f1);
  290. + for (emin = ef - 2; emin <= ef + 2; emin++)
  291. + for (emax = emin; emax <= ef + 2; emax++)
  292. + {
  293. + inex3 = mpfr_set (f3, f1, rnd);
  294. + MPFR_ASSERTN (inex3 == 0);
  295. + mpfr_set_emin (emin);
  296. + mpfr_set_emax (emax);
  297. + mpfr_clear_flags ();
  298. + inex2 = mpfr_set_z_2exp (f2, z, e, rnd);
  299. + flags2 = __gmpfr_flags;
  300. + mpfr_clear_flags ();
  301. + inex3 = mpfr_check_range (f3, 0, rnd);
  302. + flags3 = __gmpfr_flags;
  303. + if (!(mpfr_equal_p (f2, f3) &&
  304. + SAME_SIGN (inex2, inex3) &&
  305. + flags2 == flags3))
  306. + {
  307. + printf ("Error in mpfr_set_z_2exp for i=%ld e=%"
  308. + MPFR_EXP_FSPEC "d rnd_mode=%d\nand emin=%"
  309. + MPFR_EXP_FSPEC "d emax=%" MPFR_EXP_FSPEC
  310. + "d\n", i, (mpfr_eexp_t) e, rnd,
  311. + (mpfr_eexp_t) emin, (mpfr_eexp_t) emax);
  312. + printf ("expected "); mpfr_dump (f3);
  313. + printf ("with inex = %d and flags =", inex3);
  314. + flags_out (flags3);
  315. + printf ("got "); mpfr_dump (f2);
  316. + printf ("with inex = %d and flags =", inex2);
  317. + flags_out (flags2);
  318. + exit (1);
  319. + }
  320. + }
  321. + mpfr_set_emin (old_emin);
  322. + mpfr_set_emax (old_emax);
  323. }
  324. - mpfr_clear (f);
  325. +
  326. + mpfr_clears (f1, f2, f3, (mpfr_ptr) 0);
  327. mpz_clear (z);
  328. }
  329. +static void
  330. +check_huge (void)
  331. +{
  332. + if (getenv ("MPFR_CHECK_LARGEMEM") != NULL)
  333. + {
  334. + mpfr_t x;
  335. + mpz_t z;
  336. + long e;
  337. +
  338. + /* Increase tests_memory_limit to the maximum in order to avoid
  339. + an obvious failure due to insufficient memory. */
  340. + tests_memory_limit = (size_t) -1; /* no memory limit */
  341. +
  342. + mpfr_init2 (x, 32);
  343. +
  344. + /* In r14140, with a 32-bit ABI (GCC's -m32):
  345. + - With UBsan (-fsanitize=undefined -fno-sanitize-recover),
  346. + this fails with:
  347. + set_z_2exp.c:71:26: runtime error: signed integer overflow:
  348. + 67108864 * 32 cannot be represented in type 'long int'
  349. + - With -D_MPFR_EXP_FORMAT=4, this fails with:
  350. + Expected 0.10001000000000000000000000000000E5
  351. + Got 0
  352. + */
  353. + mpz_init_set_ui (z, 17);
  354. + e = 0x7ffffff0;
  355. + mpz_mul_2exp (z, z, e);
  356. + mpz_add_ui (z, z, 1);
  357. + mpfr_set_z_2exp (x, z, -e, MPFR_RNDN);
  358. + if (mpfr_cmp_ui0 (x, 17) != 0)
  359. + {
  360. + printf ("Error 1 in check_huge\n");
  361. + printf ("Expected 0.10001000000000000000000000000000E5\n");
  362. + printf ("Got ");
  363. + mpfr_dump (x);
  364. + exit (1);
  365. + }
  366. + mpz_clear (z);
  367. +
  368. + mpz_init_set_ui (z, 17);
  369. + mpz_mul_2exp (z, z, 0xffffffb0);
  370. + mpz_add_ui (z, z, 1);
  371. + mpfr_set_z_2exp (x, z, -1, MPFR_RNDN);
  372. + if (! MPFR_IS_INF (x) || MPFR_IS_NEG (x))
  373. + {
  374. + printf ("Error 2 in check_huge\n");
  375. + printf ("Expected @Inf@\n");
  376. + printf ("Got ");
  377. + mpfr_dump (x);
  378. + exit (1);
  379. + }
  380. + mpz_clear (z);
  381. +
  382. + mpfr_clear (x);
  383. + }
  384. +}
  385. +
  386. int
  387. main (int argc, char *argv[])
  388. {
  389. @@ -147,11 +247,13 @@
  390. tests_start_mpfr ();
  391. - check (0, MPFR_RNDN);
  392. + check (0, MPFR_RNDN, 0);
  393. for (j = 0; j < 200000; j++)
  394. - check (randlimb () & LONG_MAX, RND_RAND ());
  395. + check (randlimb () & LONG_MAX, RND_RAND (), j < 200);
  396. check0 ();
  397. + check_huge ();
  398. +
  399. tests_end_mpfr ();
  400. return 0;
  401. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  402. --- mpfr-4.1.0-a/PATCHES 2021-02-11 12:48:27.322243271 +0000
  403. +++ mpfr-4.1.0-b/PATCHES 2021-02-11 12:48:27.370242746 +0000
  404. @@ -0,0 +1 @@
  405. +prototypes
  406. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  407. --- mpfr-4.1.0-a/VERSION 2021-02-11 12:46:49.115316335 +0000
  408. +++ mpfr-4.1.0-b/VERSION 2021-02-11 12:48:27.370242746 +0000
  409. @@ -1 +1 @@
  410. -4.1.0-p3
  411. +4.1.0-p4
  412. diff -Naurd mpfr-4.1.0-a/src/atan.c mpfr-4.1.0-b/src/atan.c
  413. --- mpfr-4.1.0-a/src/atan.c 2020-04-22 15:27:07.000000000 +0000
  414. +++ mpfr-4.1.0-b/src/atan.c 2021-02-11 12:48:27.354242922 +0000
  415. @@ -56,7 +56,7 @@
  416. };
  417. static void
  418. -set_table (mpfr_t y, const mp_limb_t x[3])
  419. +set_table (mpfr_ptr y, const mp_limb_t x[3])
  420. {
  421. mpfr_prec_t p = MPFR_PREC(y);
  422. mp_size_t n = MPFR_PREC2LIMBS(p);
  423. diff -Naurd mpfr-4.1.0-a/src/const_euler.c mpfr-4.1.0-b/src/const_euler.c
  424. --- mpfr-4.1.0-a/src/const_euler.c 2020-01-08 18:11:13.000000000 +0000
  425. +++ mpfr-4.1.0-b/src/const_euler.c 2021-02-11 12:48:27.354242922 +0000
  426. @@ -181,7 +181,7 @@
  427. }
  428. int
  429. -mpfr_const_euler_internal (mpfr_t x, mpfr_rnd_t rnd)
  430. +mpfr_const_euler_internal (mpfr_ptr x, mpfr_rnd_t rnd)
  431. {
  432. mpfr_const_euler_bs_t sum;
  433. mpz_t t, u, v;
  434. diff -Naurd mpfr-4.1.0-a/src/eint.c mpfr-4.1.0-b/src/eint.c
  435. --- mpfr-4.1.0-a/src/eint.c 2020-03-09 15:31:45.000000000 +0000
  436. +++ mpfr-4.1.0-b/src/eint.c 2021-02-11 12:48:27.354242922 +0000
  437. @@ -36,7 +36,7 @@
  438. Return PREC(y) when the truncated series does not converge.
  439. */
  440. static mpfr_exp_t
  441. -mpfr_eint_aux (mpfr_t y, mpfr_srcptr x)
  442. +mpfr_eint_aux (mpfr_ptr y, mpfr_srcptr x)
  443. {
  444. mpfr_t eps; /* dynamic (absolute) error bound on t */
  445. mpfr_t erru, errs;
  446. diff -Naurd mpfr-4.1.0-a/src/erandom.c mpfr-4.1.0-b/src/erandom.c
  447. --- mpfr-4.1.0-a/src/erandom.c 2020-01-08 18:11:13.000000000 +0000
  448. +++ mpfr-4.1.0-b/src/erandom.c 2021-02-11 12:48:27.354242922 +0000
  449. @@ -80,7 +80,7 @@
  450. /* return an exponential random deviate with mean 1 as a MPFR */
  451. int
  452. -mpfr_erandom (mpfr_t z, gmp_randstate_t r, mpfr_rnd_t rnd)
  453. +mpfr_erandom (mpfr_ptr z, gmp_randstate_t r, mpfr_rnd_t rnd)
  454. {
  455. mpfr_random_deviate_t x, p, q;
  456. int inex;
  457. diff -Naurd mpfr-4.1.0-a/src/fpif.c mpfr-4.1.0-b/src/fpif.c
  458. --- mpfr-4.1.0-a/src/fpif.c 2020-01-08 18:11:13.000000000 +0000
  459. +++ mpfr-4.1.0-b/src/fpif.c 2021-02-11 12:48:27.354242922 +0000
  460. @@ -291,7 +291,8 @@
  461. * until one has integer types larger than 128 bits).
  462. */
  463. static unsigned char*
  464. -mpfr_fpif_store_exponent (unsigned char *buffer, size_t *buffer_size, mpfr_t x)
  465. +mpfr_fpif_store_exponent (unsigned char *buffer, size_t *buffer_size,
  466. + mpfr_ptr x)
  467. {
  468. unsigned char *result;
  469. mpfr_uexp_t uexp;
  470. @@ -372,7 +373,7 @@
  471. * than 128 bits).
  472. */
  473. static int
  474. -mpfr_fpif_read_exponent_from_file (mpfr_t x, FILE * fh)
  475. +mpfr_fpif_read_exponent_from_file (mpfr_ptr x, FILE * fh)
  476. {
  477. mpfr_exp_t exponent;
  478. mpfr_uexp_t uexp;
  479. @@ -456,7 +457,7 @@
  480. * format
  481. */
  482. static unsigned char*
  483. -mpfr_fpif_store_limbs (unsigned char *buffer, size_t *buffer_size, mpfr_t x)
  484. +mpfr_fpif_store_limbs (unsigned char *buffer, size_t *buffer_size, mpfr_ptr x)
  485. {
  486. unsigned char *result;
  487. mpfr_prec_t precision;
  488. @@ -492,7 +493,7 @@
  489. * Assume buffer is not NULL.
  490. */
  491. static void
  492. -mpfr_fpif_read_limbs (mpfr_t x, unsigned char *buffer, size_t nb_byte)
  493. +mpfr_fpif_read_limbs (mpfr_ptr x, unsigned char *buffer, size_t nb_byte)
  494. {
  495. size_t mp_bytes_per_limb;
  496. size_t nb_partial_byte;
  497. @@ -522,7 +523,7 @@
  498. * return 0 if successful
  499. */
  500. int
  501. -mpfr_fpif_export (FILE *fh, mpfr_t x)
  502. +mpfr_fpif_export (FILE *fh, mpfr_ptr x)
  503. {
  504. int status;
  505. unsigned char *buf;
  506. @@ -582,7 +583,7 @@
  507. * Return 0 if the import was successful.
  508. */
  509. int
  510. -mpfr_fpif_import (mpfr_t x, FILE *fh)
  511. +mpfr_fpif_import (mpfr_ptr x, FILE *fh)
  512. {
  513. int status;
  514. mpfr_prec_t precision;
  515. diff -Naurd mpfr-4.1.0-a/src/li2.c mpfr-4.1.0-b/src/li2.c
  516. --- mpfr-4.1.0-a/src/li2.c 2020-01-08 18:11:13.000000000 +0000
  517. +++ mpfr-4.1.0-b/src/li2.c 2021-02-11 12:48:27.354242922 +0000
  518. @@ -31,7 +31,7 @@
  519. for determinating the relative error.
  520. */
  521. static int
  522. -li2_series (mpfr_t sum, mpfr_srcptr z, mpfr_rnd_t rnd_mode)
  523. +li2_series (mpfr_ptr sum, mpfr_srcptr z, mpfr_rnd_t rnd_mode)
  524. {
  525. int i;
  526. mpfr_t s, u, v, w;
  527. diff -Naurd mpfr-4.1.0-a/src/lngamma.c mpfr-4.1.0-b/src/lngamma.c
  528. --- mpfr-4.1.0-a/src/lngamma.c 2020-01-08 18:11:13.000000000 +0000
  529. +++ mpfr-4.1.0-b/src/lngamma.c 2021-02-11 12:48:27.354242922 +0000
  530. @@ -31,7 +31,7 @@
  531. precision should be >= 4.
  532. */
  533. static void
  534. -mpfr_gamma_alpha (mpfr_t s, mpfr_prec_t p)
  535. +mpfr_gamma_alpha (mpfr_ptr s, mpfr_prec_t p)
  536. {
  537. MPFR_LOG_FUNC
  538. (("p=%Pu", p),
  539. diff -Naurd mpfr-4.1.0-a/src/mpfr-impl.h mpfr-4.1.0-b/src/mpfr-impl.h
  540. --- mpfr-4.1.0-a/src/mpfr-impl.h 2020-06-10 21:50:12.000000000 +0000
  541. +++ mpfr-4.1.0-b/src/mpfr-impl.h 2021-02-11 12:48:27.354242922 +0000
  542. @@ -2474,7 +2474,8 @@
  543. __MPFR_DECLSPEC mpz_srcptr mpfr_bernoulli_cache (unsigned long);
  544. __MPFR_DECLSPEC void mpfr_bernoulli_freecache (void);
  545. -__MPFR_DECLSPEC int mpfr_sincos_fast (mpfr_t, mpfr_t, mpfr_srcptr, mpfr_rnd_t);
  546. +__MPFR_DECLSPEC int mpfr_sincos_fast (mpfr_ptr, mpfr_ptr, mpfr_srcptr,
  547. + mpfr_rnd_t);
  548. __MPFR_DECLSPEC double mpfr_scale2 (double, int);
  549. @@ -2485,7 +2486,7 @@
  550. mpfr_prec_t);
  551. __MPFR_DECLSPEC void mpfr_mpz_init (mpz_ptr);
  552. -__MPFR_DECLSPEC void mpfr_mpz_init2 (mpz_t, mp_bitcnt_t);
  553. +__MPFR_DECLSPEC void mpfr_mpz_init2 (mpz_ptr, mp_bitcnt_t);
  554. __MPFR_DECLSPEC void mpfr_mpz_clear (mpz_ptr);
  555. __MPFR_DECLSPEC int mpfr_odd_p (mpfr_srcptr);
  556. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  557. --- mpfr-4.1.0-a/src/mpfr.h 2021-02-11 12:46:49.115316335 +0000
  558. +++ mpfr-4.1.0-b/src/mpfr.h 2021-02-11 12:48:27.366242791 +0000
  559. @@ -27,7 +27,7 @@
  560. #define MPFR_VERSION_MAJOR 4
  561. #define MPFR_VERSION_MINOR 1
  562. #define MPFR_VERSION_PATCHLEVEL 0
  563. -#define MPFR_VERSION_STRING "4.1.0-p3"
  564. +#define MPFR_VERSION_STRING "4.1.0-p4"
  565. /* User macros:
  566. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  567. @@ -781,8 +781,8 @@
  568. __MPFR_DECLSPEC int mpfr_strtofr (mpfr_ptr, const char *, char **, int,
  569. mpfr_rnd_t);
  570. -__MPFR_DECLSPEC void mpfr_round_nearest_away_begin (mpfr_t);
  571. -__MPFR_DECLSPEC int mpfr_round_nearest_away_end (mpfr_t, int);
  572. +__MPFR_DECLSPEC void mpfr_round_nearest_away_begin (mpfr_ptr);
  573. +__MPFR_DECLSPEC int mpfr_round_nearest_away_end (mpfr_ptr, int);
  574. __MPFR_DECLSPEC size_t mpfr_custom_get_size (mpfr_prec_t);
  575. __MPFR_DECLSPEC void mpfr_custom_init (void *, mpfr_prec_t);
  576. @@ -1080,10 +1080,12 @@
  577. #define mpfr_set_uj_2exp __gmpfr_set_uj_2exp
  578. #define mpfr_get_sj __gmpfr_mpfr_get_sj
  579. #define mpfr_get_uj __gmpfr_mpfr_get_uj
  580. -__MPFR_DECLSPEC int mpfr_set_sj (mpfr_t, intmax_t, mpfr_rnd_t);
  581. -__MPFR_DECLSPEC int mpfr_set_sj_2exp (mpfr_t, intmax_t, intmax_t, mpfr_rnd_t);
  582. -__MPFR_DECLSPEC int mpfr_set_uj (mpfr_t, uintmax_t, mpfr_rnd_t);
  583. -__MPFR_DECLSPEC int mpfr_set_uj_2exp (mpfr_t, uintmax_t, intmax_t, mpfr_rnd_t);
  584. +__MPFR_DECLSPEC int mpfr_set_sj (mpfr_ptr, intmax_t, mpfr_rnd_t);
  585. +__MPFR_DECLSPEC int mpfr_set_sj_2exp (mpfr_ptr, intmax_t, intmax_t,
  586. + mpfr_rnd_t);
  587. +__MPFR_DECLSPEC int mpfr_set_uj (mpfr_ptr, uintmax_t, mpfr_rnd_t);
  588. +__MPFR_DECLSPEC int mpfr_set_uj_2exp (mpfr_ptr, uintmax_t, intmax_t,
  589. + mpfr_rnd_t);
  590. __MPFR_DECLSPEC intmax_t mpfr_get_sj (mpfr_srcptr, mpfr_rnd_t);
  591. __MPFR_DECLSPEC uintmax_t mpfr_get_uj (mpfr_srcptr, mpfr_rnd_t);
  592. diff -Naurd mpfr-4.1.0-a/src/nrandom.c mpfr-4.1.0-b/src/nrandom.c
  593. --- mpfr-4.1.0-a/src/nrandom.c 2020-01-08 18:11:13.000000000 +0000
  594. +++ mpfr-4.1.0-b/src/nrandom.c 2021-02-11 12:48:27.354242922 +0000
  595. @@ -155,7 +155,7 @@
  596. /* return a normal random deviate with mean 0 and variance 1 as a MPFR */
  597. int
  598. -mpfr_nrandom (mpfr_t z, gmp_randstate_t r, mpfr_rnd_t rnd)
  599. +mpfr_nrandom (mpfr_ptr z, gmp_randstate_t r, mpfr_rnd_t rnd)
  600. {
  601. mpfr_random_deviate_t x, p, q;
  602. int inex;
  603. diff -Naurd mpfr-4.1.0-a/src/pool.c mpfr-4.1.0-b/src/pool.c
  604. --- mpfr-4.1.0-a/src/pool.c 2020-01-08 18:11:13.000000000 +0000
  605. +++ mpfr-4.1.0-b/src/pool.c 2021-02-11 12:48:27.354242922 +0000
  606. @@ -35,7 +35,7 @@
  607. static MPFR_THREAD_ATTR __mpz_struct mpz_tab[MPFR_POOL_NENTRIES];
  608. MPFR_HOT_FUNCTION_ATTR void
  609. -mpfr_mpz_init (mpz_t z)
  610. +mpfr_mpz_init (mpz_ptr z)
  611. {
  612. if (MPFR_LIKELY (n_alloc > 0))
  613. {
  614. @@ -54,7 +54,7 @@
  615. }
  616. MPFR_HOT_FUNCTION_ATTR void
  617. -mpfr_mpz_init2 (mpz_t z, mp_bitcnt_t n)
  618. +mpfr_mpz_init2 (mpz_ptr z, mp_bitcnt_t n)
  619. {
  620. /* The condition on n is used below as the argument n will be ignored if
  621. the mpz_t is obtained from the MPFR stack of previously used mpz_t.
  622. @@ -82,7 +82,7 @@
  623. MPFR_HOT_FUNCTION_ATTR void
  624. -mpfr_mpz_clear (mpz_t z)
  625. +mpfr_mpz_clear (mpz_ptr z)
  626. {
  627. /* We only put objects with at most MPFR_POOL_MAX_SIZE in the mpz_t pool,
  628. to avoid it takes too much memory (and anyway the speedup is mainly
  629. diff -Naurd mpfr-4.1.0-a/src/random_deviate.c mpfr-4.1.0-b/src/random_deviate.c
  630. --- mpfr-4.1.0-a/src/random_deviate.c 2021-02-11 12:43:51.789257562 +0000
  631. +++ mpfr-4.1.0-b/src/random_deviate.c 2021-02-11 12:48:27.354242922 +0000
  632. @@ -64,7 +64,7 @@
  633. /* allocate and set to (0,1) */
  634. void
  635. -mpfr_random_deviate_init (mpfr_random_deviate_t x)
  636. +mpfr_random_deviate_init (mpfr_random_deviate_ptr x)
  637. {
  638. mpz_init (x->f);
  639. x->e = 0;
  640. @@ -72,21 +72,22 @@
  641. /* reset to (0,1) */
  642. void
  643. -mpfr_random_deviate_reset (mpfr_random_deviate_t x)
  644. +mpfr_random_deviate_reset (mpfr_random_deviate_ptr x)
  645. {
  646. x->e = 0;
  647. }
  648. /* deallocate */
  649. void
  650. -mpfr_random_deviate_clear (mpfr_random_deviate_t x)
  651. +mpfr_random_deviate_clear (mpfr_random_deviate_ptr x)
  652. {
  653. mpz_clear (x->f);
  654. }
  655. /* swap two random deviates */
  656. void
  657. -mpfr_random_deviate_swap (mpfr_random_deviate_t x, mpfr_random_deviate_t y)
  658. +mpfr_random_deviate_swap (mpfr_random_deviate_ptr x,
  659. + mpfr_random_deviate_ptr y)
  660. {
  661. mpfr_random_size_t s;
  662. unsigned long t;
  663. @@ -107,7 +108,7 @@
  664. /* ensure x has at least k bits */
  665. static void
  666. -random_deviate_generate (mpfr_random_deviate_t x, mpfr_random_size_t k,
  667. +random_deviate_generate (mpfr_random_deviate_ptr x, mpfr_random_size_t k,
  668. gmp_randstate_t r, mpz_t t)
  669. {
  670. /* Various compile time checks on mpfr_random_deviate_t */
  671. @@ -223,7 +224,7 @@
  672. /* return position of leading bit, counting from 1 */
  673. static mpfr_random_size_t
  674. -random_deviate_leading_bit (mpfr_random_deviate_t x, gmp_randstate_t r)
  675. +random_deviate_leading_bit (mpfr_random_deviate_ptr x, gmp_randstate_t r)
  676. {
  677. mpfr_random_size_t l;
  678. random_deviate_generate (x, W, r, 0);
  679. @@ -243,7 +244,7 @@
  680. /* return kth bit of fraction, representing 2^-k */
  681. int
  682. -mpfr_random_deviate_tstbit (mpfr_random_deviate_t x, mpfr_random_size_t k,
  683. +mpfr_random_deviate_tstbit (mpfr_random_deviate_ptr x, mpfr_random_size_t k,
  684. gmp_randstate_t r)
  685. {
  686. if (k == 0)
  687. @@ -256,7 +257,8 @@
  688. /* compare two random deviates, x < y */
  689. int
  690. -mpfr_random_deviate_less (mpfr_random_deviate_t x, mpfr_random_deviate_t y,
  691. +mpfr_random_deviate_less (mpfr_random_deviate_ptr x,
  692. + mpfr_random_deviate_ptr y,
  693. gmp_randstate_t r)
  694. {
  695. mpfr_random_size_t k = 1;
  696. @@ -280,7 +282,7 @@
  697. /* set mpfr_t z = (neg ? -1 : 1) * (n + x) */
  698. int
  699. mpfr_random_deviate_value (int neg, unsigned long n,
  700. - mpfr_random_deviate_t x, mpfr_t z,
  701. + mpfr_random_deviate_ptr x, mpfr_ptr z,
  702. gmp_randstate_t r, mpfr_rnd_t rnd)
  703. {
  704. /* r is used to add as many bits as necessary to match the precision of z */
  705. diff -Naurd mpfr-4.1.0-a/src/random_deviate.h mpfr-4.1.0-b/src/random_deviate.h
  706. --- mpfr-4.1.0-a/src/random_deviate.h 2020-01-08 18:11:13.000000000 +0000
  707. +++ mpfr-4.1.0-b/src/random_deviate.h 2021-02-11 12:48:27.354242922 +0000
  708. @@ -76,7 +76,7 @@
  709. /* set mpfr_t z = (neg ? -1 : 1) * (n + x) */
  710. __MPFR_DECLSPEC int
  711. mpfr_random_deviate_value (int, unsigned long,
  712. - mpfr_random_deviate_ptr, mpfr_t,
  713. + mpfr_random_deviate_ptr, mpfr_ptr,
  714. gmp_randstate_t, mpfr_rnd_t);
  715. #if defined(__cplusplus)
  716. diff -Naurd mpfr-4.1.0-a/src/rndna.c mpfr-4.1.0-b/src/rndna.c
  717. --- mpfr-4.1.0-a/src/rndna.c 2020-01-08 18:11:13.000000000 +0000
  718. +++ mpfr-4.1.0-b/src/rndna.c 2021-02-11 12:48:27.354242922 +0000
  719. @@ -61,7 +61,7 @@
  720. and prepares rop to give it one more bit of precision
  721. and to save its old value within it. */
  722. void
  723. -mpfr_round_nearest_away_begin (mpfr_t rop)
  724. +mpfr_round_nearest_away_begin (mpfr_ptr rop)
  725. {
  726. mpfr_t tmp;
  727. mp_size_t xsize;
  728. @@ -129,7 +129,7 @@
  729. copying it back the result of the applied function
  730. and performing additional roundings. */
  731. int
  732. -mpfr_round_nearest_away_end (mpfr_t rop, int inex)
  733. +mpfr_round_nearest_away_end (mpfr_ptr rop, int inex)
  734. {
  735. mpfr_t tmp;
  736. mp_size_t xsize;
  737. diff -Naurd mpfr-4.1.0-a/src/set_sj.c mpfr-4.1.0-b/src/set_sj.c
  738. --- mpfr-4.1.0-a/src/set_sj.c 2020-06-01 10:39:52.000000000 +0000
  739. +++ mpfr-4.1.0-b/src/set_sj.c 2021-02-11 12:48:27.354242922 +0000
  740. @@ -26,13 +26,13 @@
  741. #ifdef _MPFR_H_HAVE_INTMAX_T
  742. int
  743. -mpfr_set_sj (mpfr_t x, intmax_t j, mpfr_rnd_t rnd)
  744. +mpfr_set_sj (mpfr_ptr x, intmax_t j, mpfr_rnd_t rnd)
  745. {
  746. return mpfr_set_sj_2exp (x, j, 0, rnd);
  747. }
  748. int
  749. -mpfr_set_sj_2exp (mpfr_t x, intmax_t j, intmax_t e, mpfr_rnd_t rnd)
  750. +mpfr_set_sj_2exp (mpfr_ptr x, intmax_t j, intmax_t e, mpfr_rnd_t rnd)
  751. {
  752. if (j >= 0)
  753. return mpfr_set_uj_2exp (x, j, e, rnd);
  754. diff -Naurd mpfr-4.1.0-a/src/set_str.c mpfr-4.1.0-b/src/set_str.c
  755. --- mpfr-4.1.0-a/src/set_str.c 2020-01-08 18:11:13.000000000 +0000
  756. +++ mpfr-4.1.0-b/src/set_str.c 2021-02-11 12:48:27.354242922 +0000
  757. @@ -23,7 +23,7 @@
  758. #include "mpfr-impl.h"
  759. int
  760. -mpfr_set_str (mpfr_t x, const char *str, int base, mpfr_rnd_t rnd)
  761. +mpfr_set_str (mpfr_ptr x, const char *str, int base, mpfr_rnd_t rnd)
  762. {
  763. char *p;
  764. diff -Naurd mpfr-4.1.0-a/src/set_uj.c mpfr-4.1.0-b/src/set_uj.c
  765. --- mpfr-4.1.0-a/src/set_uj.c 2020-06-01 10:39:52.000000000 +0000
  766. +++ mpfr-4.1.0-b/src/set_uj.c 2021-02-11 12:48:27.354242922 +0000
  767. @@ -29,13 +29,13 @@
  768. #define uintmaxpml (sizeof(uintmax_t) / sizeof(mp_limb_t))
  769. int
  770. -mpfr_set_uj (mpfr_t x, uintmax_t j, mpfr_rnd_t rnd)
  771. +mpfr_set_uj (mpfr_ptr x, uintmax_t j, mpfr_rnd_t rnd)
  772. {
  773. return mpfr_set_uj_2exp (x, j, 0, rnd);
  774. }
  775. int
  776. -mpfr_set_uj_2exp (mpfr_t x, uintmax_t j, intmax_t e, mpfr_rnd_t rnd)
  777. +mpfr_set_uj_2exp (mpfr_ptr x, uintmax_t j, intmax_t e, mpfr_rnd_t rnd)
  778. {
  779. int cnt, inex;
  780. mp_size_t i, k;
  781. diff -Naurd mpfr-4.1.0-a/src/sin_cos.c mpfr-4.1.0-b/src/sin_cos.c
  782. --- mpfr-4.1.0-a/src/sin_cos.c 2020-01-08 18:11:13.000000000 +0000
  783. +++ mpfr-4.1.0-b/src/sin_cos.c 2021-02-11 12:48:27.354242922 +0000
  784. @@ -463,7 +463,7 @@
  785. Return err such that the relative error is bounded by 2^err ulps.
  786. */
  787. static int
  788. -sincos_aux (mpfr_t s, mpfr_t c, mpfr_srcptr x, mpfr_rnd_t rnd_mode)
  789. +sincos_aux (mpfr_ptr s, mpfr_ptr c, mpfr_srcptr x, mpfr_rnd_t rnd_mode)
  790. {
  791. mpfr_prec_t prec_s, sh;
  792. mpz_t Q, S, C, Q2, S2, C2, y;
  793. @@ -577,7 +577,7 @@
  794. Assumes s differs from c.
  795. */
  796. int
  797. -mpfr_sincos_fast (mpfr_t s, mpfr_t c, mpfr_srcptr x, mpfr_rnd_t rnd)
  798. +mpfr_sincos_fast (mpfr_ptr s, mpfr_ptr c, mpfr_srcptr x, mpfr_rnd_t rnd)
  799. {
  800. int inexs, inexc;
  801. mpfr_t x_red, ts, tc;
  802. diff -Naurd mpfr-4.1.0-a/src/strtofr.c mpfr-4.1.0-b/src/strtofr.c
  803. --- mpfr-4.1.0-a/src/strtofr.c 2020-01-08 18:11:13.000000000 +0000
  804. +++ mpfr-4.1.0-b/src/strtofr.c 2021-02-11 12:48:27.354242922 +0000
  805. @@ -226,7 +226,7 @@
  806. BUT if it returns 0 (NAN or INF), the ternary value is also '0'
  807. (ie NAN and INF are exact) */
  808. static int
  809. -parse_string (mpfr_t x, struct parsed_string *pstr,
  810. +parse_string (mpfr_ptr x, struct parsed_string *pstr,
  811. const char **string, int base)
  812. {
  813. const char *str = *string;
  814. @@ -451,7 +451,7 @@
  815. and the precision of x.
  816. Returns the ternary value. */
  817. static int
  818. -parsed_string_to_mpfr (mpfr_t x, struct parsed_string *pstr, mpfr_rnd_t rnd)
  819. +parsed_string_to_mpfr (mpfr_ptr x, struct parsed_string *pstr, mpfr_rnd_t rnd)
  820. {
  821. mpfr_prec_t precx, prec, ysize_bits, pstr_size;
  822. mpfr_exp_t exp;
  823. @@ -934,7 +934,7 @@
  824. }
  825. int
  826. -mpfr_strtofr (mpfr_t x, const char *string, char **end, int base,
  827. +mpfr_strtofr (mpfr_ptr x, const char *string, char **end, int base,
  828. mpfr_rnd_t rnd)
  829. {
  830. int res;
  831. diff -Naurd mpfr-4.1.0-a/src/vasprintf.c mpfr-4.1.0-b/src/vasprintf.c
  832. --- mpfr-4.1.0-a/src/vasprintf.c 2020-06-01 10:39:52.000000000 +0000
  833. +++ mpfr-4.1.0-b/src/vasprintf.c 2021-02-11 12:48:27.354242922 +0000
  834. @@ -963,7 +963,7 @@
  835. #define NDIGITS 8
  836. MPFR_RETURNS_NONNULL static char *
  837. -mpfr_get_str_wrapper (mpfr_exp_t *exp, int base, size_t n, const mpfr_t op,
  838. +mpfr_get_str_wrapper (mpfr_exp_t *exp, int base, size_t n, mpfr_srcptr op,
  839. const struct printf_spec spec)
  840. {
  841. size_t ndigits;
  842. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  843. --- mpfr-4.1.0-a/src/version.c 2021-02-11 12:46:49.115316335 +0000
  844. +++ mpfr-4.1.0-b/src/version.c 2021-02-11 12:48:27.370242746 +0000
  845. @@ -25,5 +25,5 @@
  846. const char *
  847. mpfr_get_version (void)
  848. {
  849. - return "4.1.0-p3";
  850. + return "4.1.0-p4";
  851. }
  852. diff -Naurd mpfr-4.1.0-a/src/zeta.c mpfr-4.1.0-b/src/zeta.c
  853. --- mpfr-4.1.0-a/src/zeta.c 2020-01-08 18:11:13.000000000 +0000
  854. +++ mpfr-4.1.0-b/src/zeta.c 2021-02-11 12:48:27.354242922 +0000
  855. @@ -35,7 +35,7 @@
  856. sum(tc[i]*product((s+2j)*(s+2j-1)/n^2,j=1..i-1), i=1..p)*s*n^(-s-1)
  857. */
  858. static void
  859. -mpfr_zeta_part_b (mpfr_t b, mpfr_srcptr s, int n, int p, mpfr_t *tc)
  860. +mpfr_zeta_part_b (mpfr_ptr b, mpfr_srcptr s, int n, int p, mpfr_t *tc)
  861. {
  862. mpfr_t s1, d, u;
  863. unsigned long n2;
  864. @@ -130,7 +130,7 @@
  865. n - an integer
  866. Output: sum - a floating-point number approximating sum(1/i^s, i=1..n-1) */
  867. static void
  868. -mpfr_zeta_part_a (mpfr_t sum, mpfr_srcptr s, int n)
  869. +mpfr_zeta_part_a (mpfr_ptr sum, mpfr_srcptr s, int n)
  870. {
  871. mpfr_t u, s1;
  872. int i;
  873. @@ -158,7 +158,7 @@
  874. Output: z - Zeta(s) rounded to the precision of z with direction rnd_mode
  875. */
  876. static int
  877. -mpfr_zeta_pos (mpfr_t z, mpfr_srcptr s, mpfr_rnd_t rnd_mode)
  878. +mpfr_zeta_pos (mpfr_ptr z, mpfr_srcptr s, mpfr_rnd_t rnd_mode)
  879. {
  880. mpfr_t b, c, z_pre, f, s1;
  881. double beta, sd, dnep;
  882. @@ -356,8 +356,8 @@
  883. At input, p is Pi rounded down.
  884. The comments in the code are for rnd = RNDD. */
  885. static void
  886. -mpfr_reflection_overflow (mpfr_t z, mpfr_t s1, const mpfr_t s, mpfr_t y,
  887. - mpfr_t p, mpfr_rnd_t rnd)
  888. +mpfr_reflection_overflow (mpfr_ptr z, mpfr_ptr s1, mpfr_srcptr s, mpfr_ptr y,
  889. + mpfr_ptr p, mpfr_rnd_t rnd)
  890. {
  891. mpz_t sint;
  892. @@ -432,7 +432,7 @@
  893. }
  894. int
  895. -mpfr_zeta (mpfr_t z, mpfr_srcptr s, mpfr_rnd_t rnd_mode)
  896. +mpfr_zeta (mpfr_ptr z, mpfr_srcptr s, mpfr_rnd_t rnd_mode)
  897. {
  898. mpfr_t z_pre, s1, y, p;
  899. long add;
  900. diff -Naurd mpfr-4.1.0-a/tests/tcmp2.c mpfr-4.1.0-b/tests/tcmp2.c
  901. --- mpfr-4.1.0-a/tests/tcmp2.c 2020-01-08 18:11:13.000000000 +0000
  902. +++ mpfr-4.1.0-b/tests/tcmp2.c 2021-02-11 12:48:27.350242965 +0000
  903. @@ -24,7 +24,7 @@
  904. /* set bit n of x to b, where bit 0 is the most significant one */
  905. static void
  906. -set_bit (mpfr_t x, unsigned int n, int b)
  907. +set_bit (mpfr_ptr x, unsigned int n, int b)
  908. {
  909. unsigned l;
  910. mp_size_t xn;
  911. diff -Naurd mpfr-4.1.0-a/tests/tdiv.c mpfr-4.1.0-b/tests/tdiv.c
  912. --- mpfr-4.1.0-a/tests/tdiv.c 2020-01-08 18:11:13.000000000 +0000
  913. +++ mpfr-4.1.0-b/tests/tdiv.c 2021-02-11 12:48:27.350242965 +0000
  914. @@ -369,7 +369,7 @@
  915. /* given y = o(x/u), x, u, find the inexact flag by
  916. multiplying y by u */
  917. static int
  918. -get_inexact (mpfr_t y, mpfr_t x, mpfr_t u)
  919. +get_inexact (mpfr_ptr y, mpfr_ptr x, mpfr_ptr u)
  920. {
  921. mpfr_t xx;
  922. int inex;
  923. diff -Naurd mpfr-4.1.0-a/tests/teq.c mpfr-4.1.0-b/tests/teq.c
  924. --- mpfr-4.1.0-a/tests/teq.c 2020-01-08 18:11:13.000000000 +0000
  925. +++ mpfr-4.1.0-b/tests/teq.c 2021-02-11 12:48:27.350242965 +0000
  926. @@ -23,7 +23,7 @@
  927. #include "mpfr-test.h"
  928. static void
  929. -teq (mpfr_t x)
  930. +teq (mpfr_ptr x)
  931. {
  932. mpfr_t y;
  933. unsigned long k, px, mx;
  934. diff -Naurd mpfr-4.1.0-a/tests/terandom_chisq.c mpfr-4.1.0-b/tests/terandom_chisq.c
  935. --- mpfr-4.1.0-a/tests/terandom_chisq.c 2020-01-08 18:11:13.000000000 +0000
  936. +++ mpfr-4.1.0-b/tests/terandom_chisq.c 2021-02-11 12:48:27.350242965 +0000
  937. @@ -26,7 +26,7 @@
  938. * exponential distribution. We only take differences of this function so the
  939. * offset doesn't matter; here Phi(0) = 0. */
  940. static void
  941. -exponential_cumulative (mpfr_t z, mpfr_t x, mpfr_rnd_t rnd)
  942. +exponential_cumulative (mpfr_ptr z, mpfr_ptr x, mpfr_rnd_t rnd)
  943. {
  944. mpfr_neg (z, x, rnd);
  945. mpfr_expm1 (z, z, rnd);
  946. @@ -43,7 +43,7 @@
  947. * TAOCP, Vol 2, 3.3.1, Table 1. It more accurate than the similar formula,
  948. * DLMF 8.11.10. */
  949. static void
  950. -chisq_prob (mpfr_t q, long nu, mpfr_t chisqp)
  951. +chisq_prob (mpfr_ptr q, long nu, mpfr_ptr chisqp)
  952. {
  953. mpfr_t t;
  954. mpfr_rnd_t rnd;
  955. @@ -170,7 +170,7 @@
  956. * this function. low precision means prec = 2, 3, or 4. High values of
  957. * precision will result in integer overflow. */
  958. static long
  959. -sequential (mpfr_t x)
  960. +sequential (mpfr_ptr x)
  961. {
  962. long expt, prec;
  963. diff -Naurd mpfr-4.1.0-a/tests/tfmma.c mpfr-4.1.0-b/tests/tfmma.c
  964. --- mpfr-4.1.0-a/tests/tfmma.c 2020-03-24 13:47:38.000000000 +0000
  965. +++ mpfr-4.1.0-b/tests/tfmma.c 2021-02-11 12:48:27.350242965 +0000
  966. @@ -24,7 +24,7 @@
  967. /* check both mpfr_fmma and mpfr_fmms */
  968. static void
  969. -random_test (mpfr_t a, mpfr_t b, mpfr_t c, mpfr_t d, mpfr_rnd_t rnd)
  970. +random_test (mpfr_ptr a, mpfr_ptr b, mpfr_ptr c, mpfr_ptr d, mpfr_rnd_t rnd)
  971. {
  972. mpfr_t ref, res, ab, cd;
  973. int inex_ref, inex_res;
  974. diff -Naurd mpfr-4.1.0-a/tests/tfmod.c mpfr-4.1.0-b/tests/tfmod.c
  975. --- mpfr-4.1.0-a/tests/tfmod.c 2020-01-08 18:11:13.000000000 +0000
  976. +++ mpfr-4.1.0-b/tests/tfmod.c 2021-02-11 12:48:27.350242965 +0000
  977. @@ -62,8 +62,8 @@
  978. }
  979. static void
  980. -test_failed (mpfr_t erem, mpfr_t grem, int eret, int gret, mpfr_t x, mpfr_t y,
  981. - mpfr_rnd_t rnd)
  982. +test_failed (mpfr_ptr erem, mpfr_ptr grem, int eret, int gret,
  983. + mpfr_ptr x, mpfr_ptr y, mpfr_rnd_t rnd)
  984. {
  985. printf ("error: mpfr_fmod (r, x, y, rnd)\n x = ");
  986. mpfr_out_str (stdout, 10, 0, x, MPFR_RNDD);
  987. @@ -83,7 +83,7 @@
  988. }
  989. static void
  990. -check (mpfr_t r0, mpfr_t x, mpfr_t y, mpfr_rnd_t rnd)
  991. +check (mpfr_ptr r0, mpfr_ptr x, mpfr_ptr y, mpfr_rnd_t rnd)
  992. {
  993. int inex0, inex1;
  994. mpfr_t r1;
  995. diff -Naurd mpfr-4.1.0-a/tests/tfprintf.c mpfr-4.1.0-b/tests/tfprintf.c
  996. --- mpfr-4.1.0-a/tests/tfprintf.c 2020-06-01 10:39:52.000000000 +0000
  997. +++ mpfr-4.1.0-b/tests/tfprintf.c 2021-02-11 12:48:27.350242965 +0000
  998. @@ -65,7 +65,7 @@
  999. const int prec_max_printf = 5000;
  1000. static void
  1001. -check (FILE *fout, const char *fmt, mpfr_t x)
  1002. +check (FILE *fout, const char *fmt, mpfr_ptr x)
  1003. {
  1004. if (mpfr_fprintf (fout, fmt, x) == -1)
  1005. {
  1006. diff -Naurd mpfr-4.1.0-a/tests/tgamma.c mpfr-4.1.0-b/tests/tgamma.c
  1007. --- mpfr-4.1.0-a/tests/tgamma.c 2020-06-01 00:15:37.000000000 +0000
  1008. +++ mpfr-4.1.0-b/tests/tgamma.c 2021-02-11 12:48:27.350242965 +0000
  1009. @@ -890,7 +890,7 @@
  1010. computing with a working precision p2. Assume that x is not an
  1011. integer <= 2. */
  1012. static void
  1013. -exp_lgamma (mpfr_t x, mpfr_prec_t p1, mpfr_prec_t p2)
  1014. +exp_lgamma (mpfr_ptr x, mpfr_prec_t p1, mpfr_prec_t p2)
  1015. {
  1016. mpfr_t yd, yu, zd, zu;
  1017. int inexd, inexu, sign;
  1018. diff -Naurd mpfr-4.1.0-a/tests/tnrandom_chisq.c mpfr-4.1.0-b/tests/tnrandom_chisq.c
  1019. --- mpfr-4.1.0-a/tests/tnrandom_chisq.c 2020-01-08 18:11:13.000000000 +0000
  1020. +++ mpfr-4.1.0-b/tests/tnrandom_chisq.c 2021-02-11 12:48:27.350242965 +0000
  1021. @@ -26,7 +26,7 @@
  1022. * for the normal distribution. We only take differences of this function so
  1023. * the offset doesn't matter; here Phi(0) = 0. */
  1024. static void
  1025. -normal_cumulative (mpfr_t z, mpfr_t x, mpfr_rnd_t rnd)
  1026. +normal_cumulative (mpfr_ptr z, mpfr_ptr x, mpfr_rnd_t rnd)
  1027. {
  1028. mpfr_sqrt_ui (z, 2, rnd);
  1029. mpfr_div (z, x, z, rnd);
  1030. @@ -44,7 +44,7 @@
  1031. * TAOCP, Vol 2, 3.3.1, Table 1. It more accurate than the similar formula,
  1032. * DLMF 8.11.10. */
  1033. static void
  1034. -chisq_prob (mpfr_t q, long nu, mpfr_t chisqp)
  1035. +chisq_prob (mpfr_ptr q, long nu, mpfr_ptr chisqp)
  1036. {
  1037. mpfr_t t;
  1038. mpfr_rnd_t rnd;
  1039. @@ -166,7 +166,7 @@
  1040. * this function. low precision means prec = 2, 3, or 4. High values of
  1041. * precision will result in integer overflow. */
  1042. static long
  1043. -sequential (mpfr_t x)
  1044. +sequential (mpfr_ptr x)
  1045. {
  1046. long expt, prec;
  1047. diff -Naurd mpfr-4.1.0-a/tests/tprintf.c mpfr-4.1.0-b/tests/tprintf.c
  1048. --- mpfr-4.1.0-a/tests/tprintf.c 2020-06-01 10:39:52.000000000 +0000
  1049. +++ mpfr-4.1.0-b/tests/tprintf.c 2021-02-11 12:48:27.350242965 +0000
  1050. @@ -74,7 +74,7 @@
  1051. int stdout_redirect;
  1052. static void
  1053. -check (const char *fmt, mpfr_t x)
  1054. +check (const char *fmt, mpfr_ptr x)
  1055. {
  1056. if (mpfr_printf (fmt, x) == -1)
  1057. {
  1058. diff -Naurd mpfr-4.1.0-a/tests/trint.c mpfr-4.1.0-b/tests/trint.c
  1059. --- mpfr-4.1.0-a/tests/trint.c 2020-02-12 13:04:50.000000000 +0000
  1060. +++ mpfr-4.1.0-b/tests/trint.c 2021-02-11 12:48:27.350242965 +0000
  1061. @@ -367,7 +367,7 @@
  1062. #endif
  1063. static void
  1064. -err (const char *str, mp_size_t s, mpfr_t x, mpfr_t y, mpfr_prec_t p,
  1065. +err (const char *str, mp_size_t s, mpfr_ptr x, mpfr_ptr y, mpfr_prec_t p,
  1066. mpfr_rnd_t r, int trint, int inexact)
  1067. {
  1068. printf ("Error: %s\ns = %u, p = %u, r = %s, trint = %d, inexact = %d\nx = ",
  1069. diff -Naurd mpfr-4.1.0-a/tests/tsinh_cosh.c mpfr-4.1.0-b/tests/tsinh_cosh.c
  1070. --- mpfr-4.1.0-a/tests/tsinh_cosh.c 2020-01-08 18:11:13.000000000 +0000
  1071. +++ mpfr-4.1.0-b/tests/tsinh_cosh.c 2021-02-11 12:48:27.350242965 +0000
  1072. @@ -23,7 +23,7 @@
  1073. #include "mpfr-test.h"
  1074. static void
  1075. -failed (mpfr_t x, mpfr_t esh, mpfr_t gsh, mpfr_t ech, mpfr_t gch)
  1076. +failed (mpfr_ptr x, mpfr_ptr esh, mpfr_ptr gsh, mpfr_ptr ech, mpfr_ptr gch)
  1077. {
  1078. printf ("error : mpfr_sinh_cosh (x) x = ");
  1079. mpfr_out_str (stdout, 10, 0, x, MPFR_RNDD);
  1080. @@ -43,7 +43,7 @@
  1081. /* check against sinh, cosh */
  1082. static void
  1083. -check (mpfr_t x, mpfr_rnd_t rnd)
  1084. +check (mpfr_ptr x, mpfr_rnd_t rnd)
  1085. {
  1086. mpfr_t s, c, sx, cx;
  1087. int isc, is, ic;
  1088. diff -Naurd mpfr-4.1.0-a/tests/tsqr.c mpfr-4.1.0-b/tests/tsqr.c
  1089. --- mpfr-4.1.0-a/tests/tsqr.c 2020-01-08 18:11:13.000000000 +0000
  1090. +++ mpfr-4.1.0-b/tests/tsqr.c 2021-02-11 12:48:27.350242965 +0000
  1091. @@ -33,7 +33,7 @@
  1092. static void
  1093. error1 (mpfr_rnd_t rnd, mpfr_prec_t prec,
  1094. - mpfr_t in, mpfr_t outmul, mpfr_t outsqr)
  1095. + mpfr_t in, mpfr_ptr outmul, mpfr_ptr outsqr)
  1096. {
  1097. printf("ERROR: for %s and prec=%lu\nINPUT=", mpfr_print_rnd_mode(rnd),
  1098. (unsigned long) prec);
  1099. @@ -44,7 +44,7 @@
  1100. }
  1101. static void
  1102. -error2 (mpfr_rnd_t rnd, mpfr_prec_t prec, mpfr_t in, mpfr_t out,
  1103. +error2 (mpfr_rnd_t rnd, mpfr_prec_t prec, mpfr_ptr in, mpfr_ptr out,
  1104. int inexactmul, int inexactsqr)
  1105. {
  1106. printf("ERROR: for %s and prec=%lu\nINPUT=", mpfr_print_rnd_mode(rnd),
  1107. diff -Naurd mpfr-4.1.0-a/tests/tsum.c mpfr-4.1.0-b/tests/tsum.c
  1108. --- mpfr-4.1.0-a/tests/tsum.c 2020-01-08 18:11:13.000000000 +0000
  1109. +++ mpfr-4.1.0-b/tests/tsum.c 2021-02-11 12:48:27.350242965 +0000
  1110. @@ -59,7 +59,7 @@
  1111. }
  1112. static void
  1113. -get_exact_sum (mpfr_t sum, mpfr_t *tab, int n)
  1114. +get_exact_sum (mpfr_ptr sum, mpfr_t *tab, int n)
  1115. {
  1116. int i;
  1117. @@ -1198,7 +1198,7 @@
  1118. }
  1119. static int
  1120. -mpfr_sum_naive (mpfr_t s, mpfr_t *x, int n, mpfr_rnd_t rnd)
  1121. +mpfr_sum_naive (mpfr_ptr s, mpfr_t *x, int n, mpfr_rnd_t rnd)
  1122. {
  1123. int ret, i;
  1124. switch (n)
  1125. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  1126. --- mpfr-4.1.0-a/PATCHES 2021-02-11 12:50:22.384987438 +0000
  1127. +++ mpfr-4.1.0-b/PATCHES 2021-02-11 12:50:22.424987002 +0000
  1128. @@ -0,0 +1 @@
  1129. +digamma-hugemem
  1130. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  1131. --- mpfr-4.1.0-a/VERSION 2021-02-11 12:48:27.370242746 +0000
  1132. +++ mpfr-4.1.0-b/VERSION 2021-02-11 12:50:22.424987002 +0000
  1133. @@ -1 +1 @@
  1134. -4.1.0-p4
  1135. +4.1.0-p5
  1136. diff -Naurd mpfr-4.1.0-a/src/digamma.c mpfr-4.1.0-b/src/digamma.c
  1137. --- mpfr-4.1.0-a/src/digamma.c 2020-06-18 17:17:18.000000000 +0000
  1138. +++ mpfr-4.1.0-b/src/digamma.c 2021-02-11 12:50:22.412987133 +0000
  1139. @@ -214,19 +214,27 @@
  1140. (("x[%Pu]=%.*Rg rnd=%d", mpfr_get_prec(x), mpfr_log_prec, x, rnd_mode),
  1141. ("y[%Pu]=%.*Rg inexact=%d", mpfr_get_prec(y), mpfr_log_prec, y, inex));
  1142. - /* compute a precision q such that x+1 is exact */
  1143. - if (MPFR_PREC(x) < MPFR_GET_EXP(x))
  1144. - q = MPFR_EXP(x);
  1145. - else
  1146. - q = MPFR_PREC(x) + 1;
  1147. -
  1148. - /* for very large x, use |digamma(x) - log(x)| < 1/x < 2^(1-EXP(x)) */
  1149. - if (MPFR_PREC(y) + 10 < MPFR_EXP(x))
  1150. + /* For very large x, use |digamma(x) - log(x)| < 1/x < 2^(1-EXP(x)).
  1151. + However, for a fixed value of GUARD, MPFR_CAN_ROUND() might fail
  1152. + with probability 1/2^GUARD, in which case the default code will
  1153. + fail since it requires x+1 to be exact, thus a huge precision if
  1154. + x is huge. There are two workarounds:
  1155. + * either perform a Ziv's loop, by increasing GUARD at each step.
  1156. + However, this might fail if x is moderately large, in which case
  1157. + more terms of the asymptotic expansion would be needed.
  1158. + * implement a full asymptotic expansion (with Ziv's loop). */
  1159. +#define GUARD 30
  1160. + if (MPFR_PREC(y) + GUARD < MPFR_EXP(x))
  1161. {
  1162. /* this ensures EXP(x) >= 3, thus x >= 4, thus log(x) > 1 */
  1163. - mpfr_init2 (t, MPFR_PREC(y) + 10);
  1164. - mpfr_log (t, x, MPFR_RNDZ);
  1165. - if (MPFR_CAN_ROUND (t, MPFR_PREC(y) + 10, MPFR_PREC(y), rnd_mode))
  1166. + mpfr_init2 (t, MPFR_PREC(y) + GUARD);
  1167. + mpfr_log (t, x, MPFR_RNDN);
  1168. + /* |t - digamma(x)| <= 1/2*ulp(t) + |digamma(x) - log(x)|
  1169. + <= 1/2*ulp(t) + 2^(1-EXP(x))
  1170. + <= 1/2*ulp(t) + 2^(-PREC(y)-GUARD)
  1171. + <= ulp(t)
  1172. + since |t| >= 1 thus ulp(t) >= 2^(1-PREC(y)-GUARD) */
  1173. + if (MPFR_CAN_ROUND (t, MPFR_PREC(y) + GUARD, MPFR_PREC(y), rnd_mode))
  1174. {
  1175. inex = mpfr_set (y, t, rnd_mode);
  1176. mpfr_clear (t);
  1177. @@ -235,6 +243,21 @@
  1178. mpfr_clear (t);
  1179. }
  1180. + /* compute a precision q such that x+1 is exact */
  1181. + if (MPFR_PREC(x) < MPFR_GET_EXP(x))
  1182. + {
  1183. + /* The goal of the first assertion is to let the compiler ignore
  1184. + the second one when MPFR_EMAX_MAX <= MPFR_PREC_MAX. */
  1185. + MPFR_ASSERTD (MPFR_EXP(x) <= MPFR_EMAX_MAX);
  1186. + MPFR_ASSERTN (MPFR_EXP(x) <= MPFR_PREC_MAX);
  1187. + q = MPFR_EXP(x);
  1188. + }
  1189. + else
  1190. + q = MPFR_PREC(x) + 1;
  1191. +
  1192. + /* FIXME: q can be much too large, e.g. equal to the maximum exponent! */
  1193. + MPFR_LOG_MSG (("q=%Pu\n", q));
  1194. +
  1195. mpfr_init2 (x_plus_j, q);
  1196. mpfr_init2 (t, p);
  1197. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  1198. --- mpfr-4.1.0-a/src/mpfr.h 2021-02-11 12:48:27.366242791 +0000
  1199. +++ mpfr-4.1.0-b/src/mpfr.h 2021-02-11 12:50:22.424987002 +0000
  1200. @@ -27,7 +27,7 @@
  1201. #define MPFR_VERSION_MAJOR 4
  1202. #define MPFR_VERSION_MINOR 1
  1203. #define MPFR_VERSION_PATCHLEVEL 0
  1204. -#define MPFR_VERSION_STRING "4.1.0-p4"
  1205. +#define MPFR_VERSION_STRING "4.1.0-p5"
  1206. /* User macros:
  1207. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  1208. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  1209. --- mpfr-4.1.0-a/src/version.c 2021-02-11 12:48:27.370242746 +0000
  1210. +++ mpfr-4.1.0-b/src/version.c 2021-02-11 12:50:22.424987002 +0000
  1211. @@ -25,5 +25,5 @@
  1212. const char *
  1213. mpfr_get_version (void)
  1214. {
  1215. - return "4.1.0-p4";
  1216. + return "4.1.0-p5";
  1217. }
  1218. diff -Naurd mpfr-4.1.0-a/tests/tdigamma.c mpfr-4.1.0-b/tests/tdigamma.c
  1219. --- mpfr-4.1.0-a/tests/tdigamma.c 2020-06-18 17:17:18.000000000 +0000
  1220. +++ mpfr-4.1.0-b/tests/tdigamma.c 2021-02-11 12:50:22.412987133 +0000
  1221. @@ -49,12 +49,54 @@
  1222. mpfr_clear (y);
  1223. }
  1224. +/* With some GMP_CHECK_RANDOMIZE values, test_generic triggers an error
  1225. + tests_addsize(): too much memory (576460752303432776 bytes)
  1226. + Each time on prec = 200, n = 3, xprec = 140.
  1227. + The following test is a more general testcase.
  1228. +*/
  1229. +static void
  1230. +bug20210206 (void)
  1231. +{
  1232. +#define NPREC 4
  1233. + mpfr_t x, y[NPREC], z;
  1234. + mpfr_exp_t emin, emax;
  1235. + int i, precx, precy[NPREC] = { 200, 400, 520, 1416 };
  1236. +
  1237. + emin = mpfr_get_emin ();
  1238. + emax = mpfr_get_emax ();
  1239. + set_emin (MPFR_EMIN_MIN);
  1240. + set_emax (MPFR_EMAX_MAX);
  1241. +
  1242. + for (i = 0; i < NPREC; i++)
  1243. + mpfr_init2 (y[i], precy[i]);
  1244. + mpfr_init2 (z, precy[0]);
  1245. +
  1246. + for (precx = MPFR_PREC_MIN; precx < 150; precx++)
  1247. + {
  1248. + mpfr_init2 (x, precx);
  1249. + mpfr_setmax (x, __gmpfr_emax);
  1250. + for (i = 0; i < NPREC; i++)
  1251. + mpfr_digamma (y[i], x, MPFR_RNDA);
  1252. + mpfr_set (z, y[1], MPFR_RNDA);
  1253. + MPFR_ASSERTN (mpfr_equal_p (y[0], z));
  1254. + mpfr_clear (x);
  1255. + }
  1256. +
  1257. + for (i = 0; i < NPREC; i++)
  1258. + mpfr_clear (y[i]);
  1259. + mpfr_clear (z);
  1260. +
  1261. + set_emin (emin);
  1262. + set_emax (emax);
  1263. +}
  1264. +
  1265. int
  1266. main (int argc, char *argv[])
  1267. {
  1268. tests_start_mpfr ();
  1269. special ();
  1270. + bug20210206 ();
  1271. test_generic (MPFR_PREC_MIN, 200, 20);
  1272. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  1273. --- mpfr-4.1.0-a/PATCHES 2021-02-11 12:52:52.519350662 +0000
  1274. +++ mpfr-4.1.0-b/PATCHES 2021-02-11 12:52:52.563350183 +0000
  1275. @@ -0,0 +1 @@
  1276. +digamma-interm-zero
  1277. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  1278. --- mpfr-4.1.0-a/VERSION 2021-02-11 12:50:22.424987002 +0000
  1279. +++ mpfr-4.1.0-b/VERSION 2021-02-11 12:52:52.563350183 +0000
  1280. @@ -1 +1 @@
  1281. -4.1.0-p5
  1282. +4.1.0-p6
  1283. diff -Naurd mpfr-4.1.0-a/src/digamma.c mpfr-4.1.0-b/src/digamma.c
  1284. --- mpfr-4.1.0-a/src/digamma.c 2021-02-11 12:50:22.412987133 +0000
  1285. +++ mpfr-4.1.0-b/src/digamma.c 2021-02-11 12:52:52.547350357 +0000
  1286. @@ -296,21 +296,26 @@
  1287. errt = mpfr_digamma_approx (t, x_plus_j);
  1288. expt = MPFR_GET_EXP (t);
  1289. mpfr_sub (t, t, u, MPFR_RNDN);
  1290. - if (MPFR_GET_EXP (t) < expt)
  1291. - errt += expt - MPFR_EXP(t);
  1292. - /* Warning: if u is zero (which happens when x_plus_j >= min at the
  1293. - beginning of the while loop above), EXP(u) is not defined.
  1294. - In this case we have no error from u. */
  1295. - if (MPFR_NOTZERO(u) && MPFR_GET_EXP (t) < MPFR_GET_EXP (u))
  1296. - erru += MPFR_EXP(u) - MPFR_EXP(t);
  1297. - if (errt > erru)
  1298. - errt = errt + 1;
  1299. - else if (errt == erru)
  1300. - errt = errt + 2;
  1301. - else
  1302. - errt = erru + 1;
  1303. - if (MPFR_CAN_ROUND (t, p - errt, MPFR_PREC(y), rnd_mode))
  1304. - break;
  1305. + /* Warning! t may be zero (more likely in small precision). Note
  1306. + that in this case, this is an exact zero, not an underflow. */
  1307. + if (MPFR_NOTZERO(t))
  1308. + {
  1309. + if (MPFR_GET_EXP (t) < expt)
  1310. + errt += expt - MPFR_EXP(t);
  1311. + /* Warning: if u is zero (which happens when x_plus_j >= min at the
  1312. + beginning of the while loop above), EXP(u) is not defined.
  1313. + In this case we have no error from u. */
  1314. + if (MPFR_NOTZERO(u) && MPFR_GET_EXP (t) < MPFR_GET_EXP (u))
  1315. + erru += MPFR_EXP(u) - MPFR_EXP(t);
  1316. + if (errt > erru)
  1317. + errt = errt + 1;
  1318. + else if (errt == erru)
  1319. + errt = errt + 2;
  1320. + else
  1321. + errt = erru + 1;
  1322. + if (MPFR_CAN_ROUND (t, p - errt, MPFR_PREC(y), rnd_mode))
  1323. + break;
  1324. + }
  1325. MPFR_ZIV_NEXT (loop, p);
  1326. mpfr_set_prec (t, p);
  1327. mpfr_set_prec (u, p);
  1328. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  1329. --- mpfr-4.1.0-a/src/mpfr.h 2021-02-11 12:50:22.424987002 +0000
  1330. +++ mpfr-4.1.0-b/src/mpfr.h 2021-02-11 12:52:52.559350226 +0000
  1331. @@ -27,7 +27,7 @@
  1332. #define MPFR_VERSION_MAJOR 4
  1333. #define MPFR_VERSION_MINOR 1
  1334. #define MPFR_VERSION_PATCHLEVEL 0
  1335. -#define MPFR_VERSION_STRING "4.1.0-p5"
  1336. +#define MPFR_VERSION_STRING "4.1.0-p6"
  1337. /* User macros:
  1338. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  1339. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  1340. --- mpfr-4.1.0-a/src/version.c 2021-02-11 12:50:22.424987002 +0000
  1341. +++ mpfr-4.1.0-b/src/version.c 2021-02-11 12:52:52.559350226 +0000
  1342. @@ -25,5 +25,5 @@
  1343. const char *
  1344. mpfr_get_version (void)
  1345. {
  1346. - return "4.1.0-p5";
  1347. + return "4.1.0-p6";
  1348. }
  1349. diff -Naurd mpfr-4.1.0-a/tests/tdigamma.c mpfr-4.1.0-b/tests/tdigamma.c
  1350. --- mpfr-4.1.0-a/tests/tdigamma.c 2021-02-11 12:50:22.412987133 +0000
  1351. +++ mpfr-4.1.0-b/tests/tdigamma.c 2021-02-11 12:52:52.547350357 +0000
  1352. @@ -90,6 +90,26 @@
  1353. set_emax (emax);
  1354. }
  1355. +/* another test that fails with GMP_CHECK_RANDOMIZE=1612741376857003
  1356. + on revision 14398 */
  1357. +static void
  1358. +bug20210208 (void)
  1359. +{
  1360. + mpfr_t x, y;
  1361. + int inex;
  1362. +
  1363. + mpfr_init2 (x, 73);
  1364. + mpfr_init2 (y, 1);
  1365. + mpfr_set_str (x, "1.4613470547060071827450", 10, MPFR_RNDN);
  1366. + mpfr_clear_flags ();
  1367. + inex = mpfr_digamma (y, x, MPFR_RNDU);
  1368. + MPFR_ASSERTN (mpfr_cmp_si_2exp (y, -1, -12) == 0);
  1369. + MPFR_ASSERTN (inex > 0);
  1370. + MPFR_ASSERTN (__gmpfr_flags == MPFR_FLAGS_INEXACT);
  1371. + mpfr_clear (x);
  1372. + mpfr_clear (y);
  1373. +}
  1374. +
  1375. int
  1376. main (int argc, char *argv[])
  1377. {
  1378. @@ -97,6 +117,7 @@
  1379. special ();
  1380. bug20210206 ();
  1381. + bug20210208 ();
  1382. test_generic (MPFR_PREC_MIN, 200, 20);
  1383. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  1384. --- mpfr-4.1.0-a/PATCHES 2021-02-11 12:53:38.382850990 +0000
  1385. +++ mpfr-4.1.0-b/PATCHES 2021-02-11 12:53:38.426850512 +0000
  1386. @@ -0,0 +1 @@
  1387. +jn-interm-zero
  1388. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  1389. --- mpfr-4.1.0-a/VERSION 2021-02-11 12:52:52.563350183 +0000
  1390. +++ mpfr-4.1.0-b/VERSION 2021-02-11 12:53:38.426850512 +0000
  1391. @@ -1 +1 @@
  1392. -4.1.0-p6
  1393. +4.1.0-p7
  1394. diff -Naurd mpfr-4.1.0-a/src/jyn_asympt.c mpfr-4.1.0-b/src/jyn_asympt.c
  1395. --- mpfr-4.1.0-a/src/jyn_asympt.c 2020-07-10 10:33:32.000000000 +0000
  1396. +++ mpfr-4.1.0-b/src/jyn_asympt.c 2021-02-11 12:53:38.410850685 +0000
  1397. @@ -69,6 +69,8 @@
  1398. MPFR_ZIV_INIT (loop, w);
  1399. for (;;)
  1400. {
  1401. + int ok = 1;
  1402. +
  1403. mpfr_set_prec (c, w);
  1404. mpfr_init2 (s, w);
  1405. mpfr_init2 (P, w);
  1406. @@ -92,6 +94,13 @@
  1407. /* now s approximates sin(z)+cos(z), and c approximates sin(z)-cos(z),
  1408. with total absolute error bounded by 2^(1-w). */
  1409. + /* if s or c is zero, MPFR_GET_EXP will fail below */
  1410. + if (MPFR_IS_ZERO(s) || MPFR_IS_ZERO(c))
  1411. + {
  1412. + ok = 0;
  1413. + goto clear;
  1414. + }
  1415. +
  1416. /* precompute 1/(8|z|) */
  1417. mpfr_si_div (iz, MPFR_IS_POS(z) ? 1 : -1, z, MPFR_RNDN); /* err <= 1 */
  1418. mpfr_div_2ui (iz, iz, 3, MPFR_RNDN);
  1419. @@ -257,6 +266,9 @@
  1420. err = (err >= err2) ? err + 1 : err2 + 1;
  1421. /* the absolute error on c is bounded by 2^(err - w) */
  1422. + err -= MPFR_GET_EXP (c);
  1423. +
  1424. + clear:
  1425. mpfr_clear (s);
  1426. mpfr_clear (P);
  1427. mpfr_clear (Q);
  1428. @@ -266,8 +278,7 @@
  1429. mpfr_clear (err_s);
  1430. mpfr_clear (err_u);
  1431. - err -= MPFR_GET_EXP (c);
  1432. - if (MPFR_LIKELY (MPFR_CAN_ROUND (c, w - err, MPFR_PREC(res), r)))
  1433. + if (ok && MPFR_LIKELY (MPFR_CAN_ROUND (c, w - err, MPFR_PREC(res), r)))
  1434. break;
  1435. if (diverge != 0)
  1436. {
  1437. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  1438. --- mpfr-4.1.0-a/src/mpfr.h 2021-02-11 12:52:52.559350226 +0000
  1439. +++ mpfr-4.1.0-b/src/mpfr.h 2021-02-11 12:53:38.422850555 +0000
  1440. @@ -27,7 +27,7 @@
  1441. #define MPFR_VERSION_MAJOR 4
  1442. #define MPFR_VERSION_MINOR 1
  1443. #define MPFR_VERSION_PATCHLEVEL 0
  1444. -#define MPFR_VERSION_STRING "4.1.0-p6"
  1445. +#define MPFR_VERSION_STRING "4.1.0-p7"
  1446. /* User macros:
  1447. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  1448. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  1449. --- mpfr-4.1.0-a/src/version.c 2021-02-11 12:52:52.559350226 +0000
  1450. +++ mpfr-4.1.0-b/src/version.c 2021-02-11 12:53:38.426850512 +0000
  1451. @@ -25,5 +25,5 @@
  1452. const char *
  1453. mpfr_get_version (void)
  1454. {
  1455. - return "4.1.0-p6";
  1456. + return "4.1.0-p7";
  1457. }
  1458. diff -Naurd mpfr-4.1.0-a/tests/tj0.c mpfr-4.1.0-b/tests/tj0.c
  1459. --- mpfr-4.1.0-a/tests/tj0.c 2020-01-08 18:11:13.000000000 +0000
  1460. +++ mpfr-4.1.0-b/tests/tj0.c 2021-02-11 12:53:38.410850685 +0000
  1461. @@ -27,6 +27,25 @@
  1462. #define REDUCE_EMAX 262143 /* otherwise arg. reduction is too expensive */
  1463. #include "tgeneric.c"
  1464. +/* bug found in revision 14399 with GMP_CHECK_RANDOMIZE=1612721106588971 */
  1465. +static void
  1466. +bug20210208 (void)
  1467. +{
  1468. + mpfr_t x, y;
  1469. + int inex;
  1470. +
  1471. + mpfr_init2 (x, 79);
  1472. + mpfr_init2 (y, 1);
  1473. + mpfr_set_str (x, "2.552495117262005805960565e+02", 10, MPFR_RNDN);
  1474. + mpfr_clear_flags ();
  1475. + inex = mpfr_j0 (y, x, MPFR_RNDZ);
  1476. + MPFR_ASSERTN (mpfr_cmp_si_2exp (y, -1, -5) == 0);
  1477. + MPFR_ASSERTN (inex > 0);
  1478. + MPFR_ASSERTN (__gmpfr_flags == MPFR_FLAGS_INEXACT);
  1479. + mpfr_clear (x);
  1480. + mpfr_clear (y);
  1481. +}
  1482. +
  1483. int
  1484. main (int argc, char *argv[])
  1485. {
  1486. @@ -35,6 +54,8 @@
  1487. tests_start_mpfr ();
  1488. + bug20210208 ();
  1489. +
  1490. mpfr_init (x);
  1491. mpfr_init (y);
  1492. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  1493. --- mpfr-4.1.0-a/PATCHES 2021-02-17 17:22:34.594973310 +0000
  1494. +++ mpfr-4.1.0-b/PATCHES 2021-02-17 17:22:34.702972090 +0000
  1495. @@ -0,0 +1 @@
  1496. +digamma-interm-zero2
  1497. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  1498. --- mpfr-4.1.0-a/VERSION 2021-02-11 12:53:38.426850512 +0000
  1499. +++ mpfr-4.1.0-b/VERSION 2021-02-17 17:22:34.702972090 +0000
  1500. @@ -1 +1 @@
  1501. -4.1.0-p7
  1502. +4.1.0-p8
  1503. diff -Naurd mpfr-4.1.0-a/src/digamma.c mpfr-4.1.0-b/src/digamma.c
  1504. --- mpfr-4.1.0-a/src/digamma.c 2021-02-11 12:52:52.547350357 +0000
  1505. +++ mpfr-4.1.0-b/src/digamma.c 2021-02-17 17:22:34.690972226 +0000
  1506. @@ -173,16 +173,19 @@
  1507. mpfr_digamma (v, u, MPFR_RNDN); /* error <= 1/2 ulp */
  1508. expv = MPFR_GET_EXP (v);
  1509. mpfr_sub (v, v, t, MPFR_RNDN);
  1510. - if (MPFR_GET_EXP (v) < MPFR_GET_EXP (t))
  1511. - e1 += MPFR_EXP(t) - MPFR_EXP(v); /* scale error for t wrt new v */
  1512. - /* now take into account the 1/2 ulp error for v */
  1513. - if (expv - MPFR_EXP(v) - 1 > e1)
  1514. - e1 = expv - MPFR_EXP(v) - 1;
  1515. - else
  1516. - e1 ++;
  1517. - e1 ++; /* rounding error for mpfr_sub */
  1518. - if (MPFR_CAN_ROUND (v, p - e1, MPFR_PREC(y), rnd_mode))
  1519. - break;
  1520. + if (MPFR_NOTZERO(v))
  1521. + {
  1522. + if (MPFR_GET_EXP (v) < MPFR_GET_EXP (t))
  1523. + e1 += MPFR_EXP(t) - MPFR_EXP(v); /* scale error for t wrt new v */
  1524. + /* now take into account the 1/2 ulp error for v */
  1525. + if (expv - MPFR_EXP(v) - 1 > e1)
  1526. + e1 = expv - MPFR_EXP(v) - 1;
  1527. + else
  1528. + e1 ++;
  1529. + e1 ++; /* rounding error for mpfr_sub */
  1530. + if (MPFR_CAN_ROUND (v, p - e1, MPFR_PREC(y), rnd_mode))
  1531. + break;
  1532. + }
  1533. MPFR_ZIV_NEXT (loop, p);
  1534. mpfr_set_prec (t, p);
  1535. mpfr_set_prec (v, p);
  1536. @@ -416,10 +419,8 @@
  1537. }
  1538. }
  1539. - if (MPFR_IS_NEG(x))
  1540. - inex = mpfr_digamma_reflection (y, x, rnd_mode);
  1541. /* if x < 1/2 we use the reflection formula */
  1542. - else if (MPFR_EXP(x) < 0)
  1543. + if (MPFR_IS_NEG(x) || MPFR_EXP(x) < 0)
  1544. inex = mpfr_digamma_reflection (y, x, rnd_mode);
  1545. else
  1546. inex = mpfr_digamma_positive (y, x, rnd_mode);
  1547. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  1548. --- mpfr-4.1.0-a/src/mpfr.h 2021-02-11 12:53:38.422850555 +0000
  1549. +++ mpfr-4.1.0-b/src/mpfr.h 2021-02-17 17:22:34.702972090 +0000
  1550. @@ -27,7 +27,7 @@
  1551. #define MPFR_VERSION_MAJOR 4
  1552. #define MPFR_VERSION_MINOR 1
  1553. #define MPFR_VERSION_PATCHLEVEL 0
  1554. -#define MPFR_VERSION_STRING "4.1.0-p7"
  1555. +#define MPFR_VERSION_STRING "4.1.0-p8"
  1556. /* User macros:
  1557. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  1558. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  1559. --- mpfr-4.1.0-a/src/version.c 2021-02-11 12:53:38.426850512 +0000
  1560. +++ mpfr-4.1.0-b/src/version.c 2021-02-17 17:22:34.702972090 +0000
  1561. @@ -25,5 +25,5 @@
  1562. const char *
  1563. mpfr_get_version (void)
  1564. {
  1565. - return "4.1.0-p7";
  1566. + return "4.1.0-p8";
  1567. }
  1568. diff -Naurd mpfr-4.1.0-a/tests/tdigamma.c mpfr-4.1.0-b/tests/tdigamma.c
  1569. --- mpfr-4.1.0-a/tests/tdigamma.c 2021-02-11 12:52:52.547350357 +0000
  1570. +++ mpfr-4.1.0-b/tests/tdigamma.c 2021-02-17 17:22:34.690972226 +0000
  1571. @@ -110,6 +110,26 @@
  1572. mpfr_clear (y);
  1573. }
  1574. +/* another test that fails with GMP_CHECK_RANDOMIZE=1613197421465830
  1575. + on revision 14429 */
  1576. +static void
  1577. +bug20210215 (void)
  1578. +{
  1579. + mpfr_t x, y;
  1580. + int inex;
  1581. +
  1582. + mpfr_init2 (x, 510);
  1583. + mpfr_init2 (y, 4);
  1584. + mpfr_set_str (x, "-8.2923051438433494998166335341807999322052669984208422481227138906096000469898717007386115912802685588348601663465077353194268894939972221117314512518182580e+35", 10, MPFR_RNDN);
  1585. + mpfr_clear_flags ();
  1586. + inex = mpfr_digamma (y, x, MPFR_RNDU);
  1587. + MPFR_ASSERTN (mpfr_cmp_ui0 (y, 88) == 0);
  1588. + MPFR_ASSERTN (inex > 0);
  1589. + MPFR_ASSERTN (__gmpfr_flags == MPFR_FLAGS_INEXACT);
  1590. + mpfr_clear (x);
  1591. + mpfr_clear (y);
  1592. +}
  1593. +
  1594. int
  1595. main (int argc, char *argv[])
  1596. {
  1597. @@ -118,6 +138,7 @@
  1598. special ();
  1599. bug20210206 ();
  1600. bug20210208 ();
  1601. + bug20210215 ();
  1602. test_generic (MPFR_PREC_MIN, 200, 20);
  1603. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  1604. --- mpfr-4.1.0-a/PATCHES 2021-02-17 17:25:46.396981483 +0000
  1605. +++ mpfr-4.1.0-b/PATCHES 2021-02-17 17:25:46.440981068 +0000
  1606. @@ -0,0 +1 @@
  1607. +jyn_asympt-interm-zero
  1608. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  1609. --- mpfr-4.1.0-a/VERSION 2021-02-17 17:22:34.702972090 +0000
  1610. +++ mpfr-4.1.0-b/VERSION 2021-02-17 17:25:46.440981068 +0000
  1611. @@ -1 +1 @@
  1612. -4.1.0-p8
  1613. +4.1.0-p9
  1614. diff -Naurd mpfr-4.1.0-a/src/jyn_asympt.c mpfr-4.1.0-b/src/jyn_asympt.c
  1615. --- mpfr-4.1.0-a/src/jyn_asympt.c 2021-02-11 12:53:38.410850685 +0000
  1616. +++ mpfr-4.1.0-b/src/jyn_asympt.c 2021-02-17 17:25:46.424981219 +0000
  1617. @@ -69,7 +69,7 @@
  1618. MPFR_ZIV_INIT (loop, w);
  1619. for (;;)
  1620. {
  1621. - int ok = 1;
  1622. + int ok = 0;
  1623. mpfr_set_prec (c, w);
  1624. mpfr_init2 (s, w);
  1625. @@ -96,10 +96,7 @@
  1626. /* if s or c is zero, MPFR_GET_EXP will fail below */
  1627. if (MPFR_IS_ZERO(s) || MPFR_IS_ZERO(c))
  1628. - {
  1629. - ok = 0;
  1630. - goto clear;
  1631. - }
  1632. + goto clear; /* with ok=0 */
  1633. /* precompute 1/(8|z|) */
  1634. mpfr_si_div (iz, MPFR_IS_POS(z) ? 1 : -1, z, MPFR_RNDN); /* err <= 1 */
  1635. @@ -227,6 +224,9 @@
  1636. mpfr_sub (s, c, s, MPFR_RNDN);
  1637. #endif
  1638. }
  1639. + if (MPFR_IS_ZERO(s))
  1640. + goto clear; /* with ok=0 */
  1641. + ok = 1;
  1642. if ((n & 2) != 0)
  1643. mpfr_neg (s, s, MPFR_RNDN);
  1644. if (MPFR_GET_EXP (s) > err)
  1645. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  1646. --- mpfr-4.1.0-a/src/mpfr.h 2021-02-17 17:22:34.702972090 +0000
  1647. +++ mpfr-4.1.0-b/src/mpfr.h 2021-02-17 17:25:46.436981105 +0000
  1648. @@ -27,7 +27,7 @@
  1649. #define MPFR_VERSION_MAJOR 4
  1650. #define MPFR_VERSION_MINOR 1
  1651. #define MPFR_VERSION_PATCHLEVEL 0
  1652. -#define MPFR_VERSION_STRING "4.1.0-p8"
  1653. +#define MPFR_VERSION_STRING "4.1.0-p9"
  1654. /* User macros:
  1655. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  1656. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  1657. --- mpfr-4.1.0-a/src/version.c 2021-02-17 17:22:34.702972090 +0000
  1658. +++ mpfr-4.1.0-b/src/version.c 2021-02-17 17:25:46.440981068 +0000
  1659. @@ -25,5 +25,5 @@
  1660. const char *
  1661. mpfr_get_version (void)
  1662. {
  1663. - return "4.1.0-p8";
  1664. + return "4.1.0-p9";
  1665. }
  1666. diff -Naurd mpfr-4.1.0-a/tests/mpfr-test.h mpfr-4.1.0-b/tests/mpfr-test.h
  1667. --- mpfr-4.1.0-a/tests/mpfr-test.h 2020-06-29 13:57:32.000000000 +0000
  1668. +++ mpfr-4.1.0-b/tests/mpfr-test.h 2021-02-17 17:25:46.424981219 +0000
  1669. @@ -191,6 +191,8 @@
  1670. #define mpfr_cmp0(x,y) (MPFR_ASSERTN (!MPFR_IS_NAN (x) && !MPFR_IS_NAN (y)), mpfr_cmp (x,y))
  1671. #define mpfr_cmp_ui0(x,i) (MPFR_ASSERTN (!MPFR_IS_NAN (x)), mpfr_cmp_ui (x,i))
  1672. +#define mpfr_cmp_si_2exp0(x,i,e) (MPFR_ASSERTN (!MPFR_IS_NAN (x)), \
  1673. + mpfr_cmp_si_2exp (x,i,e))
  1674. /* define CHECK_EXTERNAL if you want to check mpfr against another library
  1675. with correct rounding. You'll probably have to modify mpfr_print_raw()
  1676. diff -Naurd mpfr-4.1.0-a/tests/tj1.c mpfr-4.1.0-b/tests/tj1.c
  1677. --- mpfr-4.1.0-a/tests/tj1.c 2020-01-08 18:11:13.000000000 +0000
  1678. +++ mpfr-4.1.0-b/tests/tj1.c 2021-02-17 17:25:46.424981219 +0000
  1679. @@ -55,14 +55,14 @@
  1680. /* since |x| is just above 2^e, |j1(x)| is just above 2^(e-1),
  1681. thus y should be 2^(e-1) and the inexact flag should be
  1682. of opposite sign of x */
  1683. - MPFR_ASSERTN(mpfr_cmp_si_2exp (y, sign, e - 1) == 0);
  1684. + MPFR_ASSERTN(mpfr_cmp_si_2exp0 (y, sign, e - 1) == 0);
  1685. MPFR_ASSERTN(VSIGN (inex) * sign < 0);
  1686. }
  1687. else
  1688. {
  1689. /* here |y| should be 0.5*2^emin and the inexact flag should
  1690. have the sign of x */
  1691. - MPFR_ASSERTN(mpfr_cmp_si_2exp (y, sign, e) == 0);
  1692. + MPFR_ASSERTN(mpfr_cmp_si_2exp0 (y, sign, e) == 0);
  1693. MPFR_ASSERTN(VSIGN (inex) * sign > 0);
  1694. }
  1695. }
  1696. @@ -72,6 +72,26 @@
  1697. mpfr_clear (y);
  1698. }
  1699. +/* a test that fails with GMP_CHECK_RANDOMIZE=1613146232984428
  1700. + on revision 14429 */
  1701. +static void
  1702. +bug20210215 (void)
  1703. +{
  1704. + mpfr_t x, y;
  1705. + int inex;
  1706. +
  1707. + mpfr_init2 (x, 221);
  1708. + mpfr_init2 (y, 1);
  1709. + mpfr_set_str (x, "1.6484611511696130037307738844228498447763863563070374544054791168614e+01", 10, MPFR_RNDN);
  1710. + mpfr_clear_flags ();
  1711. + inex = mpfr_j1 (y, x, MPFR_RNDZ);
  1712. + MPFR_ASSERTN (mpfr_cmp_si_2exp0 (y, -1, -9) == 0);
  1713. + MPFR_ASSERTN (inex > 0);
  1714. + MPFR_ASSERTN (__gmpfr_flags == MPFR_FLAGS_INEXACT);
  1715. + mpfr_clear (x);
  1716. + mpfr_clear (y);
  1717. +}
  1718. +
  1719. int
  1720. main (int argc, char *argv[])
  1721. {
  1722. @@ -79,6 +99,8 @@
  1723. tests_start_mpfr ();
  1724. + bug20210215 ();
  1725. +
  1726. test_small ();
  1727. mpfr_init (x);
  1728. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  1729. --- mpfr-4.1.0-a/PATCHES 2021-03-09 13:55:43.183158946 +0000
  1730. +++ mpfr-4.1.0-b/PATCHES 2021-03-09 13:55:43.223158508 +0000
  1731. @@ -0,0 +1 @@
  1732. +macros
  1733. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  1734. --- mpfr-4.1.0-a/VERSION 2021-02-17 17:25:46.440981068 +0000
  1735. +++ mpfr-4.1.0-b/VERSION 2021-03-09 13:55:43.223158508 +0000
  1736. @@ -1 +1 @@
  1737. -4.1.0-p9
  1738. +4.1.0-p10
  1739. diff -Naurd mpfr-4.1.0-a/doc/mpfr.info mpfr-4.1.0-b/doc/mpfr.info
  1740. --- mpfr-4.1.0-a/doc/mpfr.info 2020-07-10 11:59:13.000000000 +0000
  1741. +++ mpfr-4.1.0-b/doc/mpfr.info 2021-03-09 13:55:51.167071327 +0000
  1742. @@ -3217,7 +3217,11 @@
  1743. Each function in this interface is also implemented as a macro for
  1744. efficiency reasons: for example ‘mpfr_custom_init (s, p)’ uses the
  1745. -macro, while ‘(mpfr_custom_init) (s, p)’ uses the function.
  1746. +macro, while ‘(mpfr_custom_init) (s, p)’ uses the function. Note that
  1747. +the macro may evaluate arguments multiple times (or none). Moreover,
  1748. +macros implementing functions with the ‘void’ return type may not be
  1749. +used in contexts where an expression is expected, e.g., inside
  1750. +‘for(...)’ or before a comma operator.
  1751. Note 1: MPFR functions may still initialize temporary floating-point
  1752. numbers using ‘mpfr_init’ and similar functions. See Custom Allocation
  1753. @@ -4579,13 +4583,13 @@
  1754. (line 115)
  1755. * mpfr_csch: Transcendental Functions.
  1756. (line 180)
  1757. -* mpfr_custom_get_exp: Custom Interface. (line 76)
  1758. -* mpfr_custom_get_kind: Custom Interface. (line 66)
  1759. -* mpfr_custom_get_significand: Custom Interface. (line 71)
  1760. -* mpfr_custom_get_size: Custom Interface. (line 37)
  1761. -* mpfr_custom_init: Custom Interface. (line 41)
  1762. -* mpfr_custom_init_set: Custom Interface. (line 48)
  1763. -* mpfr_custom_move: Custom Interface. (line 85)
  1764. +* mpfr_custom_get_exp: Custom Interface. (line 80)
  1765. +* mpfr_custom_get_kind: Custom Interface. (line 70)
  1766. +* mpfr_custom_get_significand: Custom Interface. (line 75)
  1767. +* mpfr_custom_get_size: Custom Interface. (line 41)
  1768. +* mpfr_custom_init: Custom Interface. (line 45)
  1769. +* mpfr_custom_init_set: Custom Interface. (line 52)
  1770. +* mpfr_custom_move: Custom Interface. (line 89)
  1771. * MPFR_DECL_INIT: Initialization Functions.
  1772. (line 77)
  1773. * mpfr_digamma: Transcendental Functions.
  1774. @@ -5165,19 +5169,19 @@
  1775. Node: Memory Handling Functions155904
  1776. Node: Compatibility with MPF157792
  1777. Node: Custom Interface160961
  1778. -Node: Internals165592
  1779. -Node: API Compatibility167136
  1780. -Node: Type and Macro Changes169084
  1781. -Node: Added Functions172267
  1782. -Node: Changed Functions177074
  1783. -Node: Removed Functions184433
  1784. -Node: Other Changes185163
  1785. -Node: MPFR and the IEEE 754 Standard186864
  1786. -Node: Contributors189481
  1787. -Node: References192620
  1788. -Node: GNU Free Documentation License194501
  1789. -Node: Concept Index217095
  1790. -Node: Function and Type Index223168
  1791. +Node: Internals165852
  1792. +Node: API Compatibility167396
  1793. +Node: Type and Macro Changes169344
  1794. +Node: Added Functions172527
  1795. +Node: Changed Functions177334
  1796. +Node: Removed Functions184693
  1797. +Node: Other Changes185423
  1798. +Node: MPFR and the IEEE 754 Standard187124
  1799. +Node: Contributors189741
  1800. +Node: References192880
  1801. +Node: GNU Free Documentation License194761
  1802. +Node: Concept Index217355
  1803. +Node: Function and Type Index223428
  1804. 
  1805. End Tag Table
  1806. diff -Naurd mpfr-4.1.0-a/doc/mpfr.texi mpfr-4.1.0-b/doc/mpfr.texi
  1807. --- mpfr-4.1.0-a/doc/mpfr.texi 2020-07-10 11:52:33.000000000 +0000
  1808. +++ mpfr-4.1.0-b/doc/mpfr.texi 2021-03-09 13:55:43.211158639 +0000
  1809. @@ -3817,6 +3817,12 @@
  1810. Each function in this interface is also implemented as a macro for
  1811. efficiency reasons: for example @code{mpfr_custom_init (s, p)}
  1812. uses the macro, while @code{(mpfr_custom_init) (s, p)} uses the function.
  1813. +Note that the macro may evaluate arguments multiple times (or none).
  1814. +Moreover, macros implementing functions with the @code{void} return type
  1815. +may not be used in contexts where an expression is expected, e.g., inside
  1816. +@code{for(...)} or before a comma operator.
  1817. +@c These limitations with macros cannot be avoided in a C90 compatible way.
  1818. +@c In the future, inline functions could be used.
  1819. Note 1: MPFR functions may still initialize temporary floating-point numbers
  1820. using @code{mpfr_init} and similar functions. See Custom Allocation (GNU MP)@.
  1821. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  1822. --- mpfr-4.1.0-a/src/mpfr.h 2021-02-17 17:25:46.436981105 +0000
  1823. +++ mpfr-4.1.0-b/src/mpfr.h 2021-03-09 13:55:43.223158508 +0000
  1824. @@ -27,7 +27,7 @@
  1825. #define MPFR_VERSION_MAJOR 4
  1826. #define MPFR_VERSION_MINOR 1
  1827. #define MPFR_VERSION_PATCHLEVEL 0
  1828. -#define MPFR_VERSION_STRING "4.1.0-p9"
  1829. +#define MPFR_VERSION_STRING "4.1.0-p10"
  1830. /* User macros:
  1831. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  1832. @@ -833,23 +833,39 @@
  1833. even if it produces faster and smaller code. */
  1834. #ifndef MPFR_USE_NO_MACRO
  1835. -/* Inlining these functions is both faster and smaller */
  1836. -#define mpfr_nan_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_NAN)
  1837. -#define mpfr_inf_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_INF)
  1838. -#define mpfr_zero_p(_x) ((_x)->_mpfr_exp == __MPFR_EXP_ZERO)
  1839. -#define mpfr_regular_p(_x) ((_x)->_mpfr_exp > __MPFR_EXP_INF)
  1840. +/* In the implementation of these macros, we need to make sure that the
  1841. + arguments are evaluated one time exactly and that type conversion is
  1842. + done as it would be with a function. Tests should be added to ensure
  1843. + that.
  1844. + Note that the macros for the custom interface are not concerned; the
  1845. + MPFR manual has been clarified. */
  1846. +
  1847. +/* Prevent x from being used as an lvalue.
  1848. + Thanks to Wojtek Lerch and Tim Rentsch for the idea. */
  1849. +#define MPFR_VALUE_OF(x) (0 ? (x) : (x))
  1850. +
  1851. +/* The following macro converts the argument to mpfr_srcptr, as in type
  1852. + conversion for function parameters. But it will detect disallowed
  1853. + implicit conversions, e.g. when the argument has an integer type. */
  1854. +#define MPFR_SRCPTR(x) ((mpfr_srcptr) (0 ? (x) : (mpfr_srcptr) (x)))
  1855. +#define MPFR_GET_SIGN(_x) MPFR_VALUE_OF(MPFR_SIGN(MPFR_SRCPTR(_x)))
  1856. +
  1857. +#define mpfr_nan_p(_x) (MPFR_SRCPTR(_x)->_mpfr_exp == __MPFR_EXP_NAN)
  1858. +#define mpfr_inf_p(_x) (MPFR_SRCPTR(_x)->_mpfr_exp == __MPFR_EXP_INF)
  1859. +#define mpfr_zero_p(_x) (MPFR_SRCPTR(_x)->_mpfr_exp == __MPFR_EXP_ZERO)
  1860. +#define mpfr_regular_p(_x) (MPFR_SRCPTR(_x)->_mpfr_exp > __MPFR_EXP_INF)
  1861. +
  1862. +/* mpfr_sgn is documented as a macro, thus the following code is fine.
  1863. + But it would be safer to regard it as a function in some future
  1864. + MPFR version. */
  1865. #define mpfr_sgn(_x) \
  1866. ((_x)->_mpfr_exp < __MPFR_EXP_INF ? \
  1867. (mpfr_nan_p (_x) ? mpfr_set_erangeflag () : (mpfr_void) 0), 0 : \
  1868. MPFR_SIGN (_x))
  1869. -/* Prevent them from using as lvalues */
  1870. -#define MPFR_VALUE_OF(x) (0 ? (x) : (x))
  1871. -#define mpfr_get_prec(_x) MPFR_VALUE_OF((_x)->_mpfr_prec)
  1872. -#define mpfr_get_exp(_x) MPFR_VALUE_OF((_x)->_mpfr_exp)
  1873. -/* Note 1: If need be, the MPFR_VALUE_OF can be used for other expressions
  1874. - (of any type). Thanks to Wojtek Lerch and Tim Rentsch for the idea.
  1875. - Note 2: Defining mpfr_get_exp() as a macro has the effect to disable
  1876. +#define mpfr_get_prec(_x) MPFR_VALUE_OF(MPFR_SRCPTR(_x)->_mpfr_prec)
  1877. +#define mpfr_get_exp(_x) MPFR_VALUE_OF(MPFR_SRCPTR(_x)->_mpfr_exp)
  1878. +/* Note: Defining mpfr_get_exp() as a macro has the effect to disable
  1879. the check that the argument is a pure FP number (done in the function);
  1880. this increases the risk of undetected error and makes debugging more
  1881. complex. Is it really worth in practice? (Potential FIXME) */
  1882. @@ -861,11 +877,17 @@
  1883. #define mpfr_cmp_ui(b,i) mpfr_cmp_ui_2exp((b),(i),0)
  1884. #define mpfr_cmp_si(b,i) mpfr_cmp_si_2exp((b),(i),0)
  1885. -#define mpfr_set(a,b,r) mpfr_set4(a,b,r,MPFR_SIGN(b))
  1886. +#if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
  1887. +#define mpfr_set(a,b,r) \
  1888. + __extension__ ({ \
  1889. + mpfr_srcptr _p = (b); \
  1890. + mpfr_set4(a,_p,r,MPFR_SIGN(_p)); \
  1891. + })
  1892. +#endif
  1893. #define mpfr_abs(a,b,r) mpfr_set4(a,b,r,1)
  1894. -#define mpfr_copysign(a,b,c,r) mpfr_set4(a,b,r,MPFR_SIGN(c))
  1895. +#define mpfr_copysign(a,b,c,r) mpfr_set4(a,b,r,MPFR_GET_SIGN(c))
  1896. #define mpfr_setsign(a,b,s,r) mpfr_set4(a,b,r,(s) ? -1 : 1)
  1897. -#define mpfr_signbit(x) (MPFR_SIGN(x) < 0)
  1898. +#define mpfr_signbit(x) (MPFR_GET_SIGN(x) < 0)
  1899. #define mpfr_cmp(b, c) mpfr_cmp3(b, c, 1)
  1900. #define mpfr_mul_2exp(y,x,n,r) mpfr_mul_2ui((y),(x),(n),(r))
  1901. #define mpfr_div_2exp(y,x,n,r) mpfr_div_2ui((y),(x),(n),(r))
  1902. diff -Naurd mpfr-4.1.0-a/src/ubf.c mpfr-4.1.0-b/src/ubf.c
  1903. --- mpfr-4.1.0-a/src/ubf.c 2020-02-12 01:38:57.000000000 +0000
  1904. +++ mpfr-4.1.0-b/src/ubf.c 2021-03-09 13:55:43.211158639 +0000
  1905. @@ -78,7 +78,7 @@
  1906. mpfr_get_prec (b), mpfr_log_prec, b,
  1907. mpfr_get_prec (c), mpfr_log_prec, c),
  1908. ("a[%Pu]=%.*Rg",
  1909. - mpfr_get_prec (a), mpfr_log_prec, a));
  1910. + mpfr_get_prec ((mpfr_ptr) a), mpfr_log_prec, a));
  1911. MPFR_ASSERTD ((mpfr_ptr) a != b);
  1912. MPFR_ASSERTD ((mpfr_ptr) a != c);
  1913. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  1914. --- mpfr-4.1.0-a/src/version.c 2021-02-17 17:25:46.440981068 +0000
  1915. +++ mpfr-4.1.0-b/src/version.c 2021-03-09 13:55:43.223158508 +0000
  1916. @@ -25,5 +25,5 @@
  1917. const char *
  1918. mpfr_get_version (void)
  1919. {
  1920. - return "4.1.0-p9";
  1921. + return "4.1.0-p10";
  1922. }
  1923. diff -Naurd mpfr-4.1.0-a/tests/mpfr-test.h mpfr-4.1.0-b/tests/mpfr-test.h
  1924. --- mpfr-4.1.0-a/tests/mpfr-test.h 2021-02-17 17:25:46.424981219 +0000
  1925. +++ mpfr-4.1.0-b/tests/mpfr-test.h 2021-03-09 13:55:43.211158639 +0000
  1926. @@ -92,6 +92,32 @@
  1927. #define STRINGIZE(S) #S
  1928. #define MAKE_STR(S) STRINGIZE(S)
  1929. +/* In C (but not C++), mpfr_ptr and mpfr_srcptr arguments can be provided
  1930. + in a different pointer type, such as void *. For functions implemented
  1931. + as macros, the type conversion for the function parameters will not be
  1932. + done by the compiler, which means potential bugs in these implementations
  1933. + if we forget to take these unusual cases into account. So we need to test
  1934. + such arguments, in order to make sure that the arguments are converted to
  1935. + the expected type when needed.
  1936. +
  1937. + However, at least when the function is not implemented as a macro (which
  1938. + is the case when MPFR_USE_NO_MACRO is defined), such tests with void *
  1939. + arguments are not valid in C++; therefore, we will not do the cast to
  1940. + void * if the __cplusplus macro is defined. And with GCC compilers (and
  1941. + compatible), we will ignore the -Wc++-compat option around these tests.
  1942. +
  1943. + Note: in the future, inline functions could be used instead of macros,
  1944. + and such tests would become useless (except to detect compiler bugs).
  1945. +*/
  1946. +#if defined (__cplusplus)
  1947. +#define VOIDP_CAST(X) (X)
  1948. +#else
  1949. +#define VOIDP_CAST(X) ((void *) (X))
  1950. +#if defined (__GNUC__)
  1951. +#define IGNORE_CPP_COMPAT
  1952. +#endif
  1953. +#endif
  1954. +
  1955. #if defined (__cplusplus)
  1956. extern "C" {
  1957. #endif
  1958. diff -Naurd mpfr-4.1.0-a/tests/tcopysign.c mpfr-4.1.0-b/tests/tcopysign.c
  1959. --- mpfr-4.1.0-a/tests/tcopysign.c 2020-01-08 18:11:13.000000000 +0000
  1960. +++ mpfr-4.1.0-b/tests/tcopysign.c 2021-03-09 13:55:43.211158639 +0000
  1961. @@ -26,26 +26,72 @@
  1962. copysign_variant (mpfr_ptr z, mpfr_srcptr x, mpfr_srcptr y,
  1963. mpfr_rnd_t rnd_mode, int k)
  1964. {
  1965. + mpfr_srcptr p;
  1966. + int a = 0, b = 0, c = 0;
  1967. +
  1968. + /* invalid sign, to test that the sign is always correctly set */
  1969. + MPFR_SIGN (z) = 0;
  1970. +
  1971. + if (k >= 8)
  1972. + {
  1973. + MPFR_ASSERTN (MPFR_PREC (z) >= MPFR_PREC (x));
  1974. + mpfr_set (z, x, MPFR_RNDN);
  1975. + p = z;
  1976. + k -= 8;
  1977. + }
  1978. + else
  1979. + p = x;
  1980. +
  1981. mpfr_clear_flags ();
  1982. switch (k)
  1983. {
  1984. case 0:
  1985. - mpfr_copysign (z, x, y, MPFR_RNDN);
  1986. + mpfr_copysign (z, p, y, rnd_mode);
  1987. return;
  1988. case 1:
  1989. - (mpfr_copysign) (z, x, y, MPFR_RNDN);
  1990. + (mpfr_copysign) (z, p, y, rnd_mode);
  1991. return;
  1992. case 2:
  1993. - mpfr_setsign (z, x, mpfr_signbit (y), MPFR_RNDN);
  1994. +#ifdef IGNORE_CPP_COMPAT
  1995. +#pragma GCC diagnostic push
  1996. +#pragma GCC diagnostic ignored "-Wc++-compat"
  1997. +#endif
  1998. + mpfr_copysign ((a++, VOIDP_CAST(z)),
  1999. + (b++, VOIDP_CAST(p)),
  2000. + (c++, VOIDP_CAST(y)), rnd_mode);
  2001. +#ifdef IGNORE_CPP_COMPAT
  2002. +#pragma GCC diagnostic pop
  2003. +#endif
  2004. + MPFR_ASSERTN (a == 1);
  2005. + MPFR_ASSERTN (b == 1);
  2006. + MPFR_ASSERTN (c == 1);
  2007. return;
  2008. case 3:
  2009. - mpfr_setsign (z, x, (mpfr_signbit) (y), MPFR_RNDN);
  2010. + mpfr_setsign (z, p, mpfr_signbit (y), rnd_mode);
  2011. return;
  2012. case 4:
  2013. - (mpfr_setsign) (z, x, mpfr_signbit (y), MPFR_RNDN);
  2014. + mpfr_setsign (z, p, (mpfr_signbit) (y), rnd_mode);
  2015. return;
  2016. case 5:
  2017. - (mpfr_setsign) (z, x, (mpfr_signbit) (y), MPFR_RNDN);
  2018. + (mpfr_setsign) (z, p, mpfr_signbit (y), rnd_mode);
  2019. + return;
  2020. + case 6:
  2021. + (mpfr_setsign) (z, p, (mpfr_signbit) (y), rnd_mode);
  2022. + return;
  2023. + case 7:
  2024. +#ifdef IGNORE_CPP_COMPAT
  2025. +#pragma GCC diagnostic push
  2026. +#pragma GCC diagnostic ignored "-Wc++-compat"
  2027. +#endif
  2028. + mpfr_setsign ((a++, VOIDP_CAST(z)),
  2029. + (b++, VOIDP_CAST(p)),
  2030. + mpfr_signbit ((c++, VOIDP_CAST(y))), rnd_mode);
  2031. +#ifdef IGNORE_CPP_COMPAT
  2032. +#pragma GCC diagnostic pop
  2033. +#endif
  2034. + MPFR_ASSERTN (a == 1);
  2035. + MPFR_ASSERTN (b == 1);
  2036. + MPFR_ASSERTN (c == 1);
  2037. return;
  2038. }
  2039. }
  2040. @@ -64,7 +110,7 @@
  2041. for (i = 0; i <= 1; i++)
  2042. for (j = 0; j <= 1; j++)
  2043. - for (k = 0; k <= 5; k++)
  2044. + for (k = 0; k < 16; k++)
  2045. {
  2046. mpfr_set_nan (x);
  2047. i ? MPFR_SET_NEG (x) : MPFR_SET_POS (x);
  2048. diff -Naurd mpfr-4.1.0-a/tests/texceptions.c mpfr-4.1.0-b/tests/texceptions.c
  2049. --- mpfr-4.1.0-a/tests/texceptions.c 2020-01-08 18:11:13.000000000 +0000
  2050. +++ mpfr-4.1.0-b/tests/texceptions.c 2021-03-09 13:55:43.211158639 +0000
  2051. @@ -103,10 +103,26 @@
  2052. check_get_prec (void)
  2053. {
  2054. mpfr_t x;
  2055. + int i = 0;
  2056. mpfr_init2 (x, 17);
  2057. - if (mpfr_get_prec (x) != 17 || (mpfr_get_prec)(x) != 17)
  2058. +
  2059. + if (mpfr_get_prec (x) != 17 || (mpfr_get_prec) (x) != 17)
  2060. PRINT_ERROR ("mpfr_get_prec");
  2061. +
  2062. +#ifdef IGNORE_CPP_COMPAT
  2063. +#pragma GCC diagnostic push
  2064. +#pragma GCC diagnostic ignored "-Wc++-compat"
  2065. +#endif
  2066. +
  2067. + if (mpfr_get_prec ((i++, VOIDP_CAST(x))) != 17)
  2068. + PRINT_ERROR ("mpfr_get_prec (2)");
  2069. +
  2070. +#ifdef IGNORE_CPP_COMPAT
  2071. +#pragma GCC diagnostic pop
  2072. +#endif
  2073. +
  2074. + MPFR_ASSERTN (i == 1);
  2075. mpfr_clear (x);
  2076. }
  2077. diff -Naurd mpfr-4.1.0-a/tests/tisnan.c mpfr-4.1.0-b/tests/tisnan.c
  2078. --- mpfr-4.1.0-a/tests/tisnan.c 2020-01-08 18:11:13.000000000 +0000
  2079. +++ mpfr-4.1.0-b/tests/tisnan.c 2021-03-09 13:55:43.211158639 +0000
  2080. @@ -27,180 +27,235 @@
  2081. main (void)
  2082. {
  2083. mpfr_t x;
  2084. + int i = 0, j = 0;
  2085. +
  2086. + /* We need to check that when the function is implemented by a macro,
  2087. + it behaves correctly. */
  2088. +#define ARG (i++, VOIDP_CAST(x))
  2089. +#define CHECK MPFR_ASSERTN (i == ++j)
  2090. tests_start_mpfr ();
  2091. mpfr_init (x);
  2092. +#if 0
  2093. + /* The following should yield a compilation error when the functions
  2094. + are implemented as macros. Change 0 to 1 above in order to test. */
  2095. + (void) (mpfr_nan_p (1L));
  2096. + (void) (mpfr_inf_p (1L));
  2097. + (void) (mpfr_number_p (1L));
  2098. + (void) (mpfr_zero_p (1L));
  2099. + (void) (mpfr_regular_p (1L));
  2100. +#endif
  2101. +
  2102. +#ifdef IGNORE_CPP_COMPAT
  2103. +#pragma GCC diagnostic push
  2104. +#pragma GCC diagnostic ignored "-Wc++-compat"
  2105. +#endif
  2106. +
  2107. /* check +infinity gives non-zero for mpfr_inf_p only */
  2108. mpfr_set_ui (x, 1L, MPFR_RNDZ);
  2109. mpfr_div_ui (x, x, 0L, MPFR_RNDZ);
  2110. - if (mpfr_nan_p (x) || (mpfr_nan_p) (x) )
  2111. + if (mpfr_nan_p (x) || (mpfr_nan_p) (x) || mpfr_nan_p (ARG))
  2112. {
  2113. printf ("Error: mpfr_nan_p(+Inf) gives non-zero\n");
  2114. exit (1);
  2115. }
  2116. - if (mpfr_inf_p (x) == 0)
  2117. + CHECK;
  2118. + if (!mpfr_inf_p (x) || !(mpfr_inf_p) (x) || !mpfr_inf_p (ARG))
  2119. {
  2120. printf ("Error: mpfr_inf_p(+Inf) gives zero\n");
  2121. exit (1);
  2122. }
  2123. - if (mpfr_number_p (x) || (mpfr_number_p) (x) )
  2124. + CHECK;
  2125. + if (mpfr_number_p (x) || (mpfr_number_p) (x) || mpfr_number_p (ARG))
  2126. {
  2127. printf ("Error: mpfr_number_p(+Inf) gives non-zero\n");
  2128. exit (1);
  2129. }
  2130. - if (mpfr_zero_p (x) || (mpfr_zero_p) (x) )
  2131. + CHECK;
  2132. + if (mpfr_zero_p (x) || (mpfr_zero_p) (x) || mpfr_zero_p (ARG))
  2133. {
  2134. printf ("Error: mpfr_zero_p(+Inf) gives non-zero\n");
  2135. exit (1);
  2136. }
  2137. - if (mpfr_regular_p (x) || (mpfr_regular_p) (x) )
  2138. + CHECK;
  2139. + if (mpfr_regular_p (x) || (mpfr_regular_p) (x) || mpfr_regular_p (ARG))
  2140. {
  2141. printf ("Error: mpfr_regular_p(+Inf) gives non-zero\n");
  2142. exit (1);
  2143. }
  2144. + CHECK;
  2145. /* same for -Inf */
  2146. mpfr_neg (x, x, MPFR_RNDN);
  2147. - if (mpfr_nan_p (x) || (mpfr_nan_p(x)))
  2148. + if (mpfr_nan_p (x) || (mpfr_nan_p) (x) || mpfr_nan_p (ARG))
  2149. {
  2150. printf ("Error: mpfr_nan_p(-Inf) gives non-zero\n");
  2151. exit (1);
  2152. }
  2153. - if (mpfr_inf_p (x) == 0)
  2154. + CHECK;
  2155. + if (!mpfr_inf_p (x) || !(mpfr_inf_p) (x) || !mpfr_inf_p (ARG))
  2156. {
  2157. printf ("Error: mpfr_inf_p(-Inf) gives zero\n");
  2158. exit (1);
  2159. }
  2160. - if (mpfr_number_p (x) || (mpfr_number_p)(x) )
  2161. + CHECK;
  2162. + if (mpfr_number_p (x) || (mpfr_number_p) (x) || mpfr_number_p (ARG))
  2163. {
  2164. printf ("Error: mpfr_number_p(-Inf) gives non-zero\n");
  2165. exit (1);
  2166. }
  2167. - if (mpfr_zero_p (x) || (mpfr_zero_p)(x) )
  2168. + CHECK;
  2169. + if (mpfr_zero_p (x) || (mpfr_zero_p) (x) || mpfr_zero_p (ARG))
  2170. {
  2171. printf ("Error: mpfr_zero_p(-Inf) gives non-zero\n");
  2172. exit (1);
  2173. }
  2174. - if (mpfr_regular_p (x) || (mpfr_regular_p) (x) )
  2175. + CHECK;
  2176. + if (mpfr_regular_p (x) || (mpfr_regular_p) (x) || mpfr_regular_p (ARG))
  2177. {
  2178. printf ("Error: mpfr_regular_p(-Inf) gives non-zero\n");
  2179. exit (1);
  2180. }
  2181. + CHECK;
  2182. /* same for NaN */
  2183. mpfr_sub (x, x, x, MPFR_RNDN);
  2184. - if (mpfr_nan_p (x) == 0)
  2185. + if (!mpfr_nan_p (x) || !(mpfr_nan_p) (x) || !mpfr_nan_p (ARG))
  2186. {
  2187. printf ("Error: mpfr_nan_p(NaN) gives zero\n");
  2188. exit (1);
  2189. }
  2190. - if (mpfr_inf_p (x) || (mpfr_inf_p)(x) )
  2191. + CHECK;
  2192. + if (mpfr_inf_p (x) || (mpfr_inf_p) (x) || mpfr_inf_p (ARG))
  2193. {
  2194. printf ("Error: mpfr_inf_p(NaN) gives non-zero\n");
  2195. exit (1);
  2196. }
  2197. - if (mpfr_number_p (x) || (mpfr_number_p) (x) )
  2198. + CHECK;
  2199. + if (mpfr_number_p (x) || (mpfr_number_p) (x) || mpfr_number_p (ARG))
  2200. {
  2201. printf ("Error: mpfr_number_p(NaN) gives non-zero\n");
  2202. exit (1);
  2203. }
  2204. - if (mpfr_zero_p (x) || (mpfr_zero_p)(x) )
  2205. + CHECK;
  2206. + if (mpfr_zero_p (x) || (mpfr_zero_p) (x) || mpfr_zero_p (ARG))
  2207. {
  2208. printf ("Error: mpfr_number_p(NaN) gives non-zero\n");
  2209. exit (1);
  2210. }
  2211. - if (mpfr_regular_p (x) || (mpfr_regular_p) (x) )
  2212. + CHECK;
  2213. + if (mpfr_regular_p (x) || (mpfr_regular_p) (x) || mpfr_regular_p (ARG))
  2214. {
  2215. printf ("Error: mpfr_regular_p(NaN) gives non-zero\n");
  2216. exit (1);
  2217. }
  2218. + CHECK;
  2219. /* same for a regular number */
  2220. mpfr_set_ui (x, 1, MPFR_RNDN);
  2221. - if (mpfr_nan_p (x) || (mpfr_nan_p)(x))
  2222. + if (mpfr_nan_p (x) || (mpfr_nan_p) (x) || mpfr_nan_p (ARG))
  2223. {
  2224. printf ("Error: mpfr_nan_p(1) gives non-zero\n");
  2225. exit (1);
  2226. }
  2227. - if (mpfr_inf_p (x) || (mpfr_inf_p)(x) )
  2228. + CHECK;
  2229. + if (mpfr_inf_p (x) || (mpfr_inf_p) (x) || mpfr_inf_p (ARG))
  2230. {
  2231. printf ("Error: mpfr_inf_p(1) gives non-zero\n");
  2232. exit (1);
  2233. }
  2234. - if (mpfr_number_p (x) == 0)
  2235. + CHECK;
  2236. + if (!mpfr_number_p (x) || !(mpfr_number_p) (x) || !mpfr_number_p (ARG))
  2237. {
  2238. printf ("Error: mpfr_number_p(1) gives zero\n");
  2239. exit (1);
  2240. }
  2241. - if (mpfr_zero_p (x) || (mpfr_zero_p) (x) )
  2242. + CHECK;
  2243. + if (mpfr_zero_p (x) || (mpfr_zero_p) (x) || mpfr_zero_p (ARG))
  2244. {
  2245. printf ("Error: mpfr_zero_p(1) gives non-zero\n");
  2246. exit (1);
  2247. }
  2248. - if (mpfr_regular_p (x) == 0 || (mpfr_regular_p) (x) == 0)
  2249. + CHECK;
  2250. + if (!mpfr_regular_p (x) || !(mpfr_regular_p) (x) || !mpfr_regular_p (ARG))
  2251. {
  2252. printf ("Error: mpfr_regular_p(1) gives zero\n");
  2253. exit (1);
  2254. }
  2255. + CHECK;
  2256. /* Same for +0 */
  2257. mpfr_set_ui (x, 0, MPFR_RNDN);
  2258. - if (mpfr_nan_p (x) || (mpfr_nan_p)(x))
  2259. + if (mpfr_nan_p (x) || (mpfr_nan_p) (x) || mpfr_nan_p (ARG))
  2260. {
  2261. printf ("Error: mpfr_nan_p(+0) gives non-zero\n");
  2262. exit (1);
  2263. }
  2264. - if (mpfr_inf_p (x) || (mpfr_inf_p)(x) )
  2265. + CHECK;
  2266. + if (mpfr_inf_p (x) || (mpfr_inf_p) (x) || mpfr_inf_p (ARG))
  2267. {
  2268. printf ("Error: mpfr_inf_p(+0) gives non-zero\n");
  2269. exit (1);
  2270. }
  2271. - if (mpfr_number_p (x) == 0)
  2272. + CHECK;
  2273. + if (!mpfr_number_p (x) || !(mpfr_number_p) (x) || !mpfr_number_p (ARG))
  2274. {
  2275. printf ("Error: mpfr_number_p(+0) gives zero\n");
  2276. exit (1);
  2277. }
  2278. - if (mpfr_zero_p (x) == 0 )
  2279. + CHECK;
  2280. + if (!mpfr_zero_p (x) || !(mpfr_zero_p) (x) || !mpfr_zero_p (ARG))
  2281. {
  2282. printf ("Error: mpfr_zero_p(+0) gives zero\n");
  2283. exit (1);
  2284. }
  2285. - if (mpfr_regular_p (x) || (mpfr_regular_p) (x) )
  2286. + CHECK;
  2287. + if (mpfr_regular_p (x) || (mpfr_regular_p) (x) || mpfr_regular_p (ARG))
  2288. {
  2289. printf ("Error: mpfr_regular_p(+0) gives non-zero\n");
  2290. exit (1);
  2291. }
  2292. + CHECK;
  2293. /* Same for -0 */
  2294. mpfr_set_ui (x, 0, MPFR_RNDN);
  2295. mpfr_neg (x, x, MPFR_RNDN);
  2296. - if (mpfr_nan_p (x) || (mpfr_nan_p)(x))
  2297. + if (mpfr_nan_p (x) || (mpfr_nan_p) (x) || mpfr_nan_p (ARG))
  2298. {
  2299. printf ("Error: mpfr_nan_p(-0) gives non-zero\n");
  2300. exit (1);
  2301. }
  2302. - if (mpfr_inf_p (x) || (mpfr_inf_p)(x) )
  2303. + CHECK;
  2304. + if (mpfr_inf_p (x) || (mpfr_inf_p) (x) || mpfr_inf_p (ARG))
  2305. {
  2306. printf ("Error: mpfr_inf_p(-0) gives non-zero\n");
  2307. exit (1);
  2308. }
  2309. - if (mpfr_number_p (x) == 0)
  2310. + CHECK;
  2311. + if (!mpfr_number_p (x) || !(mpfr_number_p) (x) || !mpfr_number_p (ARG))
  2312. {
  2313. printf ("Error: mpfr_number_p(-0) gives zero\n");
  2314. exit (1);
  2315. }
  2316. - if (mpfr_zero_p (x) == 0 )
  2317. + CHECK;
  2318. + if (!mpfr_zero_p (x) || !(mpfr_zero_p) (x) || !mpfr_zero_p (ARG))
  2319. {
  2320. printf ("Error: mpfr_zero_p(-0) gives zero\n");
  2321. exit (1);
  2322. }
  2323. - if (mpfr_regular_p (x) || (mpfr_regular_p) (x) )
  2324. + CHECK;
  2325. + if (mpfr_regular_p (x) || (mpfr_regular_p) (x) || mpfr_regular_p (ARG))
  2326. {
  2327. printf ("Error: mpfr_regular_p(-0) gives non-zero\n");
  2328. exit (1);
  2329. }
  2330. + CHECK;
  2331. +
  2332. +#ifdef IGNORE_CPP_COMPAT
  2333. +#pragma GCC diagnostic pop
  2334. +#endif
  2335. mpfr_clear (x);
  2336. diff -Naurd mpfr-4.1.0-a/tests/tset.c mpfr-4.1.0-b/tests/tset.c
  2337. --- mpfr-4.1.0-a/tests/tset.c 2020-01-08 18:11:13.000000000 +0000
  2338. +++ mpfr-4.1.0-b/tests/tset.c 2021-03-09 13:55:43.207158683 +0000
  2339. @@ -207,7 +207,7 @@
  2340. static void
  2341. check_ternary_value (void)
  2342. {
  2343. - int p, q, rnd;
  2344. + int k, p, q, rnd;
  2345. int inexact, cmp;
  2346. mpfr_t x, y;
  2347. @@ -226,28 +226,45 @@
  2348. {
  2349. if (rnd == MPFR_RNDF) /* the test below makes no sense */
  2350. continue;
  2351. - inexact = mpfr_set (y, x, (mpfr_rnd_t) rnd);
  2352. - cmp = mpfr_cmp (y, x);
  2353. - if (((inexact == 0) && (cmp != 0)) ||
  2354. - ((inexact > 0) && (cmp <= 0)) ||
  2355. - ((inexact < 0) && (cmp >= 0)))
  2356. - {
  2357. - printf ("Wrong ternary value in mpfr_set for %s: expected"
  2358. - " %d, got %d\n",
  2359. - mpfr_print_rnd_mode ((mpfr_rnd_t) rnd), cmp,
  2360. - inexact);
  2361. - exit (1);
  2362. - }
  2363. - /* Test mpfr_set function too */
  2364. - inexact = (mpfr_set) (y, x, (mpfr_rnd_t) rnd);
  2365. - cmp = mpfr_cmp (y, x);
  2366. - if (((inexact == 0) && (cmp != 0)) ||
  2367. - ((inexact > 0) && (cmp <= 0)) ||
  2368. - ((inexact < 0) && (cmp >= 0)))
  2369. + for (k = 0; k < 3; k++)
  2370. {
  2371. - printf ("Wrong ternary value in mpfr_set(2): expected %d,"
  2372. - " got %d\n", cmp, inexact);
  2373. - exit (1);
  2374. + int a = 0, b = 0, c = 0;
  2375. +
  2376. + switch (k)
  2377. + {
  2378. + case 0:
  2379. + inexact = mpfr_set (y, x, (mpfr_rnd_t) rnd);
  2380. + break;
  2381. + case 1:
  2382. + inexact = (mpfr_set) (y, x, (mpfr_rnd_t) rnd);
  2383. + break;
  2384. + case 2:
  2385. +#ifdef IGNORE_CPP_COMPAT
  2386. +#pragma GCC diagnostic push
  2387. +#pragma GCC diagnostic ignored "-Wc++-compat"
  2388. +#endif
  2389. + inexact = mpfr_set ((a++, VOIDP_CAST(y)),
  2390. + (b++, VOIDP_CAST(x)),
  2391. + (c++, (mpfr_rnd_t) rnd));
  2392. +#ifdef IGNORE_CPP_COMPAT
  2393. +#pragma GCC diagnostic pop
  2394. +#endif
  2395. + MPFR_ASSERTN (a == 1);
  2396. + MPFR_ASSERTN (b == 1);
  2397. + MPFR_ASSERTN (c == 1);
  2398. + break;
  2399. + }
  2400. + cmp = mpfr_cmp (y, x);
  2401. + if (((inexact == 0) && (cmp != 0)) ||
  2402. + ((inexact > 0) && (cmp <= 0)) ||
  2403. + ((inexact < 0) && (cmp >= 0)))
  2404. + {
  2405. + printf ("Wrong ternary value in mpfr_set for %s (%d):"
  2406. + " expected %d, got %d\n",
  2407. + mpfr_print_rnd_mode ((mpfr_rnd_t) rnd),
  2408. + k, cmp, inexact);
  2409. + exit (1);
  2410. + }
  2411. }
  2412. }
  2413. }
  2414. diff -Naurd mpfr-4.1.0-a/tests/tset_exp.c mpfr-4.1.0-b/tests/tset_exp.c
  2415. --- mpfr-4.1.0-a/tests/tset_exp.c 2020-01-08 18:11:13.000000000 +0000
  2416. +++ mpfr-4.1.0-b/tests/tset_exp.c 2021-03-09 13:55:43.211158639 +0000
  2417. @@ -28,6 +28,7 @@
  2418. mpfr_t x;
  2419. int ret;
  2420. mpfr_exp_t emin, emax, e;
  2421. + int i = 0;
  2422. tests_start_mpfr ();
  2423. @@ -63,6 +64,17 @@
  2424. e = (mpfr_get_exp) (x);
  2425. MPFR_ASSERTN (e == emin);
  2426. +#ifdef IGNORE_CPP_COMPAT
  2427. +#pragma GCC diagnostic push
  2428. +#pragma GCC diagnostic ignored "-Wc++-compat"
  2429. +#endif
  2430. + e = mpfr_get_exp ((i++, VOIDP_CAST(x)));
  2431. +#ifdef IGNORE_CPP_COMPAT
  2432. +#pragma GCC diagnostic pop
  2433. +#endif
  2434. + MPFR_ASSERTN (e == emin);
  2435. + MPFR_ASSERTN (i == 1);
  2436. +
  2437. ret = mpfr_set_exp (x, -1);
  2438. MPFR_ASSERTN (ret == 0 && mpfr_cmp_ui_2exp (x, 1, -2) == 0);
  2439. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  2440. --- mpfr-4.1.0-a/PATCHES 2021-03-09 13:58:00.889650773 +0000
  2441. +++ mpfr-4.1.0-b/PATCHES 2021-03-09 13:58:00.937650249 +0000
  2442. @@ -0,0 +1 @@
  2443. +tset_sij
  2444. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  2445. --- mpfr-4.1.0-a/VERSION 2021-03-09 13:55:43.223158508 +0000
  2446. +++ mpfr-4.1.0-b/VERSION 2021-03-09 13:58:00.937650249 +0000
  2447. @@ -1 +1 @@
  2448. -4.1.0-p10
  2449. +4.1.0-p11
  2450. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  2451. --- mpfr-4.1.0-a/src/mpfr.h 2021-03-09 13:55:43.223158508 +0000
  2452. +++ mpfr-4.1.0-b/src/mpfr.h 2021-03-09 13:58:00.933650293 +0000
  2453. @@ -27,7 +27,7 @@
  2454. #define MPFR_VERSION_MAJOR 4
  2455. #define MPFR_VERSION_MINOR 1
  2456. #define MPFR_VERSION_PATCHLEVEL 0
  2457. -#define MPFR_VERSION_STRING "4.1.0-p10"
  2458. +#define MPFR_VERSION_STRING "4.1.0-p11"
  2459. /* User macros:
  2460. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  2461. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  2462. --- mpfr-4.1.0-a/src/version.c 2021-03-09 13:55:43.223158508 +0000
  2463. +++ mpfr-4.1.0-b/src/version.c 2021-03-09 13:58:00.933650293 +0000
  2464. @@ -25,5 +25,5 @@
  2465. const char *
  2466. mpfr_get_version (void)
  2467. {
  2468. - return "4.1.0-p10";
  2469. + return "4.1.0-p11";
  2470. }
  2471. diff -Naurd mpfr-4.1.0-a/tests/tset_si.c mpfr-4.1.0-b/tests/tset_si.c
  2472. --- mpfr-4.1.0-a/tests/tset_si.c 2020-03-26 11:51:33.000000000 +0000
  2473. +++ mpfr-4.1.0-b/tests/tset_si.c 2021-03-09 13:58:00.917650467 +0000
  2474. @@ -127,27 +127,29 @@
  2475. power of 2 is exact, unless underflow/overflow occurs.
  2476. The tests on the exponent below avoid integer overflows
  2477. (ep[i] may take extreme values). */
  2478. - e = mpfr_get_exp (x1);
  2479. mpfr_clear_flags ();
  2480. - if (j != 0 && ep[i] < __gmpfr_emin - e) /* underflow */
  2481. + if (j == 0)
  2482. + goto zero;
  2483. + e = MPFR_GET_EXP (x1);
  2484. + if (ep[i] < __gmpfr_emin - e) /* underflow */
  2485. {
  2486. mpfr_rnd_t r =
  2487. (rnd == MPFR_RNDN &&
  2488. - (ep[i] < __gmpfr_emin - mpfr_get_exp (y) - 1 ||
  2489. + (ep[i] < __gmpfr_emin - MPFR_GET_EXP (y) - 1 ||
  2490. IS_POW2 (sign * j))) ?
  2491. MPFR_RNDZ : (mpfr_rnd_t) rnd;
  2492. inex1 = mpfr_underflow (x1, r, sign);
  2493. flags1 = __gmpfr_flags;
  2494. }
  2495. - else if (j != 0 && ep[i] > __gmpfr_emax - e) /* overflow */
  2496. + else if (ep[i] > __gmpfr_emax - e) /* overflow */
  2497. {
  2498. inex1 = mpfr_overflow (x1, (mpfr_rnd_t) rnd, sign);
  2499. flags1 = __gmpfr_flags;
  2500. }
  2501. else
  2502. {
  2503. - if (j != 0)
  2504. - mpfr_set_exp (x1, ep[i] + e);
  2505. + mpfr_set_exp (x1, ep[i] + e);
  2506. + zero:
  2507. flags1 = inex1 != 0 ? MPFR_FLAGS_INEXACT : 0;
  2508. }
  2509. diff -Naurd mpfr-4.1.0-a/tests/tset_sj.c mpfr-4.1.0-b/tests/tset_sj.c
  2510. --- mpfr-4.1.0-a/tests/tset_sj.c 2020-06-01 10:39:52.000000000 +0000
  2511. +++ mpfr-4.1.0-b/tests/tset_sj.c 2021-03-09 13:58:00.917650467 +0000
  2512. @@ -225,27 +225,29 @@
  2513. power of 2 is exact, unless underflow/overflow occurs.
  2514. The tests on the exponent below avoid integer overflows
  2515. (ep[i] may take extreme values). */
  2516. - e = mpfr_get_exp (x1);
  2517. mpfr_clear_flags ();
  2518. - if (j != 0 && ep[i] < __gmpfr_emin - e) /* underflow */
  2519. + if (j == 0)
  2520. + goto zero;
  2521. + e = MPFR_GET_EXP (x1);
  2522. + if (ep[i] < __gmpfr_emin - e) /* underflow */
  2523. {
  2524. mpfr_rnd_t r =
  2525. (rnd == MPFR_RNDN &&
  2526. - (ep[i] < __gmpfr_emin - mpfr_get_exp (y) - 1 ||
  2527. + (ep[i] < __gmpfr_emin - MPFR_GET_EXP (y) - 1 ||
  2528. IS_POW2 (sign * j))) ?
  2529. MPFR_RNDZ : (mpfr_rnd_t) rnd;
  2530. inex1 = mpfr_underflow (x1, r, sign);
  2531. flags1 = __gmpfr_flags;
  2532. }
  2533. - else if (j != 0 && ep[i] > __gmpfr_emax - e) /* overflow */
  2534. + else if (ep[i] > __gmpfr_emax - e) /* overflow */
  2535. {
  2536. inex1 = mpfr_overflow (x1, (mpfr_rnd_t) rnd, sign);
  2537. flags1 = __gmpfr_flags;
  2538. }
  2539. else
  2540. {
  2541. - if (j != 0)
  2542. - mpfr_set_exp (x1, ep[i] + e);
  2543. + mpfr_set_exp (x1, ep[i] + e);
  2544. + zero:
  2545. flags1 = inex1 != 0 ? MPFR_FLAGS_INEXACT : 0;
  2546. }
  2547. }
  2548. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  2549. --- mpfr-4.1.0-a/PATCHES 2021-04-23 09:49:34.648281897 +0000
  2550. +++ mpfr-4.1.0-b/PATCHES 2021-04-23 09:49:34.696281616 +0000
  2551. @@ -0,0 +1 @@
  2552. +get_str_ndigits
  2553. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  2554. --- mpfr-4.1.0-a/VERSION 2021-03-09 13:58:00.937650249 +0000
  2555. +++ mpfr-4.1.0-b/VERSION 2021-04-23 09:49:34.696281616 +0000
  2556. @@ -1 +1 @@
  2557. -4.1.0-p11
  2558. +4.1.0-p12
  2559. diff -Naurd mpfr-4.1.0-a/src/get_str.c mpfr-4.1.0-b/src/get_str.c
  2560. --- mpfr-4.1.0-a/src/get_str.c 2020-06-18 17:17:18.000000000 +0000
  2561. +++ mpfr-4.1.0-b/src/get_str.c 2021-04-23 09:49:34.680281710 +0000
  2562. @@ -2484,6 +2484,8 @@
  2563. size_t
  2564. mpfr_get_str_ndigits (int b, mpfr_prec_t p)
  2565. {
  2566. + MPFR_SAVE_EXPO_DECL (expo);
  2567. +
  2568. MPFR_ASSERTN (2 <= b && b <= 62);
  2569. /* deal first with power of two bases, since even for those, mpfr_ceil_mul
  2570. @@ -2497,17 +2499,26 @@
  2571. return 1 + (p + k - 2) / k;
  2572. }
  2573. + MPFR_SAVE_EXPO_MARK (expo);
  2574. +
  2575. /* the value returned by mpfr_ceil_mul is guaranteed to be
  2576. 1 + ceil(p*log(2)/log(b)) for p < 186564318007 (it returns one more
  2577. for p=186564318007 and b=7 or 49) */
  2578. MPFR_STAT_STATIC_ASSERT (MPFR_PREC_BITS >= 64 || MPFR_PREC_BITS <= 32);
  2579. + if
  2580. #if MPFR_PREC_BITS >= 64
  2581. /* 64-bit numbers are supported by the C implementation, so that we can
  2582. use the large constant below. If MPFR_PREC_BITS <= 32, the condition
  2583. is always satisfied, so that we do not need any test. */
  2584. - if (MPFR_LIKELY (p < 186564318007))
  2585. + (MPFR_LIKELY (p < 186564318007))
  2586. +#else
  2587. + (1)
  2588. #endif
  2589. - return 1 + mpfr_ceil_mul (IS_POW2(b) ? p - 1 : p, b, 1);
  2590. + {
  2591. + size_t ret = 1 + mpfr_ceil_mul (IS_POW2(b) ? p - 1 : p, b, 1);
  2592. + MPFR_SAVE_EXPO_FREE (expo);
  2593. + return ret;
  2594. + }
  2595. /* Now p is large and b is not a power of two. The code below works for any
  2596. value of p and b, as long as b is not a power of two. Indeed, in such a
  2597. @@ -2541,6 +2552,8 @@
  2598. mpfr_clear (d);
  2599. mpfr_clear (u);
  2600. }
  2601. +
  2602. + MPFR_SAVE_EXPO_FREE (expo);
  2603. return 1 + ret;
  2604. }
  2605. }
  2606. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  2607. --- mpfr-4.1.0-a/src/mpfr.h 2021-03-09 13:58:00.933650293 +0000
  2608. +++ mpfr-4.1.0-b/src/mpfr.h 2021-04-23 09:49:34.692281639 +0000
  2609. @@ -27,7 +27,7 @@
  2610. #define MPFR_VERSION_MAJOR 4
  2611. #define MPFR_VERSION_MINOR 1
  2612. #define MPFR_VERSION_PATCHLEVEL 0
  2613. -#define MPFR_VERSION_STRING "4.1.0-p11"
  2614. +#define MPFR_VERSION_STRING "4.1.0-p12"
  2615. /* User macros:
  2616. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  2617. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  2618. --- mpfr-4.1.0-a/src/version.c 2021-03-09 13:58:00.933650293 +0000
  2619. +++ mpfr-4.1.0-b/src/version.c 2021-04-23 09:49:34.696281616 +0000
  2620. @@ -25,5 +25,5 @@
  2621. const char *
  2622. mpfr_get_version (void)
  2623. {
  2624. - return "4.1.0-p11";
  2625. + return "4.1.0-p12";
  2626. }
  2627. diff -Naurd mpfr-4.1.0-a/tests/tget_str.c mpfr-4.1.0-b/tests/tget_str.c
  2628. --- mpfr-4.1.0-a/tests/tget_str.c 2020-01-08 18:11:13.000000000 +0000
  2629. +++ mpfr-4.1.0-b/tests/tget_str.c 2021-04-23 09:49:34.680281710 +0000
  2630. @@ -1311,6 +1311,33 @@
  2631. mpfr_clear (x);
  2632. }
  2633. +static void
  2634. +test_ndigits_aux (int b, mpfr_prec_t p, size_t expected_m)
  2635. +{
  2636. + size_t m;
  2637. + mpfr_exp_t old_emin, old_emax, e[] = { MPFR_EMIN_MIN, 0, MPFR_EMAX_MAX };
  2638. + mpfr_flags_t flags;
  2639. + int i;
  2640. +
  2641. + old_emin = mpfr_get_emin ();
  2642. + old_emax = mpfr_get_emax ();
  2643. +
  2644. + i = randlimb () % (numberof (e) + 1);
  2645. + if (i < numberof (e))
  2646. + {
  2647. + set_emin (e[i]);
  2648. + set_emax (e[i]);
  2649. + }
  2650. +
  2651. + __gmpfr_flags = flags = randlimb () & MPFR_FLAGS_ALL;
  2652. + m = mpfr_get_str_ndigits (b, p);
  2653. + MPFR_ASSERTN (m == expected_m);
  2654. + MPFR_ASSERTN (__gmpfr_flags == flags);
  2655. +
  2656. + set_emin (old_emin);
  2657. + set_emax (old_emax);
  2658. +}
  2659. +
  2660. /* test of mpfr_get_str_ndigits */
  2661. static void
  2662. test_ndigits (void)
  2663. @@ -1319,61 +1346,61 @@
  2664. /* for b=2, we have 1 + ceil((p-1)*log(2)/log(b)) = p */
  2665. for (p = MPFR_PREC_MIN; p <= 1024; p++)
  2666. - MPFR_ASSERTN(mpfr_get_str_ndigits (2, p) == p);
  2667. + test_ndigits_aux (2, p, p);
  2668. /* for b=4, we have 1 + ceil((p-1)*log(2)/log(b)) = 1 + ceil((p-1)/2)
  2669. = 1 + floor(p/2) */
  2670. for (p = MPFR_PREC_MIN; p <= 1024; p++)
  2671. - MPFR_ASSERTN(mpfr_get_str_ndigits (4, p) == 1 + (p / 2));
  2672. + test_ndigits_aux (4, p, 1 + (p / 2));
  2673. /* for b=8, we have 1 + ceil((p-1)*log(2)/log(b)) = 1 + ceil((p-1)/3)
  2674. = 1 + floor((p+1)/3) */
  2675. for (p = MPFR_PREC_MIN; p <= 1024; p++)
  2676. - MPFR_ASSERTN(mpfr_get_str_ndigits (8, p) == 1 + ((p + 1) / 3));
  2677. + test_ndigits_aux (8, p, 1 + ((p + 1) / 3));
  2678. /* for b=16, we have 1 + ceil((p-1)*log(2)/log(b)) = 1 + ceil((p-1)/4)
  2679. = 1 + floor((p+2)/4) */
  2680. for (p = MPFR_PREC_MIN; p <= 1024; p++)
  2681. - MPFR_ASSERTN(mpfr_get_str_ndigits (16, p) == 1 + ((p + 2) / 4));
  2682. + test_ndigits_aux (16, p, 1 + ((p + 2) / 4));
  2683. /* for b=32, we have 1 + ceil((p-1)*log(2)/log(b)) = 1 + ceil((p-1)/5)
  2684. = 1 + floor((p+3)/5) */
  2685. for (p = MPFR_PREC_MIN; p <= 1024; p++)
  2686. - MPFR_ASSERTN(mpfr_get_str_ndigits (32, p) == 1 + ((p + 3) / 5));
  2687. + test_ndigits_aux (32, p, 1 + ((p + 3) / 5));
  2688. /* error < 1e-3 */
  2689. - MPFR_ASSERTN(mpfr_get_str_ndigits (57, 35) == 8);
  2690. + test_ndigits_aux (57, 35, 8);
  2691. /* error < 1e-4 */
  2692. - MPFR_ASSERTN(mpfr_get_str_ndigits (31, 649) == 133);
  2693. + test_ndigits_aux (31, 649, 133);
  2694. /* error < 1e-5 */
  2695. - MPFR_ASSERTN(mpfr_get_str_ndigits (43, 5041) == 931);
  2696. + test_ndigits_aux (43, 5041, 931);
  2697. /* error < 1e-6 */
  2698. - MPFR_ASSERTN(mpfr_get_str_ndigits (41, 17771) == 3319);
  2699. + test_ndigits_aux (41, 17771, 3319);
  2700. /* 20th convergent of log(2)/log(3) */
  2701. - MPFR_ASSERTN(mpfr_get_str_ndigits (3, 630138897) == 397573381);
  2702. + test_ndigits_aux (3, 630138897, 397573381);
  2703. #if MPFR_PREC_BITS >= 64
  2704. /* 21st convergent of log(2)/log(3) */
  2705. - MPFR_ASSERTN(mpfr_get_str_ndigits (3, 9809721694) == 6189245292);
  2706. + test_ndigits_aux (3, 9809721694, 6189245292);
  2707. /* 22nd convergent of log(2)/log(3) */
  2708. - MPFR_ASSERTN(mpfr_get_str_ndigits (3, 10439860591) == 6586818672);
  2709. + test_ndigits_aux (3, 10439860591, 6586818672);
  2710. /* 23rd convergent of log(2)/log(3) */
  2711. - MPFR_ASSERTN(mpfr_get_str_ndigits (3, 103768467013) == 65470613322);
  2712. + test_ndigits_aux (3, 103768467013, 65470613322);
  2713. /* 24th convergent of log(2)/log(3) */
  2714. - MPFR_ASSERTN(mpfr_get_str_ndigits (3, 217976794617) == 137528045314);
  2715. + test_ndigits_aux (3, 217976794617, 137528045314);
  2716. - MPFR_ASSERTN(mpfr_get_str_ndigits (3, 1193652440098) == 753110839882);
  2717. + test_ndigits_aux (3, 1193652440098, 753110839882);
  2718. - MPFR_ASSERTN(mpfr_get_str_ndigits (3, 683381996816440) == 431166034846569);
  2719. + test_ndigits_aux (3, 683381996816440, 431166034846569);
  2720. - MPFR_ASSERTN(mpfr_get_str_ndigits (7, 186564318007) == 66455550933);
  2721. + test_ndigits_aux (7, 186564318007, 66455550933);
  2722. #endif
  2723. }
  2724. diff -Naurd mpfr-4.1.0-a/PATCHES mpfr-4.1.0-b/PATCHES
  2725. --- mpfr-4.1.0-a/PATCHES 2021-05-17 16:09:00.574477185 +0000
  2726. +++ mpfr-4.1.0-b/PATCHES 2021-05-17 16:09:00.754476587 +0000
  2727. @@ -0,0 +1 @@
  2728. +vasprintf-prec-zero
  2729. diff -Naurd mpfr-4.1.0-a/VERSION mpfr-4.1.0-b/VERSION
  2730. --- mpfr-4.1.0-a/VERSION 2021-04-23 09:49:34.696281616 +0000
  2731. +++ mpfr-4.1.0-b/VERSION 2021-05-17 16:09:00.754476587 +0000
  2732. @@ -1 +1 @@
  2733. -4.1.0-p12
  2734. +4.1.0-p13
  2735. diff -Naurd mpfr-4.1.0-a/src/mpfr.h mpfr-4.1.0-b/src/mpfr.h
  2736. --- mpfr-4.1.0-a/src/mpfr.h 2021-04-23 09:49:34.692281639 +0000
  2737. +++ mpfr-4.1.0-b/src/mpfr.h 2021-05-17 16:09:00.754476587 +0000
  2738. @@ -27,7 +27,7 @@
  2739. #define MPFR_VERSION_MAJOR 4
  2740. #define MPFR_VERSION_MINOR 1
  2741. #define MPFR_VERSION_PATCHLEVEL 0
  2742. -#define MPFR_VERSION_STRING "4.1.0-p12"
  2743. +#define MPFR_VERSION_STRING "4.1.0-p13"
  2744. /* User macros:
  2745. MPFR_USE_FILE: Define it to make MPFR define functions dealing
  2746. diff -Naurd mpfr-4.1.0-a/src/vasprintf.c mpfr-4.1.0-b/src/vasprintf.c
  2747. --- mpfr-4.1.0-a/src/vasprintf.c 2021-02-11 12:48:27.354242922 +0000
  2748. +++ mpfr-4.1.0-b/src/vasprintf.c 2021-05-17 16:09:00.598477107 +0000
  2749. @@ -635,7 +635,13 @@
  2750. static int
  2751. buffer_cat (struct string_buffer *b, const char *s, size_t len)
  2752. {
  2753. - MPFR_ASSERTD (len > 0);
  2754. + /* If len == 0, which is possible when outputting an integer 0
  2755. + (either a native one or mpfr_prec_t) with precision field = 0,
  2756. + do nothing. This test is not necessary since the code below is
  2757. + valid for len == 0, but this is safer, just in case. */
  2758. + if (len == 0)
  2759. + return 0;
  2760. +
  2761. MPFR_ASSERTD (len <= strlen (s));
  2762. if (buffer_incr_len (b, len))
  2763. diff -Naurd mpfr-4.1.0-a/src/version.c mpfr-4.1.0-b/src/version.c
  2764. --- mpfr-4.1.0-a/src/version.c 2021-04-23 09:49:34.696281616 +0000
  2765. +++ mpfr-4.1.0-b/src/version.c 2021-05-17 16:09:00.754476587 +0000
  2766. @@ -25,5 +25,5 @@
  2767. const char *
  2768. mpfr_get_version (void)
  2769. {
  2770. - return "4.1.0-p12";
  2771. + return "4.1.0-p13";
  2772. }
  2773. diff -Naurd mpfr-4.1.0-a/tests/tsprintf.c mpfr-4.1.0-b/tests/tsprintf.c
  2774. --- mpfr-4.1.0-a/tests/tsprintf.c 2020-04-08 22:39:35.000000000 +0000
  2775. +++ mpfr-4.1.0-b/tests/tsprintf.c 2021-05-17 16:09:00.598477107 +0000
  2776. @@ -193,6 +193,10 @@
  2777. sprintf (buf, "%d", i);
  2778. check_vsprintf (buf, "%d", i);
  2779. + check_vsprintf ("0", "%d", 0);
  2780. + check_vsprintf ("", "%.d", 0);
  2781. + check_vsprintf ("", "%.0d", 0);
  2782. +
  2783. sprintf (buf, "%e", d);
  2784. check_vsprintf (buf, "%e", d);
  2785. @@ -227,9 +231,6 @@
  2786. mpfr_prec_t p = 128;
  2787. mpfr_t x, y, z;
  2788. - mpfr_init (z);
  2789. - mpfr_init2 (x, p);
  2790. -
  2791. /* specifier 'P' for precision */
  2792. check_vsprintf ("128", "%Pu", p);
  2793. check_vsprintf ("00128", "%.5Pu", p);
  2794. @@ -247,9 +248,19 @@
  2795. check_vsprintf ("0200:", "%0#+ -Po:", p);
  2796. check_vsprintf ("+0000128 :", "%0+ *.*Pd:", -9, 7, p);
  2797. check_vsprintf ("+12345 :", "%0+ -*.*Pd:", -9, -3, (mpfr_prec_t) 12345);
  2798. + check_vsprintf ("0", "%Pu", (mpfr_prec_t) 0);
  2799. /* Do not add a test like "%05.1Pd" as MS Windows is buggy: when
  2800. a precision is given, the '0' flag must be ignored. */
  2801. + /* specifier 'P' with precision field 0 */
  2802. + check_vsprintf ("128", "%.Pu", p);
  2803. + check_vsprintf ("128", "%.0Pd", p);
  2804. + /* check_vsprintf ("", "%.Pu", (mpfr_prec_t) 0); */
  2805. + check_vsprintf ("", "%.0Pd", (mpfr_prec_t) 0);
  2806. +
  2807. + mpfr_init (z);
  2808. + mpfr_init2 (x, 128);
  2809. +
  2810. /* special numbers */
  2811. mpfr_set_inf (x, 1);
  2812. check_sprintf (pinf_str, "%Re", x);