# Variable calculations should be done in this file.
# It is read and interpreted by wims for all valid calls to the module.

nextstep=$[min($laststep+1,$steplim)]
!bound step between integer 0 and $nextstep default $nextstep
!bound prec between integer 3 and 1000 default 20

chartest=$[floor(abs($char))]
!if NaN isin $chartest or Inf isin $chartest
 char=0
!endif
!if $char>0
 methd=x$$s=Mod(lift($$l),$char,1); print(lift(x$$s))
!else
 methd=x$$s=$$l; print(x$$s)
!endif

wims_rawmath_variables=$varlist
wims_rawmath_functions=binomial intnum polroots zeta theta gamma\
	eint1 besselk besseljh erf erfc bernreal bernfrac\
	gcd lcm sum suminf prod prodinf\
	bestappr
!read pari.hd

formula=!translate '";: to $    $ in $formula
formula=!rawmath $formula
formula=!trim $formula
!if $formula!=$empty or $recomp!=$empty
 !if $recomp=cut
  laststep=$[max(0,$step-1)]
  nextstep=$[$laststep+1]
  step=0
 !endif
 !distribute item ,yes, into error,compute,gpsrc
 !for s=1 to $[max($laststep,$step)]
  !if $s=$step
   l=$formula
   !if $s<=$laststep
    history=!replace line number $s by $l in $history
   !endif
  !else
   l=!line $s of $history
  !endif
  gpsrc=!append line $methd to $gpsrc
 !next s
 pari_precision=$prec
 value=!exec pari $gpsrc
 value=!replace + 0.0\*I by $ in $value
 result=!replace I by $ i in $value
 
 !if $step>$laststep
  history=!line 1 to $laststep of $history
  history=!append line $formula to $history
  !advance laststep
  !advance nextstep
 !endif
 !if $formula!=$empty
  wims_module_log=$step/$laststep|$char: $formula
 !endif
!endif

