Scrigroup - Documente si articole

     

HomeDocumenteUploadResurseAlte limbi doc
AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows
WordXml

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

bc linux command

linux



+ Font mai mare | - Font mai mic



bc

bc [options] [files]



bc is a language (and compiler) whose syntax resembles that of C, but with unlimited-precision arithmetic. bc consists of identifiers, keywords, and symbols, which are briefly described in the following entries. Examples are given at the end.

Interactively perform arbitrary-precision arithmetic or convert numbers from one base to another. Input can be taken from files or read from the standard input. To exit, type quit or EOF.

Options

-l, --mathlib

Make functions from the math library available.

-s, --standard

Ignore all extensions, and process exactly as in POSIX.

-w, --warn

When extensions to POSIX bc are used, print a warning.

-q, --quiet

Do not display welcome message.

-v, --version

Print version number.

Identifiers

An identifier is a series of one or more characters. It must begin with a lowercase letter but may also contain digits and underscores. No uppercase letters are allowed. Identifiers are used as names for variables, arrays, and functions. Variables normally store arbitrary-precision numbers. Within the same program you may name a variable, an array, and a function using the same letter. The following identifiers would not conflict:

x

Variable x.

x i

Element i of array x. i can range from 0 to 2047 and can also be an expression.

x y z

Call function x with parameters y and z.

Input-output keywords

ibase, obase, scale, and last store a value. Typing them on a line by themselves displays their current value. You can also change their values through assignment. The letters A-F are treated as digits whose values are 10-15.

ibase = n

Numbers that are input (e.g., typed) are read as base n (default is 10).

obase = n

Numbers that are displayed are in base n (default is 10). Note: Once ibase has been changed from 10, use A to restore ibase or obase to decimal.

scale = n

Display computations using n decimal places (default is 0, meaning that results are truncated to integers). scale is normally used only for base-10 computations.

last

Value of last printed number.

Statement keywords

A semicolon or a newline separates one statement from another. Curly braces are needed when grouping multiple statements.

if (rel-expr) [else ]

Do one or more statements if relational expression rel-expr is true. Otherwise, do nothing, or if else (an extension) is specified, do alternative statements. For example:

if(x==y) else

while (rel-expr

Repeat one or more statements while rel-expr is true; for example:

while(i>0)

for (expr1 rel-expr expr2

Similar to while; for example, to print the first 10 multiples of 5, you could type:

for(i=1; i<=10; i++) i*5

GNU bf does not require three arguments to for. A missing argument 1 or 3 means that those expressions will never be evaluated. A missing argument 2 evaluates to the value 1.

break

Terminate a while or for statement.

print list

GNU extension. It provides an alternate means of output. list consists of a series of comma-separated strings and expressions; print displays these entities in the order of the list. It does not print a newline when it terminates. Expressions are evaluated, printed, and assigned to the special variable last. Strings (which may contain special characters, i.e., characters beginning with ) are simply printed. Special characters can be:

a

Alert or bell

b

Backspace

f

Form feed

n

Newline

r

Carriage return

q

Double quote

t

Tab

Backslash

continue

GNU extension. When within a for statement, jump to the next iteration.

halt

GNU extension. Cause the bc processor to quit.

limits

GNU extension. Print the limits enforced by the local version of bc.

Function keywords

define f args

auto x y

Set up x and y as variables local to a function definition, initialized to 0 and meaningless outside the function. Must appear first.

return(expr

Pass the value of expression expr back to the program. Return 0 if (expr) is left off. Used in function definitions.

sqrt(expr

Compute the square root of expression expr.

length(expr

Compute how many significant digits are in expr.

scale(expr

Same as length, but count only digits to the right of the decimal point.

read( )

GNU extension. Read a number from standard input. Return value is the number read, converted via the value of ibase.

Math library functions

These are available when bc is invoked with -l. Library functions set scale to 20.

s(angle

Compute the sine of angle, a constant or expression in radians.

c(angle

Compute the cosine of angle, a constant or expression in radians.

a(n

Compute the arctangent of n, returning an angle in radians.

e(expr

Compute e to the power of expr.

l(expr

Compute the natural log of expr.

j(n x

Compute the Bessel function of integer order n.

Operators

These consist of operators and other symbols. Operators can be arithmetic, unary, assignment, or relational:

arithmetic

unary

assignment

relational

< <= > >= == !=

Other symbols

Enclose comments.

Control the evaluation of expressions (change precedence). Can also be used around assignment statements to force the result to print.

Use to group statements.

Indicate array index.

text

Use as a statement to print text.

Examples

Note in these examples that when you type some quantity (a number or expression), it is evaluated and printed, but assignment statements produce no display.

ibase = 8 Octal input
Evaluate this octal number
Terminal displays decimal value
obase = 2 Display output in base 2 instead of base 10
Octal input
Terminal now displays binary value
ibase = A Restore base-10 input
scale = 3 Truncate results to 3 decimal places
Evaluate a division
Oops! Forgot to reset output base to 10
obase=10 Input is decimal now, so A isn't needed

Terminal displays result (truncated)

The following lines show the use of functions:

define p(r,n) Value returned

scale=5
x=p(2.5,2) x = 2.5 ^ 2
x Print value of x

length(x) Number of digits

scale(x) Number of places right of decimal point



Politica de confidentialitate | Termeni si conditii de utilizare



DISTRIBUIE DOCUMENTUL

Comentarii


Vizualizari: 866
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved