bc(1) General Commands Manual bc(1) NEV bc - Lebegopontos kalkulator nyelv ATTEKINTES bc [ -hlwsqv ] [long-options] [ file ... ] LEIRAS bc egy olyan nyelv, amely lebegopontos szamolast nyujt, interaktiv vegrehajtassal. Van nemi hasonlosag a C programozasi nyelvvel. Egy standard matematikai konyvtar megadhato parancssor parameterkent. Ha szukseges, a matematikai konyvtarat definialni kell, mielott barmilyen mas fajlt feldolgoznank. A bc a megadott fajlokban levo kodot a megadas sorrenjeben dolgozza fel. Miutan minden fajlt feldolgozott a bc a szabvanyos bemenetrol var tovabbi utasitasokat. Minden kodot a beolvasas pillanataban vegrehajt. (Ha egy fajlban olyan utasitas talalhato, amely megallitja a feldolgozot, a bc nem fog a szabvanyos bemenetrol olvasni. A bc ezen implementacioja sok bovitessel rendelkezik a POSIX standardhoz kepest. Parancssor opcioval megadhato, hogy a program ezeknel figyelmeztessen, vagy dobja vissza oket. Ez a dokumentum az ezen feldolgozo altal elfogadott nyelvet irja le. A kiterjesztesek termeszetesen jelolesre kerulnek. KAPCSOLOK -h, --help Print the usage and exit. -i, --interactive Force interactive mode. -l, --mathlib Definialja a standard matematikai konyvtarat. -w, --warn Figyelmeztet a POSIX bc-hez kepest hasznalt kiterjesztesekre. -s, --standard Csak a pontos POSIX bc nyelvet dolgozza fel. -q, --quiet Do not print the normal GNU bc welcome. -v, --version Print the version number and copyright and quit. SZAMOK The most basic element in bc is the number. Numbers are arbitrary precision numbers. This precision is both in the integer part and the fractional part. All numbers are represented internally in decimal and all computation is done in decimal. (This version truncates results from divide and multiply operations.) There are two attributes of numbers, the length and the scale. The length is the total number of decimal digits used by bc to represent a number and the scale is the total number of decimal digits after the decimal point. For example: .000001 szamnak a hossza es a lepteke is 6. mig az 1935.000 szamnak a hossza 7, a lepteke 3. VALTOZOK A szamokat ket fajta valtozoban lehet tarolni, egyszeru valtozoban vagy tombben. Mind az egyszeru, mind a tombvaltozonak van neve. A neveknek betuvel kell kezdodniuk, ezt kovethetik szamok, betuk vagy alahuzasok. Minden betunek kisbetunek kell lennie. (A teljes alfanumerikus nevek mar egy kiterjesztes. A POSIX bc-ben minden nev egy kisbetubol all.) A valtozo tipusa a kontextusbol tisztan kiderul, mivel minden tomb valtozot egy szogletes zarojel par ([]) kovet. Negy specialis valtozo van, scale, ibase, obase, es last. A scale azt definialja, hogy nehany muvelet a tizdes pont utan hany szamjegyet hasznaljon. A scale alapertelmezett erteke 0. Az ibase es az obase definialja a bemeneti es a kimeneti szamrendszer konverziot. Az alapertelmezett szamrendszer mind a bemenetre, mind a kimenetre 10-es. A last (kiterjesztes) valtozoban az utolso kiirt ertek szerepel. Ez kesobb kerul reszletezesre. Ezeknek vatlozoknak lehet erteket adni, de kifejezesben is hasznalhatoak. MEGJEGYZES A megjegyzesek a bc-ben a /* karakterekkel kezdodnek es a */ karakterek jelzik a veget. A megjegyzesek barhol megjelenhetnek, es a bemenetben egy szokozt jelentenek. (Ez azt jelenti, hogy a megjegyzesek elhatarolnak mas objektumokat. Peldaul, egy megjegyzes nem lehet egy valtozonev kozepen.) A megjegyzesekben barmennyi ujsor lehet (sor vege), a megjegyzes kezdete es vege kozott. To support the use of scripts for bc, a single line comment has been added as an extension. A single line comment starts at a # character and continues to the next end of the line. The end of line character is not part of the comment and is processed normally. KIFEJEZESEK A szamokat kifejezesekkel es utasitasokkal lehet manipulalni. Mivel a nyelvet interaktivra keszitettek, az utasitasok es a kifejezesek rogton vegrehajtodnak. Nincs "fo" program (main fuggveny). A kod olyan sorrendben hajtodik vegre, ahogy a bc beolvassa. (A fuggvenyek, kesobb kerulnek leirasra, a beolvasas sorrendjeben kerulnek definialasra.) A simple expression is just a constant. bc converts constants into internal decimal numbers using the current input base, specified by the variable ibase. (There is an exception in functions.) The valid values for ibase are 2 through 36. (Bases greater than 16 are an extension.) Assigning a value outside this range to ibase will result in a value of 2 or 36. Input numbers may contain the characters 0-9 and A-Z. (Note: They must be capitals. Lower case letters are variable names.) Single digit numbers always have the value of the digit regardless of the value of ibase. (i.e. A = 10.) For multi-digit numbers, bc changes all input digits greater or equal to ibase to the value of ibase-1. This makes the number ZZZ always be the largest 3 digit number of the input base. A teljes kifejezesek hasonloak a tobbi magas szintu nyelvben levokhoz. Mivel csak egyetlen tipusu szam van, nincs szabaly a tipusok keveresenek kezelesere. Minden kifejezesnek van egy pontossaga. Ez az eredeti szamokbol, az elvegzett muveletekbol es meg sok egyebbol tevodik ossze, az erteke a scale valtozoban talalhato. Ezen valtozo legalis ertekei a 0-tol a C nyelvben egesz szamnak megadhato legnagyobb ertekig terjednek. In the following descriptions of valid expressions, "expr" refers to a complete expression and "var" refers to a simple or an array variable. A simple variable is just a nev mig egy tombre a leirasaval hivatkozhatunk. Hacsak maskent nem specifikaljuk, az eredmeny pontossaga a kifejezesek pontossaganak a maximuma lesz. Unless specifically mentioned the scale of the result is the maximum scale of the expressions involved. - expr Az eredmeny a kifejezes negaltja. ++ var A valtozo erteke eggyel no, es az eredmeny a valtozo uj erteke lesz. -- var A valtozo erteke eggyel csokken, es az eredmeny a valtozo uj erteke lesz. var ++ The result of the expression is the value of the variable and then the variable is incremented by one. var -- A kifejezes eredmenye a valtozo eredeti erteke, majd a valtozo erteke csokken eggyel. expr + expr Az eredmeny a ket kifejezes osszege. expr - expr Az eredmeny a ket kifejezes kulonbsege. expr * expr Az eredmeny a ket kifejezes szorzata. expr / expr Az eredmeny a ket kifejezes hanyadosa. Az eredmeny pontossagat a scale valtozo erteke hatarozza meg. expr % expr Az eredmeny a "maradek", amely a kovetkezokeppen kerul kiszamolasra. Az a%b kiszamolasahoz eloszor, kiszamolasra kerul az a/b, scale szamjegyre. Az eredmeny a kovetkezokeppen adodik: a-(a/b)*b, a pontossaga a scale+scale(b) es scale(a) kozul a nagyobb lesz. Ha a scale egyenlo nullaval, vagy mindket kifejezes egesz, a maradek is egesz lesz. expr ^ expr The result of the expression is the value of the first raised to the second. The second expression must be an integer. (If the second expression is not an integer, a warning is generated and the expression is truncated to get an integer value.) The scale of the result is scale if the exponent is negative. If the exponent is positive the scale of the result is the minimum of the scale of the first expression times the value of the exponent and the maximum of scale and the scale of the first expression. (e.g. scale(a^b) = min(scale(a)*b, max( scale, scale(a))).) It should be noted that expr^0 will always return the value of 1. ( expr ) Ez megvaltoztatja a kifejezes kiertekelesenek standard precedenciajat. var = expr A valtozo erteke a kifejezes lesz. var = expr Ez ekvivalens a "var = var expr" kifejezessel, azzal a kivetellel, hogy a "var" resz csak egyszer ertekelodik ki. Ez akkor okozhat kulonbseget, ha a "var" egy tomb. Relational expressions are a special kind of expression that always evaluate to 0 or 1, 0 if the relation is false and 1 if the relation is true. These may appear in any valid expression. (POSIX bc requires that relational expressions are used only in if, while, and for statements and that only one relational test may be done in them.) The relational operators are expr1 < expr2 Az eredmeny 1, ha az expr1 kisebb, mint az expr2. expr1 <= expr2 Az eredmeny 1, ha az expr1 kisebb, vagy egyenlo, mint az expr2. expr1 > expr2 Az eredmeny 1, ha az expr1 nagyobb, mint az expr2. expr1 >= expr2 Az eredmeny 1, ha az expr1 nagyobb, vagy egyenlo, mint az expr2. expr1 == expr2 Az eredmeny 1, ha az expr1 egyenlo az expr2-vel. expr1 != expr2 Az eredmeny 1, ha az expr1 nem egyenlo az expr2-vel. Boolean operations are also valid. (POSIX bc does NOT have boolean operations). The result of all boolean operations are 0 and 1 (for false and true) as in relational expressions. The boolean operators are: !expr Az eredmeny 1, ha a kifejezes 0. expr && expr Az eredmeny 1, ha a mindket kifejezes nem 0. expr || expr Az eredmeny 1, ha a barmelyik kifejezes nem 0. A kifejezesek precedenciaja a kovetkezo (alacsonytol a magas fele): || operator, balrol asszociativ && operator, balrol asszociativ ! operator, nem asszociativ Relacios operatorok, balrol asszociativ Ertekado operator, jobbrol asszociativ + es - operatorok, balrol associative *, / es % operatorok, balrol asszociativ ^ operator, jobbrol asszociativ unaris - operator, nem asszociativ ++ es -- operatorok, nem asszociativ Ez a precedencia ugy van megvalasztva, hogy a POSIX bc ala programok is korrekten fussanak. Emiatt, a relacios es logikai operatorokat az ertekado operatoroknal neha szokatlan eredmeny is kijohet. Lasd a kovetkezo kifejezest: a = 3 < 5 A legtobb C programozo ezt ugy ertelmezi, hogy a "3 < 5" (az erteke 1) kerul az "a" valtozoba. A bc itt a kovetkezot csinalja, hozzarendeli a 3-at az "a" valtozohoz, majd a 3-at osszehasonlitja az 5-tel. A legjobb, hogyha ertekado operatort hasznalsz relacios, es logikai operatorokkal, akkor hasznalsz zarojeleket. Van nehany egyeb specialis kifejezes, amelyet meg a bc nyujt. Ezek a felhasznalo altal definialhato fuggvenyek, es a standard fuggvenyek hivasa. Ezek a kovetkezo alakban jelennek meg: name(parameters) A fuggvenyekhez lasd meg a felhasznalo altal definialt fuggvenyek fejezetet. A standard fuggvenyek a kovetkezoek: length ( expression ) A length fuggveny erteke a kifejezesben megadott szam ertekes jegyeinek szama. read ( ) A read fuggveny (kiterjesztes) beolvas egy szamot a szabvanyos bemenetrol, fuggetlenul attol, hogy a fuggveny hol talalhato. Figyelmeztetes: ez problemat okozhat, ha mind a program, mind az adatok a standard bementrol jonnek. A legjobb, ha ezt a fuggvenyt csak elore megirt programoknal hasznaljuk, amely adatokat ker a felhasznalotol, de nem engedi meg, hogy a felhasznalo program kodot is beirjon. A read fuggveny erteke a szabvanyos bemenetrol beolvasott szam erteke, az ibase valtozo erteket, mint szamrendszert hasznalva a konverzio alapjaul. scale ( expression ) A scale fuggveny erteke a kifejezes tizedespont mogott szereplo szamjegyeinek szama. sqrt ( expression ) Az sqrt fuggveny erteke a kifejezes ertekenek a negyzetgyokevel egyenlo. Ha a kifejezes negativ, egy futasi hiba generalodik. UTASITASOK Statements (as in most algebraic languages) provide the sequencing of expression evaluation. In bc statements are executed "as soon as possible". Execution happens when a newline in encountered and there is one or more complete statements. Due to this immediate execution, newlines are very important in bc. In fact, both a semicolon and a newline are used as statement separators. An improperly placed newline will cause a syntax error. Because newlines are statement separators, it is possible to hide a newline by using the backslash character. The sequence "\", where is the newline appears to bc as whitespace instead of a newline. A statement list is a series of statements separated by semicolons and newlines. The following is a list of bc statements and what they do: (Things enclosed in brackets ([]) are optional parts of the statement.) expression This statement does one of two things. If the expression starts with " ...", it is considered to be an assignment statement. If the expression is not an assignment statement, the expression is evaluated and printed to the output. After the number is printed, a newline is printed. For example, "a=1" is an assignment statement and "(a=1)" is an expression that has an embedded assignment. All numbers that are printed are printed in the base specified by the variable obase. The valid values for obase are 2 through BC_BASE_MAX. (See the section LIMITS.) For bases 2 through 16, the usual method of writing numbers is used. For bases greater than 16, bc uses a multi-character digit method of printing the numbers where each higher base digit is printed as a base 10 number. The multi-character digits are separated by spaces. Each digit contains the number of characters required to represent the base ten value of "obase-1". Since numbers are of arbitrary precision, some numbers may not be printable on a single output line. These long numbers will be split across lines using the "\" as the last character on a line. The maximum number of characters printed per line is 70. Due to the interactive nature of bc, printing a number causes the side effect of assigning the printed value to the special variable last. This allows the user to recover the last value printed without having to retype the expression that printed the number. Assigning to last is valid and will overwrite the last printed value with the assigned value. The newly assigned value will remain until the next number is printed or another value is assigned to last. (Some installations may allow the use of a single period (.) which is not part of a number as a short hand notation for last.) string A string a kimenetre irodik ki. A stringek idezojellel kezdodnek, es barmilyen karaktert tartalmazhatnak a kovetkezo idezojelig. Egyetlen karakter sem kerul ertelmezesre, meg az ujsor karakter sem. A string kiirasa utan nem irodik ki ujsor karakter. print list A print utasitas (kiterjesztes), a kiiras egy ujabb modozatat kinalja. A "list" egy string es kifejezes lista, vesszovel elvalasztva. Minden string vagy kifejezes a lista sorrendjeben irodik ki. Zaro ujsor nem irodik ki. A kifejezesek kiertekelodnek, es az eredmenyuk a last valtozoban tarolasra kerul. A stringek pedig egyszeruen kiirasra kerulnek, specialis karaktereket is tartalmazhatnak. A specialis karakterek a backslalsh karakterrel kezdodnek (\). A specialis karakterek a kovetkezoek: "a" (figyelmeztetes, vagy bip), "b" (backspace), "f" (lapdobas), "n" (ujsor), "r" (kocsi vissza), "q" (idezojel), "t" (tabulator) es "\" (backslash). Minden mas, a backslash utan levo karaktert figyelmen kivul hagy a program. { utasitas_lista } Ez egy osszetett utasitas. Ennek segitsegevel lehet tobb vegrehajtando utasitast egybekapcsolni. if ( kifejezes ) then utasitas1 [else utasitas2] Az if kiertekeli a kifejezest, es vegrehajtja az utasitas1-et, vagy az utasitas2-t, a kifejezes erteketol fuggoen. Ha a kifejezes eredmenye nem nulla, az utasitas1 hajtodik vegre. Ha az utasitas2 letezik, es a kifejezes eredmenye nulla, az utasitas2 hajtodik vegre. (Az else ag kiterjesztes.) while ( kifejezes ) utasitas A while utasitas mindaddig vegrehajtja az utasitast, amig a kifejezes eredmenye nem nulla. Az utasitas minden vegrehajtasa elott kiertekeli a kifejezest. A ciklus akkor fejezodik be, ha a kifejezes eredmenye nulla lesz, vagy ha vegrehajtodik egy break utasitas. for ( [kifejezes1] ; [kifejezes2] ; [kifejezes3] ) utasitas A for utasitas egy utasitas ismetelt vegrehajtasat vezerli. A kifejezes1 a ciklus elott kiertekelodik. A kifejezes2 az utasitas minden vegrehajtasa elott kiertekelodik. Ha nem nulla, az utasitas vegrehajtodik, ha nulla, a ciklus veget er. Az utasitas minden vegrehajtasa utan, a kifejezes3 kiertekelodik, mielott a kifejezes2 kiszamolodna. Ha a kifejezes1 es a kifejezes3 hianyzik, a kiertekelodesuk helyen semmi nem fog tortenni. Ha a kifejezes2 hianyzik, az olyan, mintha a kifejezes2 helyen egy olyan kifejezes lenne, amelynek az eredmenye mindig 1. (Az opcionalis kifejezesek egy kiterjesztes.) A kovetkezo ekvivalens kodokat ad a for utasitasra: kifejezes1; while (kifejezes2) { utasitas; kifejezes3; } break Ezzel az utasitassal ki lehet lepni a legbelso while, vagy for utasitasbol. continue Ez az utasitas (kiterjesztes) azt eredmenyezi, hogy a legbelso for utasitas egy uj ciklust kezd. halt Ez az utasitas (kiterjesztes), ha vegrehajtodik, azt eredmenyezi, hogy a bc kilep. return Nulla ertekkel ter vissza egy fuggvenybol (lasd meg a fuggvenyek fejezetet). return ( kifejezes ) Return the value of the expression from a function. (See the section on functions.) As an extension, the parenthesis are not required. PSZEUDO UTASITASOK Ezek az utasitasok a tradicionalis ertelemben nem utasitasok. Nem hajtodnak vegre. Funkciojukat "forditasi" idoben fejtik ki. limits Kiirja a bc adott verzioja altal hasznalt hatarokat. Kiterjesztes. quit Ha a quit utasitast beolvassa, a bc feldolgozo kilep. Nem szamit, hogy az utasitas hol talalhato (pl. az "if (0 == 1) quit" hatasara is kilep a bc.) warranty Kiirja a figyelmezteto uzenetet. Kiterjesztes. FUGGVENYEK A fuggvenyekkel definialhatunk szamitasokat, amelyeket csak kesobb kivanunk vegrehajtani. A fuggvenyek a bc -ben mindig egy erteket szamolnak, es azt visszaadjak a hivonak. A fuggveny definicioja "dinamikus" abban az ertelemben, hogy mindaddig definialatlan, amig a feldolgozo nem talalkozik vele a bemeneten. Ez a definico mindaddig hasznalhato, amig egy ugyanezen nevu fuggveny definicoval nem talalkozik. Az uj definicio felulirja a regit. Egy fuggveny definicioja a kovetkezokeppen nez ki: define name ( parameters ) { newline auto_list statement_list } A fuggvenyhivas is egy kifejezes, a kovetkezo formaban: "name(parameters)". Parameters are numbers or arrays (an extension). In the function definition, zero or more parameters are defined by listing their names separated by commas. All parameters are call by value parameters. Arrays are specified in the parameter definition by the notation "name[]". In the function call, actual parameters are full expressions for number parameters. The same notation is used for passing arrays as for defining array parameters. The named array is passed by value to the function. Since function definitions are dynamic, parameter numbers and types are checked when a function is called. Any mismatch in number or types of parameters will cause a runtime error. A runtime error will also occur for the call to an undefined function. Az auto_list egy opcionalis valtozo lista, amely "helyi" valtozokat tartalmazza. A szintaxisa: "auto nev, ... ;". (A pontosvesszo opcionalis.) Minden nev egy auto valtozo neve. Tombok is definialhatoak igy, a szokasos modon. Ezek a valtozok a vermen kapnak helyet, a fuggveny belepese utan. A valtozok ezutan inicializalasra kerulnek nulla kezdoertekkel, es a fuggveny vegrehajtasa soran hasznalhatoak. Amikor a fuggveny kilep, ezeket a valtozokat eltavolitja a verembol, igy az eredeti ertekuk helyreallitodik. A parameterek is auto valtozok, amelyek a fuggveny meghivasakor kapjak meg ertekuket. Az auto valtozok kulonboznek a tradicionalis helyi valtozoktol a kovetkezo dologban: ha A meghivja a B fuggvenyt, B latja az A auto valtozoit, hacsak B-ben nincs ugyanezen neven is auto valtozo definialva. Azon teny miatt, hogy az auto valtozok es a parameterek egy vermen kapnak helyet, a bc kezeli a rekurziv fuggvenyeket is. A fuggveny torzse bc utasitasok listaja. Az utasitasokat pontosvesszok, vagy ujsorok valasztjak el. A return utasitas hatasara a fuggveny vegrehajtasa veget er, es visszater egy ertekkel. Az elso forma, a "return", 0-at ad vissza a hivonak, mig a masodik, "return ( kifejezes )", kiertekeli a kifejezest, es az eredmenyt adja vissza. A fuggveny vegen, ha mast nem irunk ki, mindig van egy "return (0)", ez megkimel attol, hogy explicite ki kelljen irni a return utasitast. A fuggvenyeknel megvaltozik az ibase valtozo hasznalata is. A fuggveny torzseben szereplo minden konstans, a fuggveny hivasakor hasznalatos ibase alapjan konvertalodik. Ha az ibase-t megvaltoztatjuk egy fuggvenyben, annak nem lesz hatasa, kiveve a read standard fuggvenyt, amely mindig az ibase aktualis erteket hasznalja a szamok konvertalasahoz. Several extensions have been added to functions. First, the format of the definition has been slightly relaxed. The standard requires the opening brace be on the same line as the define keyword and all other parts must be on following lines. This version of bc will allow any number of newlines before and after the opening brace of the function. For example, the following definitions are valid. define d (n) { return (2*n); } define d (n) { return (2*n); } Functions may be defined as void. A void funtion returns no value and thus may not be used in any place that needs a value. A void function does not produce any output when called by itself on an input line. The key word void is placed between the key word define and the function name. For example, consider the following session. define py (y) { print "--->", y, "<---", "\n"; } define void px (x) { print "--->", x, "<---", "\n"; } py(1) --->1<--- 0 px(1) --->1<--- Since py is not a void function, the call of py(1) prints the desired output and then prints a second line that is the value of the function. Since the value of a function that is not given an explicit return statement is zero, the zero is printed. For px(1), no zero is printed because the function is a void function. Also, call by variable for arrays was added. To declare a call by variable array, the declaration of the array parameter in the function definition looks like "*name[]". The call to the function remains the same as call by value arrays. MATEMATIKAI KONYVTAR Ha a bc-t a -l opcioval inditjuk, a matematikai konyvtar betoltodik, es a pontossag 20-as lesz. A matematikai fuggvenyek azzal a pontossaggal szamoljak ki az eredmenyt, amely a meghivasukkor be volt allitva. A matematikai konyvtar a kovetkezo fuggvenyeket definialja: s (x) Az x (radian) szinusza. c (x) Az x (radian) koszinusza. a (x) The arctangent of x, arctangent returns radians. l (x) Az x termeszetes logaritmusa. e (x) Az e x-edik hatvanya. j (n,x) Az n-ed rendu Bessel fuggvenye x-nek. PELDAK A /bin/sh-ban a kovetkezo utasitas visszaadja a "pi" erteket a pi kornyezeti valtozoban. pi=$(echo "scale=10; 4*a(1)" | bc -l) Az itt kovetkezo peldaban a matematikai konyvtarban talalhato hatvany fuggveny definiciojat mutatjuk be. A fuggveny POSIX bc nyelven irodott. scale = 20 /* Uses the fact that e^x = (e^(x/2))^2 When x is small enough, we use the series: e^x = 1 + x + x^2/2! + x^3/3! + ... */ define e(x) { auto a, d, e, f, i, m, v, z /* Check the sign of x. */ if (x<0) { m = 1 x = -x } /* Precondition x. */ z = scale; scale = 4 + z + .44*x; while (x > 1) { f += 1; x /= 2; } /* Initialize the variables. */ v = 1+x a = x d = 1 for (i=2; 1; i++) { e = (a *= x) / (d *= i) if (e == 0) { if (f>0) while (f--) v = v*v; scale = z if (m) return (1/v); return (v/1); } v += e } } A kovetkezo kod a bc kiterjesztett szolgaltatasait hasznalja, egy egyszeru csekkfuzet egyenleg kiszamolasara. Legjobb, ha ezt a programot fajlba lementjuk, hogy tobbszor is hasznalhassuk anelkul, hogy ujra be kelljen gepelni. scale=2 print "\nCheck book program!\n" print " Remember, deposits are negative transactions.\n" print " Exit by a 0 transaction.\n\n" print "Initial balance? "; bal = read() bal /= 1 print "\n" while (1) { "current balance = "; bal "transaction? "; trans = read() if (trans == 0) break; bal -= trans bal /= 1 } quit A kovetkezo fuggveny a faktorialis rekurziv definicioja. define f (x) { if (x <= 1) return (1); return (f(x-1) * x); } READLINE AND LIBEDIT OPTIONS GNU bc can be compiled (via a configure option) to use the GNU readline input editor library or the BSD libedit library. This allows the user to do editing of lines before sending them to bc. It also allows for a history of previous lines typed. When this option is selected, bc has one more special variable. This special variable, history is the number of lines of history retained. For readline, a value of -1 means that an unlimited number of history lines are retained. Setting the value of history to a positive number restricts the number of history lines to the number given. The value of 0 disables the history feature. The default value is 100. For more information, read the user manuals for the GNU readline, history and BSD libedit libraries. One can not enable both readline and libedit at the same time. ELTERESEK This version of bc was implemented from the POSIX P1003.2/D11 draft and contains several differences and extensions relative to the draft and traditional implementations. It is not implemented in the traditional way using dc(1). This version is a single process which parses and runs a byte code translation of the program. There is an "undocumented" option (-c) that causes the program to output the byte code to the standard output instead of running it. It was mainly used for debugging the parser and preparing the math library. A kulonbsegek legfobb forrasai a kiterjesztesek, hol egy szolgaltatas lett kiterjesztve, hogy tobb lehetosege legyen, hol pedig uj szolgaltatas lett letrehozva. A kovetkezo lista megmutatja a kulonbsegeket es a kiterjeszteseket. LANG environment Ez a verzio nem koveti a POSIX szabvanyt a LANG kornyezeti valtozo hasznalataban, es minden kornyezeti valtozo az "LC_" prefixszel kezdodik. nevek A tradicionalis es a POSIX bc -ben a funkciok, valtozok es tombok nevei csak egy karakter hosszuak lehettek. Itt mar tobb karaktert is hasznalhatunk, de a neveknek betuvel kell kezdodni es csak betuket szamokat es alahuzasjeleket tartalmazhatnak. Stringek A stringek nem tartalmazhatnak NUL (ASCII nulla) karaktert. A POSIX szerint barmilyen karakter lehet egy stringben. last A POSIX bc-ben nincs last valtozo. Nehany implementacio a pontot (.) hasznalja erre a celra. osszehasonlitasok A POSIX bc csak az if, vagy a while utasitasban enged meg osszehasonlitasokat, vagy a for utasitas masodik kifejezeseben. Tovabba, utasitasonkent csak egy relacios operator van megengedve. if utasitas, else ag A POSIX bc-ben nincs else ag. for utasitas A POSIX bc-ben minden kifejezesnek szerepelnie kell. &&, ||, ! A POSIX bc-ben nincsenek logikai operatorok. read fuggveny A POSIX bc-ben nincs read fuggveny. print utasitas A POSIX bc-ben nincs print utasitas. continue utasitas A POSIX bc-ben nincs continue utasitas. return utasitas POSIX bc requires parentheses around the return expression. tomb parameterek POSIX bc does not (currently) support array parameters in full. The POSIX grammar allows for arrays in function definitions, but does not provide a method to specify an array as an actual parameter. (This is most likely an oversight in the grammar.) Traditional implementations of bc have only call by value array parameters. function format POSIX bc requires the opening brace on the same line as the define key word and the auto statement on the next line. =+, =-, =*, =/, =%, =^ A POSIX bc-ben nincs szukseg ezekre a "regi stilusu" ertekado operatorokra. Ez a verzio megengedi ezeket. Hasznald a limits utasitast, hogy megtudd, hogy az installalt verzio megengedi-e ezeket. Ha igen, az "a =- 1" kifejezes csokkenti az a erteket 1-gyel, egyebkent pedig az a erteket beallitja -1-re. szokozok a szamokban A bc mas implementacioi megengedik szokozok hasznalatat a szamokban. Peldaul, az "x=1 3" kifejezes az x valtozohoz hozzarendeli a 13-at. Ebben a bc-ben ugyanez az utasitas szintaktikai hibat ad. hibak es vegrehajtas Ez az impelmentacio kulonbozik a tobbitol abban, hogy mely kodokat hajtja vegre, mikor egy szintaktikai, vagy mas hibaba belefut. Ha egy szintaktikai hibat talal a fuggveny definiciojaban, a hibakezelo megprobalja megtalalni az utasitas elejet, es folytatni a fuggveny feldolgozasat. Ha a szintaktikai hiba a fuggveny torzseben kovetkezik be, a fuggveny nem lesz definialva, es nem lehet meghivni sem. Az interaktiv vegrehajtasi blokkokban levo szintaktikai hibak ervenytelenitik az egesz blokkot. Egy vegrehajtasi blokknak minosul az az utasitassor, amely a kovetkezo soremelesig tart. Peldaul: a = 1 b = 2 ez ket vegrehajtasi blokk es { a = 1 b = 2 } ez egy. A futasi-hibak hatasara a jelenlegi blokk vegrehajtasa befejezodik. A futasi-figyelmezetetes nem allitja meg a blokk vegrehajtasat. Megszakitasok Egy interaktiv vegrehajtas soran, a SIGINT szignal (altalaban a terminalrol erkezo Control-C karakter generalja) hatasara a jelenlegi blokk vegrehajtasa megszakad. Kijelzesre kerul egy "futasi" hiba, hogy melyik fuggveny lett megszakitva. Miutan minden futasi struktura kiurul, egy uzenet kerul kiirasra a felhasznalo fele, hogy a bc kesz tovabbi adatok fogadasara. Minden korabban definialt fuggveny tovabbra is definialva marad, es minden nem-auto valtozoban a megszakitaskori ertek lesz. Minden auto valtozo (a fuggvenyek parameterei is) torlesre kerul a kiuritesi eljaras soran. Nem-interaktiv vegrehajtaskor a SIGINT szignal az egesz bc futasat megszakitja. HATAROK A kovetkezo hatarok vannak beepitve ebbe a bc -be. Nehanyuk egy installalassal megvaltoztathato. Az aktualis ertekeik megszerzesehez hasznald a limits utasitast. BC_BASE_MAX The maximum output base is at least 10^9. The maximum input base is 16. BC_DIM_MAX Ez a jelenlegi pontossagi hatar, 655535. Az on installaciojaban mas lehet. BC_SCALE_MAX The number of digits after the decimal point is limited to INT_MAX digits. Also, the number of digits before the decimal point is limited to INT_MAX digits. BC_STRING_MAX A karakterek maximalis szama egy stringben INT_MAX. exponens A hatvanyozas operator (^) kitevojenek maximum erteket a LONG_MAX hatarozza meg. valtozo nevek A jelenlegi limit az egyedi nevekre 32767 mind az egyszeru valtozokra, mind a tombokre es a fuggvenyekre. KORNYEZETI VALTOZOK The following environment variables are processed by bc: POSIXLY_CORRECT This is the same as the -s option. BC_ENV_ARGS This is another mechanism to get arguments to bc. The format is the same as the command line arguments. These arguments are processed first, so any files listed in the environment arguments are processed before any command line argument files. This allows the user to set up "standard" options and files to be processed at every invocation of bc. The files in the environment variables would typically contain function definitions for functions the user wants defined every time bc is run. BC_LINE_LENGTH This should be an integer specifying the number of characters in an output line for numbers. This includes the backslash and newline characters for long numbers. As an extension, the value of zero disables the multi-line feature. Any other value of this variable that is less than 3 sets the line length to 70. DIAGNOSZTIKA Ha egy a parancssorban szereplo fajl nem nyithato meg, a bc uzen, hogy a fajl nem elerheto, es kilep. Ugyanigy, a forditasi es a futasi ideju diagnosztika is onmagyarazo. HIBAK A hibakezeles meg nem tul jo. Email bug reports to bug-bc@gnu.org. Be sure to include the word "bc" somewhere in the "Subject:" field. SZERZO Philip A. Nelson philnelson@acm.org KOSZONETNYILVANITAS A szerzo szeretne megkoszonni Setve Sommars-nak (Steve.Sommars@att.com), hogy oly nagy mertekben segitett az implementacio teszteleseben. Sok nagyon jo tanacsot adott. Segitsegevel egy sokkal jobb termeket sikerult letrehozni. FORDITAS A kezikonyv magyar forditasat a Csehi Andras keszitette. Ez a forditas ingyenes dokumentacio; lasd a GNU General Public License 3 . Vagy ujabb verziojat a szerzoi jogi feltetelekkel kapcsolatban. Feltetelezzuk, hogy NEM FELELOSSEG. Ha hibat talal a kezikonyv oldal forditasaban, kuldje el a e-mail cim: TODO. <>. GNU Project 2025. januar 5 bc(1)