gexpr man page on DragonFly

Man page or keyword search:  
man Server   44335 pages
apropos Keyword Search (all sections)
Output format
DragonFly logo
[printable version]

GEXPR(1)							      GEXPR(1)

NAME
       gexpr - handy shell calculator

SYNOPSIS
       gexpr [ options ] expression

DESCRIPTION
       gexpr is an expression parser that can be used as a simple command-line
       calculator, as in gexpr 'sin(pi/4)*sqrt(4)', or to add  floating	 point
       math  to	 shell	scripts.  It  is meant to be an alternative to bc (1),
       being less powerful but lighter and much more intuitive. It  also  pro‐
       vides a few nice features of its own.

       If  an  expression  is given as argument, it must be protected from the
       shell using quotes as in the example above.  If	you  fail  to  do  so,
       parentheses will be interpreted and the * character will be expanded by
       the shell, wreaking havoc. Using double quotes " " is necessary if  you
       want to use shell variables within expression.

       gexpr  supports	the  usual arithmetical operators  + - * / , the rela‐
       tional operators	 < <= > >= == != , and all the standard C mathematical
       functions  apart	 from  frexp  (3)  and modf (3), which cannot be fully
       implemented since they actually return two values. In  addition,	 gexpr
       provides the constants defined in math.h (M_PI, etc), the fact(n) func‐
       tion, which returns the factorial of n, and the rnd(n) function,	 which
       returns a random number between 0 and n.

       A  nice	feature	 of gexpr is the possibility of using other bases than
       10. For instance, this expression is allowed:

       $ gexpr "0x10 + 0b1010 + 010"
       34
       $ _

       the prefix "0x" denotes numbers written in base	16,  "0b"  numbers  in
       base 2, and "0" octal numbers.

       The  command "base nn" is used to display the results in a base between
       2 and 16. Example:

       gexpr> base 16
       output base is now 16
       gexpr> 256 * 2
       200
       gexpr> _

       The command "decimals nn" (or "dec nn") specifies the number of decimal
       positions. Example:

       gexpr> PI
       3.1415926525
       gexpr> dec 20
       decimal positions now 20
       gexpr> PI
       3.14159265258979311740
       gexpr> _

COMMANDS
       base    specify the output base.

       dec(imals)
	       specify the number of decimals (default: 10).

       help    display a list of functions, constants, and commands.

       q(uit)  quit the program.

OPTIONS
       --help, -h
	       display a short help.

       --base n, -b n
	       output results in base n.

       --no_prompt, -n
	       don't display the gexpr> prompt.

EXAMPLES
       gexpr 2 + 10 / 2
       gexpr "sqrt(5) < log(10)"
       echo "sqrt(2)/2" | gexpr -n
       gexpr "sin($X) - tan($Y)"
       gexpr "$X + ($Y)*log10(${ZZ})"

       This is an interesting use of gexpr in a shell script:

       #!/bin/sh  DEC=`echo "M_PI_2" | gexpr -n` EXA=`echo "M_PI_2" | gexpr -n
       -b16` echo "Pi/2 is $DEC (or $EXA in hexa)"

       Another example:

       #!/bin/sh
       X=0
       while [ `gexpr "$X < 10"` = 1 ]
       do
	 X=`gexpr "$X + 0.2"`
	 echo $X
       done

BUGS
       It is awfully slow and its use cannot replace a "real" programming lan‐
       guage supporting floating point math.

       Most  errors  are  trapped  but some are not, like overflows and under‐
       flows. For example, on the Linux box it was written on gexpr  overflows
       when the result exceeds about 1.797e+308.

       It  would  be  nice  to add command-line editing. This would make gexpr
       quite bigger, though.

AUTHOR
       Guido Gonzato <ggonza@tin.it>

SEE ALSO
       expr (1), sh (1), bc (1)

GEXPR 2.0.2			   May 2001			      GEXPR(1)
[top]

List of man pages available for DragonFly

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net