Arithmetic Evaluation

   

Korn Shell: Unix and Linux Programming Manual, Third Edition, The
By Anatole Olczak

Table of Contents
Appendix E.  Korn Shell Man Page


The shell performs arithmetic evaluation for arithmetic substitution, to evaluate an arithmetic command, to evaluate an indexed array subscript, and to evaluate arguments to the builtin commands shift and let. Evaluations are performed using double precision floating point arithmetic. Floating point constants follow the ANSI-C programming language conventions. Integer constants are of the form [base#]n where base is a decimal number between two and sixty-four representing the arithmetic base and n is a number in that base. The digits above 9 are represented by the lower case letters, the upper case letters, @, and _ respectively. For bases less than or equal to 36, upper and lower case characters can be used interchangeably. If base is omitted, then base 10 is used.

An arithmetic expression uses the same syntax, precedence, and associativity of expression as the C language. All the C language operators that apply to floating point quantities can be used. In addition, when the value of an arithmetic variable or sub-expression can be represented as a long integer, all C language integer arithmetic operations can be performed. Variables can be referenced by name within an arithmetic expression without using the parameter expansion syntax. When a variable is referenced, its value is evaluated as an arithmetic expression.

The following math library functions can be used with an arithmetic expression:


abs acos asin atan cos cosh exp int log sin sinh sqrt tan tanh 

An internal representation of a variable as a double precision floating point can be specified with the -E [n] or -F [n] option of the typeset special built-in command. The -E option causes the expansion of the value to be represented using scientific notation when it is expanded. The optional option argument n defines the number of significant figures. The -F option causes the expansion to be represented as a floating decimal number when it is expanded. The optional option argument n defines the number of places after the decimal point in this case.

An internal integer representation of a variable can be specified with the -i [n] option of the typeset special built-in command. The optional option argument n specifies an arithmetic base to be used when expanding the variable. If you do not specify an arithmetic base, the first assignment to the variable determines the arithmetic base.

Arithmetic evaluation is performed on the value of each assignment to a variable with the -E, -F, or -i attribute. Assigning a floating point number to a variable whose type is an integer causes the fractional part to be truncated.


       
    Top
     



    Korn Shell. Unix and Linux Programming Manual, Third Edition
    Korn Shell. Unix and Linux Programming Manual, Third Edition
    ISBN: N/A
    EAN: N/A
    Year: 2000
    Pages: 177

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net