SET (/A) Command (floating point)

The SET /A commande enables the value of an arithmetical expression to be stored into a variable.

This manual pages is only about the use of the /A of the SET command and the use of floating point numbers. To learn more about the general use of the command, please see the SET manual page.

Synopsis

SET [/a | /a[:]f] variable=expression

Computes the value of the arithmetical expression expression and stores it into variable. The behaviour of the command depends on the EnableFloats setting of the SETLOCAL command.

The = sign can be replaced by one of the following operator:

Operators

The arithmetical expression has to be made of combination of the following operators and operands.

Binary operators available with floating point arithmetics are:

Multiplication and division have precedence over addition and subtration. Precedence rules can be overridden using parenthesis.

Only one unary operator is available with floating point arithmetics:

Unary operators have highest precedence.

Mathematical function

In addition to operators, expression may contain mathematical function. To use such a function use the name of it followed by its arguments enclosed in parenthesis :

function(expression)

Available functions are:

Constants

Finally, the following constants are defined

Special numbers

Special numbers are values that are not numbers but are considered as so. The values have been defined by IEEE standard, but Dos9 only support two of them:

Precisness

As opposed to integers, wich are usually bound between -2 147 483 648 and +2 147 483 647, floating point numbers offer a much greater range, between4 2,2250738585072014e-308 à 1,7976931348623157e+308. However, this gain on range causes a loss of precision because of approached computing.

Bugs

It is not unusual to encounter preciseness bug as floating point number have a finite precision of about 15 decimal places. As a result some expression may be subject to approximation errors when dealing with numbers several orders of magnitude away from one another. Here is an example:

(2*10^60+1)-2*10^60)

Computing this expression using floating points arithmetics will lead to a precision error as the result would be 0 even though it is clearly 1. This happen because 10^60 is several orders of magnitude greater that 1. Changing slightly the expression can fix this issue :

2*10^60-2*10^60+1

Another problem may be comparing two results of floating point computing, as approximations may lead to a slightly different values even though they are equal from a mathematical point of view. To fix this kind of bugs, use the FEQ comparison from the IF command.

Notes

This command uses a modified version of the GNU libmatheval library.

Compatibility

Available since 0.7.1.0, before the support of expressions was incomplete, supporting neither the % operating system nor functions.

Not compatible with cmd.exe that does not support floating point arithmetics.

See also

SET Command, SET (/a) Command (integers)