Skip to content

Commit

Permalink
Modify docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Edd12321 committed Dec 1, 2023
1 parent 71206d3 commit 23564c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
23 changes: 8 additions & 15 deletions doc/man1/expr.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
.SH NAME
expr \- Evaluate expressions
.SH SYNOPSIS
.BI "expr [" -r "] [" EXPRESSION ]
.BI "expr [" EXPRESSION ]
.SH DESCRIPTION
This builtin concatenates all of its arguments into one arithmetic expression, evaluates it and returns its value. All of these functions/operators can also be found in other languages, such as C or Python. Remember to escape certain symbols when necessary, so they don't conflict with Zrc constructs (globbing, tilde expansion, redirection, etc.)
.PP
Note that this command actually returns a value, as opposted to POSIX
.I expr
which writes to stdout, so square brackets should be used to access it.
which writes to stdout, so square brackets should be used to access it. NOTE that the interpreter obviously has no idea if you want to bit shift or redirect, so if you use bit manipulation operators, remember to
.I brace your expr-essions
to not clobber files. (and other obvious reasons, like double substitution. See the Tcler's Wiki, it all applies to Zrc too :-) )
.SS Precedence level 0
.RB ( , ) ;
.SS Precedence level 1 (ternary operator)
Expand All @@ -34,31 +36,22 @@ which writes to stdout, so square brackets should be used to access it.
.SS Precedence level 11
.RB + , - ;
.SS Precedence level 12
.RB * , / , // , % ;
.RB * , / , ** , // , % ;
.SS Precedence level 13: implicit
.SS Functions
.RB log10 , log2 , ln / log , sqrt , sin , asin / arcsin , cos , acos / arccos , ctg / cot , actg / acot / arcctg / arccot , tg / tan , atg / atan / arctg / arctan , sec , arcsec / asec , csc / cosec , acsc / acosec / arccsc / arccosec / floor , ceil , abs , round , trunc;
.SS Other words
.RB nan , false , true ;
.SS Unary operators
.RB - , + , ~ .
.SH OPTIONS
.TP
.BR r
Evaluate args as a
.B reverse polish notation
expression (RPN), instead of an
.B infix notation
expression. NOTE that in this mode, whitespace is required, so if you use bit manipulation operators, remember to
.I brace your expr-essions
to not clobber files. (and other obvious reasons, like double substitution. See the Tcler's Wiki, it all applies to Zrc too :-) )
.RB - , + , ~ , ! .
.SH EXAMPLES
.EX
echo [expr 1+2/(100**3+log(4))//2+sin 2+cos(floor(ceil(-8.7)))]
echo [expr 1&&2||(1?2:0)+5&(3<<1)]
echo [expr 1 + 2/ 3 + 4]
# RPN expressions used to be supported, but now they have been removed.
# RPN expressions used to be supported, but now they have been removed due to a new reimplementation using a proper BNF.
# They may return in a future version, but the standard mathop.zrc already provides similar functionality...
echo [expr -r {1 2 + 3 '*' 2 '<<'}]
echo [expr {((1+2)*3)<<2}]
Expand Down
2 changes: 1 addition & 1 deletion doc/man1/zrc.1
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ Replace the current shell process.
.br
Exit Zrc.
.HP
.BI "expr [" -r "] [" EXPRESSION ]
.BI "expr [" EXPRESSION ]
.br
Evaluate arithmetic expressions.
.HP
Expand Down

0 comments on commit 23564c7

Please sign in to comment.