must use brackets with minus

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

must use brackets with minus

Lars Damgaard
Hi,
I had some problems with the minus sign. If I make this macro

macro "minustest" {
line="20,30,40,50,60"
vars=split(line,",");
a=vars[0];
b=vars[1];
c= b-a;
print(c);
}

I get the error: "Statement cannot begin with '-' in line 6. no_of_pics = end_pic <-> start_pic + 1;"
However, it works as intended if I put parentheses around the two variables on the right side of line 6 like this:

macro "minustest" {
line="20,30,40,50,60"
vars=split(line,",");
a=vars[0];
b=vars[1];
c= (b)-(a);
print(c);
}

Is this a bug or am I misunderstanding something?

Best, Lars

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: must use brackets with minus

Gabriel Landini
On Friday 13 Jun 2014 08:08:15 Lars Damgaard wrote:
> vars=split(line,",");
> a=vars[0];
> b=vars[1];
> c= b-a;

Aren't you trying to subtract two strings?
Perhaps you need to parse the string to a number.

parseFloat(string)
Converts the string argument to a number and returns it. Returns NaN (Not a
Number) if the string cannot be converted into a number. Use the isNaN()
function to test for NaN. For examples, see ParseFloatIntExamples.

parseInt(string)
Converts string to an integer and returns it. Returns NaN if the string cannot
be converted into a integer.

parseInt(string, radix)
Converts string to an integer and returns it. The optional second argument
(radix) specifies the base of the number contained in the string. The radix
must be an integer between 2 and 36. For radixes above 10, the letters of the
alphabet indicate numerals greater than 9. Set radix to 16 to parse
hexadecimal numbers. Returns NaN if the string cannot be converted into a
integer. For examples, see ParseFloatIntExamples.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html