math.evalStr

From Inspired-Lua Wiki
Jump to: navigation, search

math.eval is a math library extension.

This has been introduced in TI-Nspire OS 3.2 (Changes).


The function calls the math server with the specified arguments and returns the result if possible, as a string.

This function sends an expression or command to the TI-Nspire math server for eval-uation. The input expression must be a string that the TI-Nspire math server can interpret and evaluate. The evaluation is performed using the current document settings, which can be overriden by math.setEvalSettings. NOTE: All evaluations are performed at full precision regardless of the document settings or overrides.

Beginning with platform.apiLevel = '2.0' (OS 3.2), the evaluation is performed using the current document settings, except that all evaluations are performed at full precision in approximate mode. The current document settings can be overriden by math.setEvalSettings.
If the math server evaluates the expression successfully, it returns the results as a fundamental Lua data type.
If the math server cannot evaluate the expression because of a syntax, simplification, or semantic error, eval returns two results: nil and an error number meaningful to the math server. (The error numbers are documented in the TI-Nspire Reference Guide - Error Codes and Messages for math.eval.)
If the math server calculates a symbolic result, it cannot be represented as a fundamental Lua type, so eval returns nil and the string "incompatible data type."


Example : To evaluate f1 for a given value in x, the parameter x must be converted to a string, and then any embedded "e" must be replaced with Unicode character U+F000.

local mx = tostring(x):gsub("e", string.uhar(0xF000))
local expr = "f1(" .. mx .. ")"
return math.evalStr(expr)


Syntax[edit]

math.evalStr(expression)
evaluates "expression" (can contain TI-Basic arguments) and returns a result if possible, as a string.

Expression can contain everything a TI-Basic function can contain. You can seperate statements using ":".
It can also contain calls to user defined functions in the document, or functions in global libraries.


Example[edit]

math.evalStr("sqrt(16)") -- returns "4"


See also[edit]

math.eval