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>
This commit is contained in:
Denys Vlasenko 2020-12-29 18:50:56 +01:00
parent cba45d9b65
commit 29a9043b36
7 changed files with 110 additions and 104 deletions

View File

@ -231,7 +231,7 @@ typedef struct BcNum {
#define BC_NUM_MAX_IBASE 36 #define BC_NUM_MAX_IBASE 36
// larger value might speed up BIGNUM calculations a bit: // larger value might speed up BIGNUM calculations a bit:
#define BC_NUM_DEF_SIZE 16 #define BC_NUM_DEF_SIZE 16
#define BC_NUM_PRINT_WIDTH 69 #define BC_NUM_PRINT_WIDTH 70
#define BC_NUM_KARATSUBA_LEN 32 #define BC_NUM_KARATSUBA_LEN 32
@ -7372,11 +7372,29 @@ static unsigned xc_vm_envLen(const char *var)
lenv = getenv(var); lenv = getenv(var);
len = BC_NUM_PRINT_WIDTH; len = BC_NUM_PRINT_WIDTH;
if (!lenv) return len; if (lenv) {
len = bb_strtou(lenv, NULL, 10);
len = bb_strtou(lenv, NULL, 10) - 1; if (len == 0 || len > INT_MAX)
if (errno || len < 2 || len >= INT_MAX) len = INT_MAX;
if (errno)
len = BC_NUM_PRINT_WIDTH; 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; return len;
} }
@ -7467,16 +7485,6 @@ int dc_main(int argc UNUSED_PARAM, char **argv)
INIT_G(); 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"); xc_vm_init("DC_LINE_LENGTH");
// Run -e'SCRIPT' and -fFILE in order of appearance, then handle FILEs // Run -e'SCRIPT' and -fFILE in order of appearance, then handle FILEs

View File

@ -9,9 +9,9 @@
1998 1998
324869359109479 324869359109479
2378639108055453348401 2378639108055453348401
78562139406792834691802347619083467219846713490861872324967138636055\ 785621394067928346918023476190834672198467134908618723249671386360554\
45508706362018540498696043776980521464405852627147161556994835657433\ 550870636201854049869604377698052146440585262714716155699483565743300\
00967298 967298
1.1 1.1
1.1 1.1
37842935130118.1187478621432354 37842935130118.1187478621432354
@ -20,21 +20,21 @@
-2 -2
-19 -19
-1287904651762470260258 -1287904651762470260258
100000000000000000000000000000000000000000000000000000000000.0000000\ 100000000000000000000000000000000000000000000000000000000000.00000000\
00000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000.0000000\ 100000000000000000000000000000000000000000000000000000000000.00000000\
00000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000.0000000\ 100000000000000000000000000000000000000000000000000000000000.00000000\
00000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000009999 0000000000000000000000000000000000000009999
99999999999999999999999999999999999999999999999999999999999.99999999\ 99999999999999999999999999999999999999999999999999999999999.999999999\
99999999999999999999999999999999999999999999999999000000000000000000\ 999999999999999999999999999999999999999999999999900000000000000000000\
00000000000000000000000000000000000000009999 000000000000000000000000000000000000009999
99999999999999999999999999999999999990000000000000000000000.00000000\ 99999999999999999999999999999999999990000000000000000000000.000000000\
00000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000009999 000000000000000000000000000000000000009999
122761518 122761518
-14338.391079082 -14338.391079082
-2422295.6865057444 -2422295.6865057444

View File

@ -9,19 +9,17 @@
123 123
7505 7505
1023468723275435238491972521917846 1023468723275435238491972521917846
43434724324317058673920735170382703980273527090273892739207390379379\ 434347243243170586739207351703827039802735270902738927392073903793796\
60379637893607893607893670530278200795207952702873892786172916728961\ 037963789360789360789367053027820079520795270287389278617291672896178\
78390789360741897358785738607967926792673752073092537298378279365279\ 3907893607418973587857386079679267926737520730925372983782793652793
3
-1 -1
-203 -203
-57 -57
-18586 -18586
-31378682943772818461924738352952347258 -31378682943772818461924738352952347258
-8239456287456735894950672387239865203756982376208346745096273452730\ -82394562874567358949506723872398652037569823762083467450962734527309\
96287563846592384526349872634895763257893467523987578690283762897568\ 628756384659238452634987263489576325789346752398757869028376289756845\
45907234875807107108781350187590812735901871502384171023987230138727\ 9072348758071071087813501875908127359018715023841710239872301387278
8
.123521346523546 .123521346523546
.1245923756273856 .1245923756273856
-.1024678456387 -.1024678456387
@ -31,21 +29,21 @@
234237468293576.000000000000000000000000000000 234237468293576.000000000000000000000000000000
23987623568943567.00000000000000000005677834650000000000000 23987623568943567.00000000000000000005677834650000000000000
23856934568940675.000000000000000435676782300000000000000456784 23856934568940675.000000000000000435676782300000000000000456784
77567648698496.00000000000000000058767475000000000045856380000000000\ 77567648698496.000000000000000000587674750000000000458563800000000000\
0000 000
2348672354968723.237482354600000000000325698739450234689243562387000\ 2348672354968723.2374823546000000000003256987394502346892435623870000\
0000034578 000034578
-2354768.000000000000000000000000000000000000 -2354768.000000000000000000000000000000000000
-96739874567.000000000347683456 -96739874567.000000000347683456
-3764568345.000000000004573845000000347683460 -3764568345.000000000004573845000000347683460
-356784356.934568495770004586495678300000000 -356784356.934568495770004586495678300000000
74325437345273852773827101738273127312738521733017537073520735207307\ 743254373452738527738271017382731273127385217330175370735207352073075\
570358738257390761276072160719802671980267018728630178.7082681027680\ 70358738257390761276072160719802671980267018728630178.708268102768052\
52176021786784127612768127086782782176817317820783071097801773817867\ 176021786784127612768127086782782176817317820783071097801773817867801\
8012767377058785378278207385237085237803278203782037237582795870 2767377058785378278207385237085237803278203782037237582795870
-7567527327852738512737285378527382578372836789657385273852729836783\ -75675273278527385127372853785273825783728367896573852738527298367837\
72867327835672967385278372637862738627836279863782673862783670.71738\ 2867327835672967385278372637862738627836279863782673862783670.7173817\
17836173871836718637861073861783678160376017836701860376017810773527\ 836173871836718637861073861783678160376017836701860376017810773527837\
8372832783728367826738627836278378260736270367362073867097307925 2832783728367826738627836278378260736270367362073867097307925
9812734012837410982345719208345712908357412903587192048571920458712.\ 9812734012837410982345719208345712908357412903587192048571920458712.2\
23957182459817249058172945781 3957182459817249058172945781

View File

@ -58,8 +58,8 @@
100864416620775.31076855630746548983 100864416620775.31076855630746548983
-53336.193401942302558132911110799109649707477 -53336.193401942302558132911110799109649707477
.00000000052530099381 .00000000052530099381
.0000000000000000000000000000000000000000000000000000000000000001907\ .00000000000000000000000000000000000000000000000000000000000000019072\
266929376630027064745963897 66929376630027064745963897
42612515855353136519261264261472677699404182.78776061098893912189 42612515855353136519261264261472677699404182.78776061098893912189
0 0
0 0
@ -121,6 +121,6 @@
100864416620775 100864416620775
-3878923750692883.7238596702834756902 -3878923750692883.7238596702834756902
0 0
.0000000000000000000000000000000000000000000184866017689020776005643\ .00000000000000000000000000000000000000000001848660176890207760056433\
3621086 621086
42612515855353136519261264261472677699404182 42612515855353136519261264261472677699404182

View File

@ -15,8 +15,8 @@
3543531533584430580556128344529291738 3543531533584430580556128344529291738
568600835566479683035874339053.4411638427543228060 568600835566479683035874339053.4411638427543228060
7487566285885.8557453089005171423976251098 7487566285885.8557453089005171423976251098
373846412427291014394738378015501363938345620046.7869650248829232267\ 373846412427291014394738378015501363938345620046.78696502488292322672\
2297002026819 297002026819
-1 -1
-2 -2
-2751507058396910892 -2751507058396910892

View File

@ -10,15 +10,15 @@
18927361346 18927361346
.23523785962738592635777 .23523785962738592635777
328956734869213746.89782398457234 328956734869213746.89782398457234
16473742664221279051571200630760751138799221376964991600670000200609\ 164737426642212790515712006307607511387992213769649916006700002006090\
08006052596520320731708604393844468006290371918262741885989163144389\ 800605259652032073170860439384446800629037191826274188598916314438939\
39367835091560809036359941703341471396407660150658436796925310445979\ 367835091560809036359941703341471396407660150658436796925310445979213\
21333166245765946557344383284626113908419359990042883048537750217279\ 331662457659465573443832846261139084193599900428830485377502172791748\
17481980123593363177308481941550382845381799410533956718500484099889\ 198012359336317730848194155038284538179941053395671850048409988961080\
610805653325917409549921909941664118421333562129 5653325917409549921909941664118421333562129
0 0
43287877285033571298394739716218787350087163435619825150259705419.98\ 43287877285033571298394739716218787350087163435619825150259705419.980\
016445740928054425 16445740928054425
1.00000000000000000000 1.00000000000000000000
.50000000000000000000 .50000000000000000000
.10000000000000000000 .10000000000000000000
@ -31,27 +31,27 @@
1 1
-2 -2
4 4
14997322375665265051328725757939209353051902095893907150382724666290\ 149973223756652650513287257579392093530519020958939071503827246662904\
49749481660976421019742616298227588464420182758442163654172400528243\ 974948166097642101974261629822758846442018275844216365417240052824300\
00885441207762486233574213374503090372518590691583139696652847404883\ 885441207762486233574213374503090372518590691583139696652847404883085\
08573912261119588874308960204159666762789603037188471170006223907416\ 739122611195888743089602041596667627896030371884711700062239074166049\
60492840269152716750700089148882139254399347568222390231015487895905\ 284026915271675070008914888213925439934756822239023101548789590573727\
73727080561379177721440905866857248917982113340543176658480139248897\ 080561379177721440905866857248917982113340543176658480139248897548025\
54802503253413282808814063861470711399810899724515727713334909764746\ 032534132828088140638614707113998108997245157277133349097647462791029\
27910290211411231279325882505708287941671508154740003122373284699097\ 021141123127932588250570828794167150815474000312237328469909778346501\
78346501539634198926772266511968381368929692275950529960923432771985\ 539634198926772266511968381368929692275950529960923432771985125971893\
12597189390708050983487158873301681237787429436264801751664042999180\ 907080509834871588733016812377874294362648017516640429991803448659818\
3448659818912436089 912436089
11478830555358864333472551120140548480416206583184496764727387456058\ 114788305553588643334725511201405484804162065831844967647273874560587\
792742209537931243951391229607936 92742209537931243951391229607936
-.00000000000000017759 -.00000000000000017759
-2067373624686414405470850679965010694114490999957199847684803894306\ -20673736246864144054708506799650106941144909999571998476848038943065\
56243666149296582304582679590231948238805965642713928910384741502707\ 6243666149296582304582679590231948238805965642713928910384741502707.2\
.23224479257866798694 3224479257866798694
11606078892843496082360561256965139908586179418605021706789617179085\ 116060788928434960823605612569651399085861794186050217067896171790858\
85768049299693425729565480314913006780973928345684673490252494674985\ 576804929969342572956548031491300678097392834568467349025249467498501\
0186164225375953066263609289359900615361965737717208159874390.293769\ 86164225375953066263609289359900615361965737717208159874390.293769702\
70206344604971 06344604971
-1.00000000000000000000 -1.00000000000000000000
1.00000000000000000000 1.00000000000000000000
-.50000000000000000000 -.50000000000000000000
@ -59,14 +59,14 @@
0 0
0 0
-.00000000000002874159 -.00000000000002874159
-1945134149489344891879057554905782841936258356736314337975569799825\ -19451341494893448918790575549057828419362583567363143379755697998259\
94091939572752348215929683891336730843553721422164737465108229034947\ 409193957275234821592968389133673084355372142216473746510822903494787\
87333189564755763444242676978610321731298729194092653999616928308494\ 333189564755763444242676978610321731298729194092653999616928308494264\
26419468484566422775668903315088810746121307679948574976162519479931\ 194684845664227756689033150888107461213076799485749761625194799311893\
18935243698160094347216562490000767121041786977792546155155934655909\ 524369816009434721656249000076712104178697779254615515593465590914123\
14123833869470494708767968978717730012864171105540029928688274136791\ 833869470494708767968978717730012864171105540029928688274136791981750\
98175053824022144065005509214813689232148489884560100200475909009813\ 538240221440650055092148136892321484898845601002004759090098133400981\
340098100705258138.98542904577525702068 00705258138.98542904577525702068
0 0
0 0
0 0

View File

@ -8,15 +8,15 @@
2874519803456326214611 2874519803456326214611
9000000000000000000000000000000000000001 9000000000000000000000000000000000000001
1 1
9000000000000000000000000000000000000000.000000000000000000000000000\ 9000000000000000000000000000000000000000.0000000000000000000000000000\
00000001 0000001
.0000000000000000000000000000000001 .0000000000000000000000000000000001
9999999999999999999999999999999999999999.999999999999999999999999999\ 9999999999999999999999999999999999999999.9999999999999999999999999999\
9999999999999999999999999999999999999999999999999999999999
10000000000000000000000000000000000000000.999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999 99999999999999999999999999999999999999999999999999999999999
10000000000000000000000000000000000000000.99999999999999999999999999\ 10000000000000000000000000000000000000000.000000000099999999999999999\
999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999
10000000000000000000000000000000000000000.00000000009999999999999999\
99999999999999999999999999999999999999999999999999
-8 -8
-182934721309467230894628759280719690 -182934721309467230894628759280719690
1245723576605103923392087218483 1245723576605103923392087218483