aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/bc.c38
-rw-r--r--testsuite/dc_add_results.txt36
-rw-r--r--testsuite/dc_decimal_results.txt42
-rw-r--r--testsuite/dc_divmod_results.txt8
-rw-r--r--testsuite/dc_multiply_results.txt4
-rw-r--r--testsuite/dc_power_results.txt72
-rw-r--r--testsuite/dc_subtract_results.txt14
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 {
231#define BC_NUM_MAX_IBASE 36 231#define BC_NUM_MAX_IBASE 36
232// larger value might speed up BIGNUM calculations a bit: 232// larger value might speed up BIGNUM calculations a bit:
233#define BC_NUM_DEF_SIZE 16 233#define BC_NUM_DEF_SIZE 16
234#define BC_NUM_PRINT_WIDTH 69 234#define BC_NUM_PRINT_WIDTH 70
235 235
236#define BC_NUM_KARATSUBA_LEN 32 236#define BC_NUM_KARATSUBA_LEN 32
237 237
@@ -7372,11 +7372,29 @@ static unsigned xc_vm_envLen(const char *var)
7372 7372
7373 lenv = getenv(var); 7373 lenv = getenv(var);
7374 len = BC_NUM_PRINT_WIDTH; 7374 len = BC_NUM_PRINT_WIDTH;
7375 if (!lenv) return len; 7375 if (lenv) {
7376 len = bb_strtou(lenv, NULL, 10);
7377 if (len == 0 || len > INT_MAX)
7378 len = INT_MAX;
7379 if (errno)
7380 len = BC_NUM_PRINT_WIDTH;
7381 }
7376 7382
7377 len = bb_strtou(lenv, NULL, 10) - 1; 7383 // dc (GNU bc 1.07.1) 1.4.1 seems to use width
7378 if (errno || len < 2 || len >= INT_MAX) 7384 // 1 char wider than bc from the same package.
7379 len = BC_NUM_PRINT_WIDTH; 7385 // Both default width, and xC_LINE_LENGTH=N are wider:
7386 // "DC_LINE_LENGTH=5 dc -e'123456 p'" prints:
7387 // |1234\ |
7388 // |56 |
7389 // "echo '123456' | BC_LINE_LENGTH=5 bc" prints:
7390 // |123\ |
7391 // |456 |
7392 // Do the same, but it might be a bug in GNU package
7393 if (IS_BC)
7394 len--;
7395
7396 if (len < 2)
7397 len = IS_BC ? BC_NUM_PRINT_WIDTH - 1 : BC_NUM_PRINT_WIDTH;
7380 7398
7381 return len; 7399 return len;
7382} 7400}
@@ -7467,16 +7485,6 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
7467 7485
7468 INIT_G(); 7486 INIT_G();
7469 7487
7470 // TODO: dc (GNU bc 1.07.1) 1.4.1 seems to use width
7471 // 1 char wider than bc from the same package.
7472 // Both default width, and xC_LINE_LENGTH=N are wider:
7473 // "DC_LINE_LENGTH=5 dc -e'123456 p'" prints:
7474 // |1234\ |
7475 // |56 |
7476 // "echo '123456' | BC_LINE_LENGTH=5 bc" prints:
7477 // |123\ |
7478 // |456 |
7479 // Do the same, or it's a bug?
7480 xc_vm_init("DC_LINE_LENGTH"); 7488 xc_vm_init("DC_LINE_LENGTH");
7481 7489
7482 // Run -e'SCRIPT' and -fFILE in order of appearance, then handle FILEs 7490 // 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 @@
91998 91998
10324869359109479 10324869359109479
112378639108055453348401 112378639108055453348401
1278562139406792834691802347619083467219846713490861872324967138636055\ 12785621394067928346918023476190834672198467134908618723249671386360554\
1345508706362018540498696043776980521464405852627147161556994835657433\ 13550870636201854049869604377698052146440585262714716155699483565743300\
1400967298 14967298
151.1 151.1
161.1 161.1
1737842935130118.1187478621432354 1737842935130118.1187478621432354
@@ -20,21 +20,21 @@
20-2 20-2
21-19 21-19
22-1287904651762470260258 22-1287904651762470260258
23100000000000000000000000000000000000000000000000000000000000.0000000\ 23100000000000000000000000000000000000000000000000000000000000.00000000\
2400000000000000000000000000000000000000000000000000000000000000000000\ 24000000000000000000000000000000000000000000000000000000000000000000000\
25000000000000000000000000000000000000000000000 250000000000000000000000000000000000000000000
26100000000000000000000000000000000000000000000000000000000000.0000000\ 26100000000000000000000000000000000000000000000000000000000000.00000000\
2700000000000000000000000000000000000000000000000000000000000000000000\ 27000000000000000000000000000000000000000000000000000000000000000000000\
28000000000000000000000000000000000000000000000 280000000000000000000000000000000000000000000
29100000000000000000000000000000000000000000000000000000000000.0000000\ 29100000000000000000000000000000000000000000000000000000000000.00000000\
3000000000000000000000000000000000000000000000000000000000000000000000\ 30000000000000000000000000000000000000000000000000000000000000000000000\
31000000000000000000000000000000000000000009999 310000000000000000000000000000000000000009999
3299999999999999999999999999999999999999999999999999999999999.99999999\ 3299999999999999999999999999999999999999999999999999999999999.999999999\
3399999999999999999999999999999999999999999999999999000000000000000000\ 33999999999999999999999999999999999999999999999999900000000000000000000\
3400000000000000000000000000000000000000009999 34000000000000000000000000000000000000009999
3599999999999999999999999999999999999990000000000000000000000.00000000\ 3599999999999999999999999999999999999990000000000000000000000.000000000\
3600000000000000000000000000000000000000000000000000000000000000000000\ 36000000000000000000000000000000000000000000000000000000000000000000000\
3700000000000000000000000000000000000000009999 37000000000000000000000000000000000000009999
38122761518 38122761518
39-14338.391079082 39-14338.391079082
40-2422295.6865057444 40-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 @@
9123 9123
107505 107505
111023468723275435238491972521917846 111023468723275435238491972521917846
1243434724324317058673920735170382703980273527090273892739207390379379\ 12434347243243170586739207351703827039802735270902738927392073903793796\
1360379637893607893607893670530278200795207952702873892786172916728961\ 13037963789360789360789367053027820079520795270287389278617291672896178\
1478390789360741897358785738607967926792673752073092537298378279365279\ 143907893607418973587857386079679267926737520730925372983782793652793
153
16-1 15-1
17-203 16-203
18-57 17-57
19-18586 18-18586
20-31378682943772818461924738352952347258 19-31378682943772818461924738352952347258
21-8239456287456735894950672387239865203756982376208346745096273452730\ 20-82394562874567358949506723872398652037569823762083467450962734527309\
2296287563846592384526349872634895763257893467523987578690283762897568\ 21628756384659238452634987263489576325789346752398757869028376289756845\
2345907234875807107108781350187590812735901871502384171023987230138727\ 229072348758071071087813501875908127359018715023841710239872301387278
248
25.123521346523546 23.123521346523546
26.1245923756273856 24.1245923756273856
27-.1024678456387 25-.1024678456387
@@ -31,21 +29,21 @@
31234237468293576.000000000000000000000000000000 29234237468293576.000000000000000000000000000000
3223987623568943567.00000000000000000005677834650000000000000 3023987623568943567.00000000000000000005677834650000000000000
3323856934568940675.000000000000000435676782300000000000000456784 3123856934568940675.000000000000000435676782300000000000000456784
3477567648698496.00000000000000000058767475000000000045856380000000000\ 3277567648698496.000000000000000000587674750000000000458563800000000000\
350000 33000
362348672354968723.237482354600000000000325698739450234689243562387000\ 342348672354968723.2374823546000000000003256987394502346892435623870000\
370000034578 35000034578
38-2354768.000000000000000000000000000000000000 36-2354768.000000000000000000000000000000000000
39-96739874567.000000000347683456 37-96739874567.000000000347683456
40-3764568345.000000000004573845000000347683460 38-3764568345.000000000004573845000000347683460
41-356784356.934568495770004586495678300000000 39-356784356.934568495770004586495678300000000
4274325437345273852773827101738273127312738521733017537073520735207307\ 40743254373452738527738271017382731273127385217330175370735207352073075\
43570358738257390761276072160719802671980267018728630178.7082681027680\ 4170358738257390761276072160719802671980267018728630178.708268102768052\
4452176021786784127612768127086782782176817317820783071097801773817867\ 42176021786784127612768127086782782176817317820783071097801773817867801\
458012767377058785378278207385237085237803278203782037237582795870 432767377058785378278207385237085237803278203782037237582795870
46-7567527327852738512737285378527382578372836789657385273852729836783\ 44-75675273278527385127372853785273825783728367896573852738527298367837\
4772867327835672967385278372637862738627836279863782673862783670.71738\ 452867327835672967385278372637862738627836279863782673862783670.7173817\
4817836173871836718637861073861783678160376017836701860376017810773527\ 46836173871836718637861073861783678160376017836701860376017810773527837\
498372832783728367826738627836278378260736270367362073867097307925 472832783728367826738627836278378260736270367362073867097307925
509812734012837410982345719208345712908357412903587192048571920458712.\ 489812734012837410982345719208345712908357412903587192048571920458712.2\
5123957182459817249058172945781 493957182459817249058172945781
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 @@
58100864416620775.31076855630746548983 58100864416620775.31076855630746548983
59-53336.193401942302558132911110799109649707477 59-53336.193401942302558132911110799109649707477
60.00000000052530099381 60.00000000052530099381
61.0000000000000000000000000000000000000000000000000000000000000001907\ 61.00000000000000000000000000000000000000000000000000000000000000019072\
62266929376630027064745963897 6266929376630027064745963897
6342612515855353136519261264261472677699404182.78776061098893912189 6342612515855353136519261264261472677699404182.78776061098893912189
640 640
650 650
@@ -121,6 +121,6 @@
121100864416620775 121100864416620775
122-3878923750692883.7238596702834756902 122-3878923750692883.7238596702834756902
1230 1230
124.0000000000000000000000000000000000000000000184866017689020776005643\ 124.00000000000000000000000000000000000000000001848660176890207760056433\
1253621086 125621086
12642612515855353136519261264261472677699404182 12642612515855353136519261264261472677699404182
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 @@
153543531533584430580556128344529291738 153543531533584430580556128344529291738
16568600835566479683035874339053.4411638427543228060 16568600835566479683035874339053.4411638427543228060
177487566285885.8557453089005171423976251098 177487566285885.8557453089005171423976251098
18373846412427291014394738378015501363938345620046.7869650248829232267\ 18373846412427291014394738378015501363938345620046.78696502488292322672\
192297002026819 19297002026819
20-1 20-1
21-2 21-2
22-2751507058396910892 22-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 @@
1018927361346 1018927361346
11.23523785962738592635777 11.23523785962738592635777
12328956734869213746.89782398457234 12328956734869213746.89782398457234
1316473742664221279051571200630760751138799221376964991600670000200609\ 13164737426642212790515712006307607511387992213769649916006700002006090\
1408006052596520320731708604393844468006290371918262741885989163144389\ 14800605259652032073170860439384446800629037191826274188598916314438939\
1539367835091560809036359941703341471396407660150658436796925310445979\ 15367835091560809036359941703341471396407660150658436796925310445979213\
1621333166245765946557344383284626113908419359990042883048537750217279\ 16331662457659465573443832846261139084193599900428830485377502172791748\
1717481980123593363177308481941550382845381799410533956718500484099889\ 17198012359336317730848194155038284538179941053395671850048409988961080\
18610805653325917409549921909941664118421333562129 185653325917409549921909941664118421333562129
190 190
2043287877285033571298394739716218787350087163435619825150259705419.98\ 2043287877285033571298394739716218787350087163435619825150259705419.980\
21016445740928054425 2116445740928054425
221.00000000000000000000 221.00000000000000000000
23.50000000000000000000 23.50000000000000000000
24.10000000000000000000 24.10000000000000000000
@@ -31,27 +31,27 @@
311 311
32-2 32-2
334 334
3414997322375665265051328725757939209353051902095893907150382724666290\ 34149973223756652650513287257579392093530519020958939071503827246662904\
3549749481660976421019742616298227588464420182758442163654172400528243\ 35974948166097642101974261629822758846442018275844216365417240052824300\
3600885441207762486233574213374503090372518590691583139696652847404883\ 36885441207762486233574213374503090372518590691583139696652847404883085\
3708573912261119588874308960204159666762789603037188471170006223907416\ 37739122611195888743089602041596667627896030371884711700062239074166049\
3860492840269152716750700089148882139254399347568222390231015487895905\ 38284026915271675070008914888213925439934756822239023101548789590573727\
3973727080561379177721440905866857248917982113340543176658480139248897\ 39080561379177721440905866857248917982113340543176658480139248897548025\
4054802503253413282808814063861470711399810899724515727713334909764746\ 40032534132828088140638614707113998108997245157277133349097647462791029\
4127910290211411231279325882505708287941671508154740003122373284699097\ 41021141123127932588250570828794167150815474000312237328469909778346501\
4278346501539634198926772266511968381368929692275950529960923432771985\ 42539634198926772266511968381368929692275950529960923432771985125971893\
4312597189390708050983487158873301681237787429436264801751664042999180\ 43907080509834871588733016812377874294362648017516640429991803448659818\
443448659818912436089 44912436089
4511478830555358864333472551120140548480416206583184496764727387456058\ 45114788305553588643334725511201405484804162065831844967647273874560587\
46792742209537931243951391229607936 4692742209537931243951391229607936
47-.00000000000000017759 47-.00000000000000017759
48-2067373624686414405470850679965010694114490999957199847684803894306\ 48-20673736246864144054708506799650106941144909999571998476848038943065\
4956243666149296582304582679590231948238805965642713928910384741502707\ 496243666149296582304582679590231948238805965642713928910384741502707.2\
50.23224479257866798694 503224479257866798694
5111606078892843496082360561256965139908586179418605021706789617179085\ 51116060788928434960823605612569651399085861794186050217067896171790858\
5285768049299693425729565480314913006780973928345684673490252494674985\ 52576804929969342572956548031491300678097392834568467349025249467498501\
530186164225375953066263609289359900615361965737717208159874390.293769\ 5386164225375953066263609289359900615361965737717208159874390.293769702\
5470206344604971 5406344604971
55-1.00000000000000000000 55-1.00000000000000000000
561.00000000000000000000 561.00000000000000000000
57-.50000000000000000000 57-.50000000000000000000
@@ -59,14 +59,14 @@
590 590
600 600
61-.00000000000002874159 61-.00000000000002874159
62-1945134149489344891879057554905782841936258356736314337975569799825\ 62-19451341494893448918790575549057828419362583567363143379755697998259\
6394091939572752348215929683891336730843553721422164737465108229034947\ 63409193957275234821592968389133673084355372142216473746510822903494787\
6487333189564755763444242676978610321731298729194092653999616928308494\ 64333189564755763444242676978610321731298729194092653999616928308494264\
6526419468484566422775668903315088810746121307679948574976162519479931\ 65194684845664227756689033150888107461213076799485749761625194799311893\
6618935243698160094347216562490000767121041786977792546155155934655909\ 66524369816009434721656249000076712104178697779254615515593465590914123\
6714123833869470494708767968978717730012864171105540029928688274136791\ 67833869470494708767968978717730012864171105540029928688274136791981750\
6898175053824022144065005509214813689232148489884560100200475909009813\ 68538240221440650055092148136892321484898845601002004759090098133400981\
69340098100705258138.98542904577525702068 6900705258138.98542904577525702068
700 700
710 710
720 720
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 @@
82874519803456326214611 82874519803456326214611
99000000000000000000000000000000000000001 99000000000000000000000000000000000000001
101 101
119000000000000000000000000000000000000000.000000000000000000000000000\ 119000000000000000000000000000000000000000.0000000000000000000000000000\
1200000001 120000001
13.0000000000000000000000000000000001 13.0000000000000000000000000000000001
149999999999999999999999999999999999999999.999999999999999999999999999\ 149999999999999999999999999999999999999999.9999999999999999999999999999\
159999999999999999999999999999999999999999999999999999999999
1610000000000000000000000000000000000000000.999999999999999999999999999\
1599999999999999999999999999999999999999999999999999999999999 1799999999999999999999999999999999999999999999999999999999999
1610000000000000000000000000000000000000000.99999999999999999999999999\ 1810000000000000000000000000000000000000000.000000000099999999999999999\
17999999999999999999999999999999999999999999999999999999999999 199999999999999999999999999999999999999999999999999
1810000000000000000000000000000000000000000.00000000009999999999999999\
1999999999999999999999999999999999999999999999999999
20-8 20-8
21-182934721309467230894628759280719690 21-182934721309467230894628759280719690
221245723576605103923392087218483 221245723576605103923392087218483