MAD-X icon indicating copy to clipboard operation
MAD-X copied to clipboard

Inconsistent treatment of +-

Open bjlindst opened this issue 2 years ago • 3 comments

The way that MAD-X currently treats expressions with "+-" in them is inconsistent, which I think can be a bit confusing. It can also easily lead to bugs in scripts.

For example:

var = 5; var = (2+-1); value,var; 1

With brackets around the expression containing the +-, the calculation is performed as expected and the value is updated.

var = 5; var = 2+-1; ++++++ warning: illegal expression set to 0 in: var = 2 + - 1 value,var; 5

Here a warning is printed, and the original value of the variable is retained. I would expect it to be updated and set to 1.

mq: multipole, knl={0, 0.00005+-0.00004}; +=+=+= fatal: illegal format near: :

In this case you get a fatal error and the program exits.

To make the code more user friendly, I would suggest that expressions of the type a+-b are always interpreted as a-b. The +- can easily appear in automated scripts where a running variable can be negative. This can also make it difficult to spot since it might not appear when testing a new script.

bjlindst avatar Mar 16 '22 17:03 bjlindst