Home
Name Modified Size InfoDownloads / Week
fzcal-0.0.5_1.tar.xz 2014-09-14 56.6 kB
fzcal-0.0.5.tar.xz 2014-09-14 53.4 kB
README 2014-09-14 8.9 kB
fzcal-0.0.4.tar.xz 2013-08-18 55.7 kB
libfzcal-0.0.3-Linux2.6.28-arm.tar.bz2 2012-02-27 2.9 MB
fzcal-0.0.3.tar.bz2 2012-02-26 71.2 kB
fzcal-0.0.2.tar.bz2 2012-01-23 62.9 kB
fzcal-0.0.1.tar.bz2 2011-12-06 33.5 kB
fzcal-0.0.0.tar.bz2 2011-10-12 30.8 kB
Totals: 9 Items   3.2 MB 0
fzcal v0.0.5_1 - a calculator capable of complex arithmetics

THIS IS ALPHA VERSION:

There can be number of errors in the code and things might be changed
in the later version.


** build **

Type "make" (or "pmake" for Linux users). Rules are all written in a
single "Makefile", which might need to be checked for your
environment. The binary "fzcalc.bin" is a command line calculator but
has no line-edit functionality and use of "rlwrap" is recommended.
"fzcalc" is a wrapper script to process piped input for "fzcalc.bin".


** Usage **

Type "fzcalc.bin -h" to print brief ussage info.


** Valid expressions **

These are examples of valid expressions:

  (1+2)(3+4)/(5+6
  4atan(1
  1/2pi
  sin(pi/4)cos(pi/4
  a=1;b=2;d=a+b
  1+exp(pi i
  1/-2
  1.23e-4
  100_M
  sin (pi
  2 2 2

As you can see in the above examples, parenthesis need not be closed
and omission of multiplication operator is supported. The implicit
multiplications always have higher priority than ordinary one, that
is, 
  
  1/2pi=1/(2*pi)
 
  Numbers can have SI prefix with leading "_", which includes
"yzafpnum" and "kMGTPEZY". Note that 1_k=1000 by default but if in a
"byte" mode it will be 1024.
  In some cases space is significant; the last example equals to 2*2*2
and "sin (pi" is read as a parameter "sin" multiplied by "pi" and
returns error if the parameter "sin" is undefined. 
  If undefined parameters are used in the macro or function assignment
it will be automatically defined and initialized to 0.


** Operators **

In the following table operators are listed according to
presidencies, lowest to highest.

=, +=, -=, *=, /=
  assignment 
?:
  conditional
or, and, eq, neq, not, ~
  logical
==, ~=, >, <, >=, <=
  relational
+, -
  add, sub
*, /
  mul, div 
&P, &C
  permutation, combination
+, -
  plus, minus
!, !!, !_
  factorial, double factorial, multi-factorial
++, --
  inc, dec(no difference between ++a and a++)
**, ^, //
  pow, invpow; a//b=a^(1/b)
@x
  read input from stdin for x
;, ;;
  separates statements. more than one ; will print the result.
v:n
  in data mode, input value "v" with weight "n" .

For example, 

  -3! = -(3!)
  2**3++ = 8++
  2**3! = 8!
  -2**3 = -(2**3)
  ++2! = 3!
    

** Intrinsic functions **

Some of special functions are still under construction and may not
work properly.

ran()	     random number in the range [0,1)
sin(z)	     sine
cos(z)	     cosine
tan(z)	     tangent
sinh(z)	     hyperbolic sine
cosh(z)	     hyperbolic cosine
tanh(z)	     hyperbolic tangent
asin(z)	     inverse of sin
acos(z)	     inverse of cos
atan(z)	     inverse of tan
asinh(z)     inverse of sinh
acosh(z)     inverse of cosh
atanh(z)     inverse of tanh
exp(z)	     exponential
log(z)	     logarithm of base 10
ln(z)	     natural logarithm
sqrt(z)	     square root
cbrt(z)	     cubic root
abs(z)	     absolute value
int(x)	     integer part
frac(x)	     fractional part
conjg(z)     complex conjugate
nint(x)	     nearest integer
re(z)	     real part
im(z)	     imaginary part
mag(z)	     magnitude
arg(z)	     argument
gamma(z)     Gamma function
lgamma(z)    principal value of logarithm of Gamma function
psy(z)	     psy function
mod(n,m)     modulas of n for m
gami(z,z)    incomplete Gamma function
jn(x,z)	     spherical Bessel function
yn(x,z)	     spherical Bessel function
hn(x,z)	     spherical Hankel function
djn(x,z)     derivative of jn
dyn(x,z)     derivative of yn
dhn(x,z)     derivative of hn
Fl(x,x,x)    regular Coulomb wave function
Gl(x,x,x)    irregular Coulomb wave function 
Hl(x,x,x)    Gl + i Fl
dFl(x,x,x)   derivative of Fl
dGl(x,x,x)   derivative of Gl
dHl(x,x,x)   derivative of Hl
min(x,...)   minimum value
max(x,...)   maximum value
sum(z,...)   summation
ave(z,...)   average
var(z,...)   variance
uvar(z,...)  unbiased variance
sum2(z,...)  squared summation


** Intrinsic parameters **

These are all read-only and assigning a parameter with the same names
as these is not allowed except "c".

tmp	     internal use.
ans	     the answer of the last eval
eps	     machine precision
huge	     the largest number 
i	     imaginary unit
pi	     pi
c	     speed of light in m/s


** User-defined Function **

For example, 

  mysin(z)=(exp(i*z)-exp(-i*z))/2i 

defines a new function "mysin". 
  If you define a function with the same name as intrinsic ones, yours
are called.
  Semicolons in between quotation marks work as the separators;

  yoursin(z)="a=i*z;b=-a;(exp(a)-exp(b))/2i"


** Using macros **

This example,

  myownsin="@z;sin(z)-mysin(z)"

first prompt for variable "z" and then calculates
"sin(z)-mysin(z)". Just typing "myownsin" will invoke the macro.  
  If there exists a parameter with the same name as macros the macro
is called.
  In macro execution, operation and display modes etc. are local.

  sum10=".dat;1;2;3;4;5;6;7;8;9;10;.sta;.fig;sum"
  sum10

will print 55 and succeeding

  sum

will return error for not in the statistic mode and ".print data" will
print nothing, however, if the macro is invoked with "$", it will be
literally interpreted and

  $sum10
  sum
  .print data

will print no error.


** Numerical integration **

fzcal performs numerical integration by utilizing double exponential
formula. The syntax is,

  deint_x(f(x),a,b)

where "x" is a dummy argument of integrand "f", and "a" and "b" are
the lower and upper bound, respectively. If the "_x" was omitted "X"
is assumed to be a dummy argument. In the integrand you can use
two other arguments, "x_lo" and "x_up" as well as "x", where
"x_lo=x-a" and "x_up=b-x", respectively.
  When the integrand has singularity at the boundary, use of "x_lo"
and "x_up" can avoid loss of precision.
For example, 

  pi-deint_x(1/sqrt(1-x**2),-1,1)

returns 3.55e-17, while

  pi-deint_x(1/sqrt(x_lo*x_up),-1,1)

returns 0. 
  Note that "a" and "b" must be real while "f(x)" can be of complex.
  Since "x_lo" and "x_up" are only recognized in the 1st argument of "deint",
something like,

  f(x)=1/sqrt(x_lo*x_up)
  deint_x(f(x),-1,1)

will not work at all, however, macro expansion will work fine,

  m="1/sqrt(x_lo*x_up)"
  deint_x($m,-1,1)

Note that semi-colon separator cannot be used in the 1st argument of "deint".


** Data and statistics mode **

The commands .dat and .sta start the data and statistics mode,
respectively. In the data mode the answer of each calculation is
stored, whose statistical values can be obtained as variables such
as "sum" or "ave" in the statistics mode.
The following example will print "55";

  .cle
  .dat
  1;2;3;4;5;6;7;8;9;10
  .sta
  sum

 
** Commands **

fzcal supports all the commands described below.
libfzcal accepts some of them.

.q, .quit
  exit

.deg, .rad
  angles are in degree/radian

.fig
  sets display mode to ordinary expression

.exp 8
  sets display mode to scientific notation with 8 digits

.fix 8
  sets display mode to fixed point with 8 digit

.eng 8
  sets display mode to engineering notation with 8 digit

.bin, .oct, .dec, .hex
  sets display mode of integers

.Bin, .Oct, .Dec, .Hex
  sets base for input

.BIN, .OCT, .DEC, .HEX
  sets base for both input and output. 

.data, .dat
  to data input mode

.cle
  clear data in the data mode

.stat, .sta
  to statistics mode

.norm, .n
  to normal mode

.loads file
  reads a file

.del {func|mac|par} name
  deletes a function, macro or parameter.

.pp, .pm, .pf, .pd
  prints parameters, macros, functions or data

and more


** Using library **

The library "libfzcal" comes with C and fortran interface, "fzc.h" and
"fzc.f90", respectively, but has not support all the functionality of
the "fzcal" yet.

The following example illustrates how to calculate "a+b", where "a" 
and "b" are double variables in the main function.

#include <stdio.h>
#include <string.h>
#include <fzc.h>

void main()
{
  size_t pfzc;
  int rc;
  char str[LEN_FZCSTR_MAX];
  size_t pstr;
  double a,b;

  pfzc=fzc_init();
  pstr=(size_t)&str;

  strcpy(str,"a");
  fzc_regpar ( pfzc, (size_t)&a, pstr, FZCPK_DBLE );

  strcpy(str,"b");
  fzc_regpar ( pfzc, (size_t)&b, pstr, FZCPK_DBLE );

  a=1; b=2;
  strcpy(str,"a+b");    
  rc=fzc_setparse_formula ( pfzc, pstr );

  if ( rc>0 ){
    printf ( "Syntax Error\n" );
  }else if ( rc<0 ){
    // nothing to eval when function/macro/parameter 
    // is defined.
    printf ( "ok\n" ); 
  }else{
    rc = fzc_eval ( pfzc );
    if ( rc==0 ){
      fzc_get_strans ( pfzc, pstr );
      printf ( "%s\n", str);
    }else if( rc<0 ){
      // no anser returns when command is executed
      printf ( "ok\n" );
    }else{
      printf ( "Eval Error\n" );		
    }
  } 
}

Note that "a" and "b" are passed by reference to "libfzcal", but their
values are read on the call of "fzc_setparse_formula" and after that, 
changing "a" or "b" will have no effect on the result of "fzc_eval".


** Contacts **

All reports and requests are welcome to
http://sourceforge.net/projects/fzcal/
E-Mail: elseifkk@gmail.com
Source: README, updated 2014-09-14