Login  Register

Re: macro language bug in v1.44h?

Posted by BenTupper on Sep 25, 2010; 12:40pm
URL: http://imagej.273.s1.nabble.com/macro-language-bug-in-v1-44h-tp3686799p3686801.html

Hi,

Mac OSX 10.5.8  ImageJ 1.44g3

You might be able to resolve the issue by using parseFloat() on each  
element of x.  The upper code block is your original and the lower is  
mine with the added creation of the variable "value".

value = parseFloat(x[j]);

Then I use "value" in the place of "x[j]".


as string

3.3  3.5  3.5
4.4  4.4  3.5
11.1  4.4  11.1
33.3  4.4  33.3
22.2  4.4  22.2
9.9  9.9  22.2
3.3  9.9  22.2

parsed to float

3.3  3.5  3.5
4.4  4.4  3.5
11.1  11.1  3.5
33.3  33.3  3.5
22.2  33.3  3.5
9.9  33.3  3.5
3.3  33.3  3.5


Cheers,
Ben

print("\\Clear"); print("as string"); print(" ");
        x = newArray("3.3", "4.4", "11.1", "33.3", "22.2", "9.9", "3.3");
        xmax = 3.5;
        x10max = 3.5;
        for (j = 0; j < lengthOf(x); j++) {
                if (x[j] > xmax)
                        xmax = x[j];
                if (10*x[j] > 10*xmax)
                        x10max = x[j];
                print(x[j] + "  " + xmax + "  " + x10max);
        }

print(" ");print("parsed to float"); print(" ");
        x = newArray("3.3", "4.4", "11.1", "33.3", "22.2", "9.9", "3.3");
        xmax = 3.5;
        x10max = 3.5;
        for (j = 0; j < lengthOf(x); j++) {
             value = parseFloat(x[j]);
                if (value > xmax){
                        xmax = value;
                }
                if ((10*value) > (10*xmax)) {
                        x10max = value;
                }
                print(value + "  " + xmax + "  " + x10max);
        }





On Sep 25, 2010, at 8:07 AM, Bill Christens-Barry wrote:

> The following macro code produces odd results using MacOS 10.6.4:
>
>    macro "MaxBugDemo" {
>
> print("\\Clear");
> x = newArray("3.3", "4.4", "11.1", "33.3", "22.2", "9.9", "3.3");
> xmax = 3.5;
> x10max = 3.5;
> for (j = 0; j < lengthOf(x); j++) {
> if (x[j] > xmax)
> xmax = x[j];
> if (10*x[j] > 10*xmax)
> x10max = x[j];
> print(x[j] + "  " + xmax + "  " + x10max);
> }
>    }
>
> Output is:
>
>    3.3  3.5  3.5
>    4.4  4.4  3.5
>    11.1  4.4  11.1
>    33.3  4.4  33.3
>    22.2  4.4  22.2
>    9.9  9.9  22.2
>    3.3  9.9  22.2
>
> Same in 1.44i daily build. I wonder if this is this a string  
> conversion issue.