From 29a9043b36c9ca5a5d6f10fc183c7b7de0f979c7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 29 Dec 2020 18:50:56 +0100 Subject: bc,dc: make BC_LINE_LENGTH/DC_LINE_LENGTH more compatible with GNU function old new delta xc_vm_init 640 682 +42 Signed-off-by: Denys Vlasenko --- miscutils/bc.c | 38 +++++++++++++-------- testsuite/dc_add_results.txt | 36 ++++++++++---------- testsuite/dc_decimal_results.txt | 42 +++++++++++------------ testsuite/dc_divmod_results.txt | 8 ++--- testsuite/dc_multiply_results.txt | 4 +-- testsuite/dc_power_results.txt | 72 +++++++++++++++++++-------------------- testsuite/dc_subtract_results.txt | 14 ++++---- 7 files changed, 110 insertions(+), 104 deletions(-) diff --git a/miscutils/bc.c b/miscutils/bc.c index 59e18a8c1..6d54f968a 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c @@ -231,7 +231,7 @@ typedef struct BcNum { #define BC_NUM_MAX_IBASE 36 // larger value might speed up BIGNUM calculations a bit: #define BC_NUM_DEF_SIZE 16 -#define BC_NUM_PRINT_WIDTH 69 +#define BC_NUM_PRINT_WIDTH 70 #define BC_NUM_KARATSUBA_LEN 32 @@ -7372,11 +7372,29 @@ static unsigned xc_vm_envLen(const char *var) lenv = getenv(var); len = BC_NUM_PRINT_WIDTH; - if (!lenv) return len; + if (lenv) { + len = bb_strtou(lenv, NULL, 10); + if (len == 0 || len > INT_MAX) + len = INT_MAX; + if (errno) + len = BC_NUM_PRINT_WIDTH; + } - len = bb_strtou(lenv, NULL, 10) - 1; - if (errno || len < 2 || len >= INT_MAX) - len = BC_NUM_PRINT_WIDTH; + // dc (GNU bc 1.07.1) 1.4.1 seems to use width + // 1 char wider than bc from the same package. + // Both default width, and xC_LINE_LENGTH=N are wider: + // "DC_LINE_LENGTH=5 dc -e'123456 p'" prints: + // |1234\ | + // |56 | + // "echo '123456' | BC_LINE_LENGTH=5 bc" prints: + // |123\ | + // |456 | + // Do the same, but it might be a bug in GNU package + if (IS_BC) + len--; + + if (len < 2) + len = IS_BC ? BC_NUM_PRINT_WIDTH - 1 : BC_NUM_PRINT_WIDTH; return len; } @@ -7467,16 +7485,6 @@ int dc_main(int argc UNUSED_PARAM, char **argv) INIT_G(); - // TODO: dc (GNU bc 1.07.1) 1.4.1 seems to use width - // 1 char wider than bc from the same package. - // Both default width, and xC_LINE_LENGTH=N are wider: - // "DC_LINE_LENGTH=5 dc -e'123456 p'" prints: - // |1234\ | - // |56 | - // "echo '123456' | BC_LINE_LENGTH=5 bc" prints: - // |123\ | - // |456 | - // Do the same, or it's a bug? xc_vm_init("DC_LINE_LENGTH"); // Run -e'SCRIPT' and -fFILE in order of appearance, then handle FILEs diff --git a/testsuite/dc_add_results.txt b/testsuite/dc_add_results.txt index 542a62ea3..2d955935f 100644 --- a/testsuite/dc_add_results.txt +++ b/testsuite/dc_add_results.txt @@ -9,9 +9,9 @@ 1998 324869359109479 2378639108055453348401 -78562139406792834691802347619083467219846713490861872324967138636055\ -45508706362018540498696043776980521464405852627147161556994835657433\ -00967298 +785621394067928346918023476190834672198467134908618723249671386360554\ +550870636201854049869604377698052146440585262714716155699483565743300\ +967298 1.1 1.1 37842935130118.1187478621432354 @@ -20,21 +20,21 @@ -2 -19 -1287904651762470260258 -100000000000000000000000000000000000000000000000000000000000.0000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -000000000000000000000000000000000000000000000 -100000000000000000000000000000000000000000000000000000000000.0000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -000000000000000000000000000000000000000000000 -100000000000000000000000000000000000000000000000000000000000.0000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -000000000000000000000000000000000000000009999 -99999999999999999999999999999999999999999999999999999999999.99999999\ -99999999999999999999999999999999999999999999999999000000000000000000\ -00000000000000000000000000000000000000009999 -99999999999999999999999999999999999990000000000000000000000.00000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000009999 +100000000000000000000000000000000000000000000000000000000000.00000000\ +000000000000000000000000000000000000000000000000000000000000000000000\ +0000000000000000000000000000000000000000000 +100000000000000000000000000000000000000000000000000000000000.00000000\ +000000000000000000000000000000000000000000000000000000000000000000000\ +0000000000000000000000000000000000000000000 +100000000000000000000000000000000000000000000000000000000000.00000000\ +000000000000000000000000000000000000000000000000000000000000000000000\ +0000000000000000000000000000000000000009999 +99999999999999999999999999999999999999999999999999999999999.999999999\ +999999999999999999999999999999999999999999999999900000000000000000000\ +000000000000000000000000000000000000009999 +99999999999999999999999999999999999990000000000000000000000.000000000\ +000000000000000000000000000000000000000000000000000000000000000000000\ +000000000000000000000000000000000000009999 122761518 -14338.391079082 -2422295.6865057444 diff --git a/testsuite/dc_decimal_results.txt b/testsuite/dc_decimal_results.txt index 275d431c6..66bb91ac3 100644 --- a/testsuite/dc_decimal_results.txt +++ b/testsuite/dc_decimal_results.txt @@ -9,19 +9,17 @@ 123 7505 1023468723275435238491972521917846 -43434724324317058673920735170382703980273527090273892739207390379379\ -60379637893607893607893670530278200795207952702873892786172916728961\ -78390789360741897358785738607967926792673752073092537298378279365279\ -3 +434347243243170586739207351703827039802735270902738927392073903793796\ +037963789360789360789367053027820079520795270287389278617291672896178\ +3907893607418973587857386079679267926737520730925372983782793652793 -1 -203 -57 -18586 -31378682943772818461924738352952347258 --8239456287456735894950672387239865203756982376208346745096273452730\ -96287563846592384526349872634895763257893467523987578690283762897568\ -45907234875807107108781350187590812735901871502384171023987230138727\ -8 +-82394562874567358949506723872398652037569823762083467450962734527309\ +628756384659238452634987263489576325789346752398757869028376289756845\ +9072348758071071087813501875908127359018715023841710239872301387278 .123521346523546 .1245923756273856 -.1024678456387 @@ -31,21 +29,21 @@ 234237468293576.000000000000000000000000000000 23987623568943567.00000000000000000005677834650000000000000 23856934568940675.000000000000000435676782300000000000000456784 -77567648698496.00000000000000000058767475000000000045856380000000000\ -0000 -2348672354968723.237482354600000000000325698739450234689243562387000\ -0000034578 +77567648698496.000000000000000000587674750000000000458563800000000000\ +000 +2348672354968723.2374823546000000000003256987394502346892435623870000\ +000034578 -2354768.000000000000000000000000000000000000 -96739874567.000000000347683456 -3764568345.000000000004573845000000347683460 -356784356.934568495770004586495678300000000 -74325437345273852773827101738273127312738521733017537073520735207307\ -570358738257390761276072160719802671980267018728630178.7082681027680\ -52176021786784127612768127086782782176817317820783071097801773817867\ -8012767377058785378278207385237085237803278203782037237582795870 --7567527327852738512737285378527382578372836789657385273852729836783\ -72867327835672967385278372637862738627836279863782673862783670.71738\ -17836173871836718637861073861783678160376017836701860376017810773527\ -8372832783728367826738627836278378260736270367362073867097307925 -9812734012837410982345719208345712908357412903587192048571920458712.\ -23957182459817249058172945781 +743254373452738527738271017382731273127385217330175370735207352073075\ +70358738257390761276072160719802671980267018728630178.708268102768052\ +176021786784127612768127086782782176817317820783071097801773817867801\ +2767377058785378278207385237085237803278203782037237582795870 +-75675273278527385127372853785273825783728367896573852738527298367837\ +2867327835672967385278372637862738627836279863782673862783670.7173817\ +836173871836718637861073861783678160376017836701860376017810773527837\ +2832783728367826738627836278378260736270367362073867097307925 +9812734012837410982345719208345712908357412903587192048571920458712.2\ +3957182459817249058172945781 diff --git a/testsuite/dc_divmod_results.txt b/testsuite/dc_divmod_results.txt index c55e9303d..ee91ee88c 100644 --- a/testsuite/dc_divmod_results.txt +++ b/testsuite/dc_divmod_results.txt @@ -58,8 +58,8 @@ 100864416620775.31076855630746548983 -53336.193401942302558132911110799109649707477 .00000000052530099381 -.0000000000000000000000000000000000000000000000000000000000000001907\ -266929376630027064745963897 +.00000000000000000000000000000000000000000000000000000000000000019072\ +66929376630027064745963897 42612515855353136519261264261472677699404182.78776061098893912189 0 0 @@ -121,6 +121,6 @@ 100864416620775 -3878923750692883.7238596702834756902 0 -.0000000000000000000000000000000000000000000184866017689020776005643\ -3621086 +.00000000000000000000000000000000000000000001848660176890207760056433\ +621086 42612515855353136519261264261472677699404182 diff --git a/testsuite/dc_multiply_results.txt b/testsuite/dc_multiply_results.txt index 9666059a5..aaf3a20fc 100644 --- a/testsuite/dc_multiply_results.txt +++ b/testsuite/dc_multiply_results.txt @@ -15,8 +15,8 @@ 3543531533584430580556128344529291738 568600835566479683035874339053.4411638427543228060 7487566285885.8557453089005171423976251098 -373846412427291014394738378015501363938345620046.7869650248829232267\ -2297002026819 +373846412427291014394738378015501363938345620046.78696502488292322672\ +297002026819 -1 -2 -2751507058396910892 diff --git a/testsuite/dc_power_results.txt b/testsuite/dc_power_results.txt index 997f44f59..dc5d56766 100644 --- a/testsuite/dc_power_results.txt +++ b/testsuite/dc_power_results.txt @@ -10,15 +10,15 @@ 18927361346 .23523785962738592635777 328956734869213746.89782398457234 -16473742664221279051571200630760751138799221376964991600670000200609\ -08006052596520320731708604393844468006290371918262741885989163144389\ -39367835091560809036359941703341471396407660150658436796925310445979\ -21333166245765946557344383284626113908419359990042883048537750217279\ -17481980123593363177308481941550382845381799410533956718500484099889\ -610805653325917409549921909941664118421333562129 +164737426642212790515712006307607511387992213769649916006700002006090\ +800605259652032073170860439384446800629037191826274188598916314438939\ +367835091560809036359941703341471396407660150658436796925310445979213\ +331662457659465573443832846261139084193599900428830485377502172791748\ +198012359336317730848194155038284538179941053395671850048409988961080\ +5653325917409549921909941664118421333562129 0 -43287877285033571298394739716218787350087163435619825150259705419.98\ -016445740928054425 +43287877285033571298394739716218787350087163435619825150259705419.980\ +16445740928054425 1.00000000000000000000 .50000000000000000000 .10000000000000000000 @@ -31,27 +31,27 @@ 1 -2 4 -14997322375665265051328725757939209353051902095893907150382724666290\ -49749481660976421019742616298227588464420182758442163654172400528243\ -00885441207762486233574213374503090372518590691583139696652847404883\ -08573912261119588874308960204159666762789603037188471170006223907416\ -60492840269152716750700089148882139254399347568222390231015487895905\ -73727080561379177721440905866857248917982113340543176658480139248897\ -54802503253413282808814063861470711399810899724515727713334909764746\ -27910290211411231279325882505708287941671508154740003122373284699097\ -78346501539634198926772266511968381368929692275950529960923432771985\ -12597189390708050983487158873301681237787429436264801751664042999180\ -3448659818912436089 -11478830555358864333472551120140548480416206583184496764727387456058\ -792742209537931243951391229607936 +149973223756652650513287257579392093530519020958939071503827246662904\ +974948166097642101974261629822758846442018275844216365417240052824300\ +885441207762486233574213374503090372518590691583139696652847404883085\ +739122611195888743089602041596667627896030371884711700062239074166049\ +284026915271675070008914888213925439934756822239023101548789590573727\ +080561379177721440905866857248917982113340543176658480139248897548025\ +032534132828088140638614707113998108997245157277133349097647462791029\ +021141123127932588250570828794167150815474000312237328469909778346501\ +539634198926772266511968381368929692275950529960923432771985125971893\ +907080509834871588733016812377874294362648017516640429991803448659818\ +912436089 +114788305553588643334725511201405484804162065831844967647273874560587\ +92742209537931243951391229607936 -.00000000000000017759 --2067373624686414405470850679965010694114490999957199847684803894306\ -56243666149296582304582679590231948238805965642713928910384741502707\ -.23224479257866798694 -11606078892843496082360561256965139908586179418605021706789617179085\ -85768049299693425729565480314913006780973928345684673490252494674985\ -0186164225375953066263609289359900615361965737717208159874390.293769\ -70206344604971 +-20673736246864144054708506799650106941144909999571998476848038943065\ +6243666149296582304582679590231948238805965642713928910384741502707.2\ +3224479257866798694 +116060788928434960823605612569651399085861794186050217067896171790858\ +576804929969342572956548031491300678097392834568467349025249467498501\ +86164225375953066263609289359900615361965737717208159874390.293769702\ +06344604971 -1.00000000000000000000 1.00000000000000000000 -.50000000000000000000 @@ -59,14 +59,14 @@ 0 0 -.00000000000002874159 --1945134149489344891879057554905782841936258356736314337975569799825\ -94091939572752348215929683891336730843553721422164737465108229034947\ -87333189564755763444242676978610321731298729194092653999616928308494\ -26419468484566422775668903315088810746121307679948574976162519479931\ -18935243698160094347216562490000767121041786977792546155155934655909\ -14123833869470494708767968978717730012864171105540029928688274136791\ -98175053824022144065005509214813689232148489884560100200475909009813\ -340098100705258138.98542904577525702068 +-19451341494893448918790575549057828419362583567363143379755697998259\ +409193957275234821592968389133673084355372142216473746510822903494787\ +333189564755763444242676978610321731298729194092653999616928308494264\ +194684845664227756689033150888107461213076799485749761625194799311893\ +524369816009434721656249000076712104178697779254615515593465590914123\ +833869470494708767968978717730012864171105540029928688274136791981750\ +538240221440650055092148136892321484898845601002004759090098133400981\ +00705258138.98542904577525702068 0 0 0 diff --git a/testsuite/dc_subtract_results.txt b/testsuite/dc_subtract_results.txt index 9f7726254..0a9762381 100644 --- a/testsuite/dc_subtract_results.txt +++ b/testsuite/dc_subtract_results.txt @@ -8,15 +8,15 @@ 2874519803456326214611 9000000000000000000000000000000000000001 1 -9000000000000000000000000000000000000000.000000000000000000000000000\ -00000001 +9000000000000000000000000000000000000000.0000000000000000000000000000\ +0000001 .0000000000000000000000000000000001 -9999999999999999999999999999999999999999.999999999999999999999999999\ +9999999999999999999999999999999999999999.9999999999999999999999999999\ +9999999999999999999999999999999999999999999999999999999999 +10000000000000000000000000000000000000000.999999999999999999999999999\ 99999999999999999999999999999999999999999999999999999999999 -10000000000000000000000000000000000000000.99999999999999999999999999\ -999999999999999999999999999999999999999999999999999999999999 -10000000000000000000000000000000000000000.00000000009999999999999999\ -99999999999999999999999999999999999999999999999999 +10000000000000000000000000000000000000000.000000000099999999999999999\ +9999999999999999999999999999999999999999999999999 -8 -182934721309467230894628759280719690 1245723576605103923392087218483 -- cgit v1.2.3