Math Statements

Math statements enable you to perform basic math operations on data in your NBC programs. Unlike high level programming languages where mathematical expressions use standard math operators (such as *, -, +, /), in NBC, as with other assembly languages, math operations are expressed as statements with the math operation name coming first, followed by the arguments to the operation. Nearly all the statements in this family have one output argument and two input arguments. The exceptions include sqrt (square root), neg (negate), abs (absolute value), and sign statements, which are unary statements having a single input argument.

Math statements in NBC differ from traditional assembly math statements because many of the operations can handle arguments of scalar, array, and struct types rather than only scalar types. If, for example, you multiply an array by a scalar then each of the elements in the resulting array will be the corresponding element in the original array multiplied by the scalar value.

Only the abs (absolute value) and sign statements require that their arguments are scalar types. When using the standard NXT firmware these two statements are implemented by the compiler since the firmware does not have built-in support for them. If you install the enhanced NBC/NXC firmware and tell the compiler to target it using the -EF command line switch then these statements will be handled directly by the firmware itself rather than by the compiler.

This family of statements also includes several math operations that are supported only by the enhanced NBC/NXC firmware. These statements cannot be used at all if you tell the compiler to generate code for the standard NXT firmware. The enhanced NBC/NXC firmware math statements are mostly unary functions with a single input argument and a single output argument. They are sin, cos, tan, sind, cosd, tand, asin, acos, atan, asind, acosd, atand, sinh, cosh, tanh, sinhd, coshd, tanhd, ceil, floor, trunc, frac, exp, log, and log10. There are three enhanced firmware math statements which take two input arguments: pow, atan2, and atan2d. And the muldiv statement takes three input arguments.

Generated by 1.6.2