WARNING: This server provides a static reference view of the NetKernel documentation. Links to dynamic content do not work. For the best experience we recommend you install NetKernel and view the documentation in the live system .

Endpoint
Name:Calculator Runtime
Description:Calculator Numeric Expression Runtime
Id:CalculatorRuntime
Category:accessor
Identifier Syntax

Calculator Runtime is an accessor using Active URI syntax with the following base identifiers:

Base
active:calculate

and the following arguments: (for more details on argument passing details see here)

ArgumentRulesTypingDescription
operator
Mandatory
Representation (java.lang.Object)expression to evaluate
varargs [varargs] Any quantityRepresentation (java.lang.Object)Varargs allows an arbitrary number of additional unspecified arguments.
Request Verbs

The following verb is supported:

Verb
SOURCE
Response

The following response representations can be returned for SOURCE requests:

SOURCE Representations
java.lang.Double

This accessor throws no documented exceptions.

Import Requirements

To use Calculator Runtime accessor you must import the module urn:org:netkernel:lang:math:

<import>
  <uri>urn:org:netkernel:lang:math</uri>
</import>

The active:calculate runtime evaluates numeric expressions and produces double-precision numeric results.

operator

The operator argument is a mathematical expression to be parsed and numerically evaluated. This must be transreptable to a String.

Example

100*10.60

Variable arguments

Any additional arguments will be sourced as java.lang.Double and will be provided as variables to the operator expression.

Example

Suppose you invoke the service with

active:calculate+operator@[ ... ] + x@[ ... ]

If the operator is

x^2-2*x+3

and the x argument is 1.0

the expression "1^2-2*1+3" is evaluated and the value 2.0 is returned.

Any number of named arguments may by supplied and referenced in the calculation expression.

Representation Model

The tool requires that all variable arguments are transreptable to java.lang.Double. The tool will return java.lang.Double representations.

Built-in Functions

This endpoint utilises the org.matheclipse.parser.client.eval.DoubleEvaluator and has the following built-in functions...

    check("42", "42.0");
    check("1.0E10", "1.0E10");
    check("1.0E-10", "1.0E-10");
    check("1.0E+10", "1.0E10");
    check("1.5", "1.5");
    check("-42", "-42.0");
    check("+42", "42.0");
    check("-42.1", "-42.1");
    check("+42.2", "42.2");
    check("-3/4", "-0.75");
    check("+3/4", "0.75");
    check("3^3", "27.0");
    check("2+2*2", "6.0");
    check("2^9", "512.0");
    check("2^3^2", "512.0");
    check("(2^3)^2", "64.0");
    check("3+4*7", "31.0");
    check("3+4*7*3", "87.0");
    check("1+2+3+4*7*3", "90.0");
    // calculate in Radians
    check("Sin[Cos[3.2]]", "-0.8405484252742996");
    // Pi / 2
    check("90.0*Degree", "1.5707963267948966");
    check("Pi/2", "1.5707963267948966");
    check("Sin[Pi/2*Cos[Pi]]", "-1.0");

    check("Max[0,-42,Pi,12]", "12.0");
    check("Min[0,-42,Pi,12]", "-42.0");
    check("If[3/4<0.51, 1.1, -1.2]", "-1.2");
    check("If[True, 1.1, -1.2]", "1.1");
    check("If[3/4>0.51 && 3/8>0.1, 1.1, -1.2]", "1.1");
    check("If[3/4>0.51 || 3/8>0.1, 1.1, -1.2]", "1.1");
    check("If[!(3/4>0.51 || 3/8>0.1), 1.1, -1.2]", "-1.2");
    
    //check("Rand[]", "Random Double between 0.0 and 1.0");
  }