uspTukubaiコマンドに関する様々な資料がここにあります。

 

 

魂内検索

DOCUMENTS

COMMAND

FORUM

UEC DOCS

VIDEO

 

Alphabetical list

(Video materials in preparation)

lcalc(USP)

Name

lcalc : Perform high precision decimal fixed-point calculation

(18 integer digits + 18 fraction digits)

Synopsis

Usage   : lcalc <script> <files>...

Option  : --divzero[=<string>]

          --overflow[=<string>]

          --outdomain[=<string>]

          -d

Version : Tue Jan  9 09:02:34 JST 2024

Edition : 1

Description

Performs a mathematical calculation as described in <script> on

each field of the specified file or standard input.  In <script>,

you can specify expressions, fields and field ranges by themselves

or several separated by commas.

The mathematical calculations are carried out with 36-digit

precision (18 integer digits and 18 fraction digits).  Within the

expressions you can use constants, pseudo variables (NF: Number of

Fields, NR: Number of Records), intrinsic functions (round()

roundup() rounddown() ceil() floor() sqrt()), unary operators (- ! $),

binary operators (+ - * / % **), unary operators (- ! $), logical AND

(&&), logical OR (||), conditional operator (?:) and parentheses.

You can use ^ instead of the power operator **.

The "$" operator represents the field that was input.  Operands are

truncated to integers.  The truncated result must be within the

range 0 to NF.  "$0" stands for whole line.

The rounding functions (round() roundup() and rounddown()) round

the first argument to the precision specified in the second argument.

The second argument must be an integer constant.  If the second

argument starts with zero, rounding is performed on the integer part,

if it begins with anything other than zero, rounding is performed on

the fraction part.  For example: rounddown(123.456, 01) returns

120.000, rounddown(123.456, 1) returns 123.400.

The ceil function ceil() and the floor function floor() returns

minimum/maximum number greater/less than its argument, respectively.

The square root function sqrt() returns square root of its argument.

The absolute function abs() returns the absolute value of its

argument.

The sign function sign() returns 1/0/-1 according to the sign of

its argument.

The output format of the expression is "Integer_Part.Fraction_Part".

The integer part is displayed to the necessary number of digits (1

~ 18) but the fraction part is always displayed to 18 digits.

However, when the result of the calculation is an integer, then no

decimal point nor fraction digits are displayed.

Fields have $<expression> format and indicate the input field.  The

difference with the $ operator is whether or not it is resolved to a

number.  For example, if the script is "$1, ($2)" and the input is:

123.456 123.456

Then the output is:

123.456 123.456000000000000000

A range of fields can be specified using the format $[<expr>:<expr>]

which represents multiple contiguous input fields.  <expr>s must be

within the range 1 to NF.

You can have as much whitespace (including linefeeds) in between the

elements of the script.

Everything starting with "#" up until the end of the line is a

comment.  Comments can be placed anywhere whitespace can be placed.

For division and modulo, if the right operand is zero then the

result of the calculation is zero.  If you specify the --divzero

option, the expression containing that operation is discarded and

the text string specified in the option is output.  If you omit the

text string in the --overflow option, the string "div/0" is output

by default.

If overflow occurs in an expression, execution of lcalc is aborted.

If you specify the --overflow option, the calculation of the

expression is aborted, the text string specified in the option is

output, and execution of lcalc is continued.  If you omit the text

string in the --overflow option, the string "ovflw" is output by

default.

If the argument of the square root function or the operand of the

power operator is invalid, execution of lcalc is aborted.  If you

specify the --outdomain option, the calculation of the expression is

aborted, the text string specified in the option is output, and

execution of lcalc is continued.  If you omit the text string in the

--overflow option, the string "outdm" is output by default.

If you specify the -d option, the file is not read and the script is

executed directly.  In this case, you cannot specify the $ operator,

fields or ranges of fields.

Example 1

Normal Usage

$ cat data

01 Massachusetts 91 59 20 76 54.1

01 Massachusetts 46 39  8 5 21.2

01 Massachusetts 82  0 23 84 10.3

02 New_York      30 50 71 36 30.4

02 New_York      58 71 20 10  6.5

04 Pennsylvania  92 56 83 96 75.6

$ lcalc '$1, $2, $3 / $4 + $5 * $6' data

01 Massachusetts 1521.542372881355932203

01 Massachusetts 41.179487179487179487

01 Massachusetts 1932

02 New_York 2556.600000000000000000

02 New_York 200.816901408450704225

04 Pennsylvania 7969.642857142857142857

Example 2

Calculator Usage

$ lcalc -d '1.23 * 3.45 / 3'

1.414500000000000000