calc

Prev Next

Function Names

calc

Description

This function calculates the expression either formulated as direct code or provided in a string. The return value will be provided as calculated in the expression

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

1

Parameters

No.TypeDescription
1
code
expression
:string
expression to calculate

Return value

TypeDescription
all types Return value

It is the return value as provided by the specified expression

Examples

  ex[] = "sqrt( x[]*x[] + y[]*y[] )";
  x[] = 3;
  y[] = 4;

  r[] = calc( sqrt( x[]*x[] + y[]*y[] ) );
  echo("Output r[] = ", r[] );

  r[] = calc( : ex[] );
  echo("Output r[] = ", r[] );

  // Note the required colon.  Otherwise ex[] as variable is returned.

Output

Output r[] = 5
Output r[] = 5
Try it yourself: Open LIB_Function_calc.b4p in B4P_Examples.zip. Decompress before use.

See also

exec
compare [function]