diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-29 18:50:56 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-29 18:52:19 +0100 |
commit | 29a9043b36c9ca5a5d6f10fc183c7b7de0f979c7 (patch) | |
tree | 6a77b0d0c204d1180bdd92087911cfe5ef1b59f0 | |
parent | cba45d9b6586ff57c021911885930e6a415aa2c4 (diff) | |
download | busybox-w32-29a9043b36c9ca5a5d6f10fc183c7b7de0f979c7.tar.gz busybox-w32-29a9043b36c9ca5a5d6f10fc183c7b7de0f979c7.tar.bz2 busybox-w32-29a9043b36c9ca5a5d6f10fc183c7b7de0f979c7.zip |
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 <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 38 | ||||
-rw-r--r-- | testsuite/dc_add_results.txt | 36 | ||||
-rw-r--r-- | testsuite/dc_decimal_results.txt | 42 | ||||
-rw-r--r-- | testsuite/dc_divmod_results.txt | 8 | ||||
-rw-r--r-- | testsuite/dc_multiply_results.txt | 4 | ||||
-rw-r--r-- | testsuite/dc_power_results.txt | 72 | ||||
-rw-r--r-- | 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 { | |||
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 @@ | |||
9 | 1998 | 9 | 1998 |
10 | 324869359109479 | 10 | 324869359109479 |
11 | 2378639108055453348401 | 11 | 2378639108055453348401 |
12 | 78562139406792834691802347619083467219846713490861872324967138636055\ | 12 | 785621394067928346918023476190834672198467134908618723249671386360554\ |
13 | 45508706362018540498696043776980521464405852627147161556994835657433\ | 13 | 550870636201854049869604377698052146440585262714716155699483565743300\ |
14 | 00967298 | 14 | 967298 |
15 | 1.1 | 15 | 1.1 |
16 | 1.1 | 16 | 1.1 |
17 | 37842935130118.1187478621432354 | 17 | 37842935130118.1187478621432354 |
@@ -20,21 +20,21 @@ | |||
20 | -2 | 20 | -2 |
21 | -19 | 21 | -19 |
22 | -1287904651762470260258 | 22 | -1287904651762470260258 |
23 | 100000000000000000000000000000000000000000000000000000000000.0000000\ | 23 | 100000000000000000000000000000000000000000000000000000000000.00000000\ |
24 | 00000000000000000000000000000000000000000000000000000000000000000000\ | 24 | 000000000000000000000000000000000000000000000000000000000000000000000\ |
25 | 000000000000000000000000000000000000000000000 | 25 | 0000000000000000000000000000000000000000000 |
26 | 100000000000000000000000000000000000000000000000000000000000.0000000\ | 26 | 100000000000000000000000000000000000000000000000000000000000.00000000\ |
27 | 00000000000000000000000000000000000000000000000000000000000000000000\ | 27 | 000000000000000000000000000000000000000000000000000000000000000000000\ |
28 | 000000000000000000000000000000000000000000000 | 28 | 0000000000000000000000000000000000000000000 |
29 | 100000000000000000000000000000000000000000000000000000000000.0000000\ | 29 | 100000000000000000000000000000000000000000000000000000000000.00000000\ |
30 | 00000000000000000000000000000000000000000000000000000000000000000000\ | 30 | 000000000000000000000000000000000000000000000000000000000000000000000\ |
31 | 000000000000000000000000000000000000000009999 | 31 | 0000000000000000000000000000000000000009999 |
32 | 99999999999999999999999999999999999999999999999999999999999.99999999\ | 32 | 99999999999999999999999999999999999999999999999999999999999.999999999\ |
33 | 99999999999999999999999999999999999999999999999999000000000000000000\ | 33 | 999999999999999999999999999999999999999999999999900000000000000000000\ |
34 | 00000000000000000000000000000000000000009999 | 34 | 000000000000000000000000000000000000009999 |
35 | 99999999999999999999999999999999999990000000000000000000000.00000000\ | 35 | 99999999999999999999999999999999999990000000000000000000000.000000000\ |
36 | 00000000000000000000000000000000000000000000000000000000000000000000\ | 36 | 000000000000000000000000000000000000000000000000000000000000000000000\ |
37 | 00000000000000000000000000000000000000009999 | 37 | 000000000000000000000000000000000000009999 |
38 | 122761518 | 38 | 122761518 |
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 @@ | |||
9 | 123 | 9 | 123 |
10 | 7505 | 10 | 7505 |
11 | 1023468723275435238491972521917846 | 11 | 1023468723275435238491972521917846 |
12 | 43434724324317058673920735170382703980273527090273892739207390379379\ | 12 | 434347243243170586739207351703827039802735270902738927392073903793796\ |
13 | 60379637893607893607893670530278200795207952702873892786172916728961\ | 13 | 037963789360789360789367053027820079520795270287389278617291672896178\ |
14 | 78390789360741897358785738607967926792673752073092537298378279365279\ | 14 | 3907893607418973587857386079679267926737520730925372983782793652793 |
15 | 3 | ||
16 | -1 | 15 | -1 |
17 | -203 | 16 | -203 |
18 | -57 | 17 | -57 |
19 | -18586 | 18 | -18586 |
20 | -31378682943772818461924738352952347258 | 19 | -31378682943772818461924738352952347258 |
21 | -8239456287456735894950672387239865203756982376208346745096273452730\ | 20 | -82394562874567358949506723872398652037569823762083467450962734527309\ |
22 | 96287563846592384526349872634895763257893467523987578690283762897568\ | 21 | 628756384659238452634987263489576325789346752398757869028376289756845\ |
23 | 45907234875807107108781350187590812735901871502384171023987230138727\ | 22 | 9072348758071071087813501875908127359018715023841710239872301387278 |
24 | 8 | ||
25 | .123521346523546 | 23 | .123521346523546 |
26 | .1245923756273856 | 24 | .1245923756273856 |
27 | -.1024678456387 | 25 | -.1024678456387 |
@@ -31,21 +29,21 @@ | |||
31 | 234237468293576.000000000000000000000000000000 | 29 | 234237468293576.000000000000000000000000000000 |
32 | 23987623568943567.00000000000000000005677834650000000000000 | 30 | 23987623568943567.00000000000000000005677834650000000000000 |
33 | 23856934568940675.000000000000000435676782300000000000000456784 | 31 | 23856934568940675.000000000000000435676782300000000000000456784 |
34 | 77567648698496.00000000000000000058767475000000000045856380000000000\ | 32 | 77567648698496.000000000000000000587674750000000000458563800000000000\ |
35 | 0000 | 33 | 000 |
36 | 2348672354968723.237482354600000000000325698739450234689243562387000\ | 34 | 2348672354968723.2374823546000000000003256987394502346892435623870000\ |
37 | 0000034578 | 35 | 000034578 |
38 | -2354768.000000000000000000000000000000000000 | 36 | -2354768.000000000000000000000000000000000000 |
39 | -96739874567.000000000347683456 | 37 | -96739874567.000000000347683456 |
40 | -3764568345.000000000004573845000000347683460 | 38 | -3764568345.000000000004573845000000347683460 |
41 | -356784356.934568495770004586495678300000000 | 39 | -356784356.934568495770004586495678300000000 |
42 | 74325437345273852773827101738273127312738521733017537073520735207307\ | 40 | 743254373452738527738271017382731273127385217330175370735207352073075\ |
43 | 570358738257390761276072160719802671980267018728630178.7082681027680\ | 41 | 70358738257390761276072160719802671980267018728630178.708268102768052\ |
44 | 52176021786784127612768127086782782176817317820783071097801773817867\ | 42 | 176021786784127612768127086782782176817317820783071097801773817867801\ |
45 | 8012767377058785378278207385237085237803278203782037237582795870 | 43 | 2767377058785378278207385237085237803278203782037237582795870 |
46 | -7567527327852738512737285378527382578372836789657385273852729836783\ | 44 | -75675273278527385127372853785273825783728367896573852738527298367837\ |
47 | 72867327835672967385278372637862738627836279863782673862783670.71738\ | 45 | 2867327835672967385278372637862738627836279863782673862783670.7173817\ |
48 | 17836173871836718637861073861783678160376017836701860376017810773527\ | 46 | 836173871836718637861073861783678160376017836701860376017810773527837\ |
49 | 8372832783728367826738627836278378260736270367362073867097307925 | 47 | 2832783728367826738627836278378260736270367362073867097307925 |
50 | 9812734012837410982345719208345712908357412903587192048571920458712.\ | 48 | 9812734012837410982345719208345712908357412903587192048571920458712.2\ |
51 | 23957182459817249058172945781 | 49 | 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 @@ | |||
58 | 100864416620775.31076855630746548983 | 58 | 100864416620775.31076855630746548983 |
59 | -53336.193401942302558132911110799109649707477 | 59 | -53336.193401942302558132911110799109649707477 |
60 | .00000000052530099381 | 60 | .00000000052530099381 |
61 | .0000000000000000000000000000000000000000000000000000000000000001907\ | 61 | .00000000000000000000000000000000000000000000000000000000000000019072\ |
62 | 266929376630027064745963897 | 62 | 66929376630027064745963897 |
63 | 42612515855353136519261264261472677699404182.78776061098893912189 | 63 | 42612515855353136519261264261472677699404182.78776061098893912189 |
64 | 0 | 64 | 0 |
65 | 0 | 65 | 0 |
@@ -121,6 +121,6 @@ | |||
121 | 100864416620775 | 121 | 100864416620775 |
122 | -3878923750692883.7238596702834756902 | 122 | -3878923750692883.7238596702834756902 |
123 | 0 | 123 | 0 |
124 | .0000000000000000000000000000000000000000000184866017689020776005643\ | 124 | .00000000000000000000000000000000000000000001848660176890207760056433\ |
125 | 3621086 | 125 | 621086 |
126 | 42612515855353136519261264261472677699404182 | 126 | 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 @@ | |||
15 | 3543531533584430580556128344529291738 | 15 | 3543531533584430580556128344529291738 |
16 | 568600835566479683035874339053.4411638427543228060 | 16 | 568600835566479683035874339053.4411638427543228060 |
17 | 7487566285885.8557453089005171423976251098 | 17 | 7487566285885.8557453089005171423976251098 |
18 | 373846412427291014394738378015501363938345620046.7869650248829232267\ | 18 | 373846412427291014394738378015501363938345620046.78696502488292322672\ |
19 | 2297002026819 | 19 | 297002026819 |
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 @@ | |||
10 | 18927361346 | 10 | 18927361346 |
11 | .23523785962738592635777 | 11 | .23523785962738592635777 |
12 | 328956734869213746.89782398457234 | 12 | 328956734869213746.89782398457234 |
13 | 16473742664221279051571200630760751138799221376964991600670000200609\ | 13 | 164737426642212790515712006307607511387992213769649916006700002006090\ |
14 | 08006052596520320731708604393844468006290371918262741885989163144389\ | 14 | 800605259652032073170860439384446800629037191826274188598916314438939\ |
15 | 39367835091560809036359941703341471396407660150658436796925310445979\ | 15 | 367835091560809036359941703341471396407660150658436796925310445979213\ |
16 | 21333166245765946557344383284626113908419359990042883048537750217279\ | 16 | 331662457659465573443832846261139084193599900428830485377502172791748\ |
17 | 17481980123593363177308481941550382845381799410533956718500484099889\ | 17 | 198012359336317730848194155038284538179941053395671850048409988961080\ |
18 | 610805653325917409549921909941664118421333562129 | 18 | 5653325917409549921909941664118421333562129 |
19 | 0 | 19 | 0 |
20 | 43287877285033571298394739716218787350087163435619825150259705419.98\ | 20 | 43287877285033571298394739716218787350087163435619825150259705419.980\ |
21 | 016445740928054425 | 21 | 16445740928054425 |
22 | 1.00000000000000000000 | 22 | 1.00000000000000000000 |
23 | .50000000000000000000 | 23 | .50000000000000000000 |
24 | .10000000000000000000 | 24 | .10000000000000000000 |
@@ -31,27 +31,27 @@ | |||
31 | 1 | 31 | 1 |
32 | -2 | 32 | -2 |
33 | 4 | 33 | 4 |
34 | 14997322375665265051328725757939209353051902095893907150382724666290\ | 34 | 149973223756652650513287257579392093530519020958939071503827246662904\ |
35 | 49749481660976421019742616298227588464420182758442163654172400528243\ | 35 | 974948166097642101974261629822758846442018275844216365417240052824300\ |
36 | 00885441207762486233574213374503090372518590691583139696652847404883\ | 36 | 885441207762486233574213374503090372518590691583139696652847404883085\ |
37 | 08573912261119588874308960204159666762789603037188471170006223907416\ | 37 | 739122611195888743089602041596667627896030371884711700062239074166049\ |
38 | 60492840269152716750700089148882139254399347568222390231015487895905\ | 38 | 284026915271675070008914888213925439934756822239023101548789590573727\ |
39 | 73727080561379177721440905866857248917982113340543176658480139248897\ | 39 | 080561379177721440905866857248917982113340543176658480139248897548025\ |
40 | 54802503253413282808814063861470711399810899724515727713334909764746\ | 40 | 032534132828088140638614707113998108997245157277133349097647462791029\ |
41 | 27910290211411231279325882505708287941671508154740003122373284699097\ | 41 | 021141123127932588250570828794167150815474000312237328469909778346501\ |
42 | 78346501539634198926772266511968381368929692275950529960923432771985\ | 42 | 539634198926772266511968381368929692275950529960923432771985125971893\ |
43 | 12597189390708050983487158873301681237787429436264801751664042999180\ | 43 | 907080509834871588733016812377874294362648017516640429991803448659818\ |
44 | 3448659818912436089 | 44 | 912436089 |
45 | 11478830555358864333472551120140548480416206583184496764727387456058\ | 45 | 114788305553588643334725511201405484804162065831844967647273874560587\ |
46 | 792742209537931243951391229607936 | 46 | 92742209537931243951391229607936 |
47 | -.00000000000000017759 | 47 | -.00000000000000017759 |
48 | -2067373624686414405470850679965010694114490999957199847684803894306\ | 48 | -20673736246864144054708506799650106941144909999571998476848038943065\ |
49 | 56243666149296582304582679590231948238805965642713928910384741502707\ | 49 | 6243666149296582304582679590231948238805965642713928910384741502707.2\ |
50 | .23224479257866798694 | 50 | 3224479257866798694 |
51 | 11606078892843496082360561256965139908586179418605021706789617179085\ | 51 | 116060788928434960823605612569651399085861794186050217067896171790858\ |
52 | 85768049299693425729565480314913006780973928345684673490252494674985\ | 52 | 576804929969342572956548031491300678097392834568467349025249467498501\ |
53 | 0186164225375953066263609289359900615361965737717208159874390.293769\ | 53 | 86164225375953066263609289359900615361965737717208159874390.293769702\ |
54 | 70206344604971 | 54 | 06344604971 |
55 | -1.00000000000000000000 | 55 | -1.00000000000000000000 |
56 | 1.00000000000000000000 | 56 | 1.00000000000000000000 |
57 | -.50000000000000000000 | 57 | -.50000000000000000000 |
@@ -59,14 +59,14 @@ | |||
59 | 0 | 59 | 0 |
60 | 0 | 60 | 0 |
61 | -.00000000000002874159 | 61 | -.00000000000002874159 |
62 | -1945134149489344891879057554905782841936258356736314337975569799825\ | 62 | -19451341494893448918790575549057828419362583567363143379755697998259\ |
63 | 94091939572752348215929683891336730843553721422164737465108229034947\ | 63 | 409193957275234821592968389133673084355372142216473746510822903494787\ |
64 | 87333189564755763444242676978610321731298729194092653999616928308494\ | 64 | 333189564755763444242676978610321731298729194092653999616928308494264\ |
65 | 26419468484566422775668903315088810746121307679948574976162519479931\ | 65 | 194684845664227756689033150888107461213076799485749761625194799311893\ |
66 | 18935243698160094347216562490000767121041786977792546155155934655909\ | 66 | 524369816009434721656249000076712104178697779254615515593465590914123\ |
67 | 14123833869470494708767968978717730012864171105540029928688274136791\ | 67 | 833869470494708767968978717730012864171105540029928688274136791981750\ |
68 | 98175053824022144065005509214813689232148489884560100200475909009813\ | 68 | 538240221440650055092148136892321484898845601002004759090098133400981\ |
69 | 340098100705258138.98542904577525702068 | 69 | 00705258138.98542904577525702068 |
70 | 0 | 70 | 0 |
71 | 0 | 71 | 0 |
72 | 0 | 72 | 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 @@ | |||
8 | 2874519803456326214611 | 8 | 2874519803456326214611 |
9 | 9000000000000000000000000000000000000001 | 9 | 9000000000000000000000000000000000000001 |
10 | 1 | 10 | 1 |
11 | 9000000000000000000000000000000000000000.000000000000000000000000000\ | 11 | 9000000000000000000000000000000000000000.0000000000000000000000000000\ |
12 | 00000001 | 12 | 0000001 |
13 | .0000000000000000000000000000000001 | 13 | .0000000000000000000000000000000001 |
14 | 9999999999999999999999999999999999999999.999999999999999999999999999\ | 14 | 9999999999999999999999999999999999999999.9999999999999999999999999999\ |
15 | 9999999999999999999999999999999999999999999999999999999999 | ||
16 | 10000000000000000000000000000000000000000.999999999999999999999999999\ | ||
15 | 99999999999999999999999999999999999999999999999999999999999 | 17 | 99999999999999999999999999999999999999999999999999999999999 |
16 | 10000000000000000000000000000000000000000.99999999999999999999999999\ | 18 | 10000000000000000000000000000000000000000.000000000099999999999999999\ |
17 | 999999999999999999999999999999999999999999999999999999999999 | 19 | 9999999999999999999999999999999999999999999999999 |
18 | 10000000000000000000000000000000000000000.00000000009999999999999999\ | ||
19 | 99999999999999999999999999999999999999999999999999 | ||
20 | -8 | 20 | -8 |
21 | -182934721309467230894628759280719690 | 21 | -182934721309467230894628759280719690 |
22 | 1245723576605103923392087218483 | 22 | 1245723576605103923392087218483 |