You are here: Lua Scripting Resources eGuide > Lua Scripting API Reference Guide > Math Library Extension > evalStr

12.2 evalStr

math.evalStr(math_expression)

This function sends an expression or command to the TI-Nspire™ math server for evaluation. 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 overridden by math.setEvalSettings. NOTE: All evaluations are performed at full precision regardless of the document settings or overrides.

If the math server evaluates the expression successfully, it returns the results as a string. The evalStr function returns no result if the math server does not return a calculated result. If the math server cannot evaluate the expression because of a syntax, simplification, or semantic error, evalStr returns two results: nil and an error number meaningful to the math server.

Scientific Notation

The evaluation of “10.220” (document settings in auto mode) returns the following result: 1.4859473959784 20. A closer look at the result string reveals the box character as “\239\128\128”, which is the Unicode character U+F000 – a small
capital letter “E” used inside TI-Nspire™ software for the E notation.

Listing 12.2: math.evalStr() Returning Result in E Notation

result, error = math.evalStr('10.2^20')
firstFive = table.concat({string.byte(result, 1, 5)}, ' ')
lastFive = table.concat({string.byte(result, 15, 20)}, ' ') print (result, ':', firstFive, '...', lastFive)

Listing 12.2 prints:

1.4859473959784 20 : 49 46 52 56 53 ... 52 239 128 128 50 48


Nagative numbers

The evaluation of “2-3” returns “-1”. The result string will be encoded as
\226\136\146\49”. “\226\136\146” is Unicode character U+2212, which is a minus
sign.

Listing 12.3: math.evalStr() Returning Negative Numbers

result, error = math.evalStr('2-3')
print (result, ':', string.byte(result, 1, 10))

Listing 12.3 prints:

-1 : 226 136 146 498

Introduced in platform.apiLevel = '2.0'