macro language bug in v1.44h?

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

macro language bug in v1.44h?

Bill Christens-Barry
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.
Reply | Threaded
Open this post in threaded view
|

Re: macro language bug in v1.44h?

Gabriel Landini
On Saturday 25 September 2010, Bill Christens-Barry wrote:
> The following macro code produces odd results using MacOS 10.6.4:
> x = newArray("3.3", "4.4", "11.1", "33.3", "22.2", "9.9", "3.3");

Shouldn't that be:
 x = newArray(3.3, 4.4, 11.1, 33.3, 22.2, 9.9, 3.3);


G.
Reply | Threaded
Open this post in threaded view
|

Re: macro language bug in v1.44h?

BenTupper
In reply to this post by Bill Christens-Barry
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.
Reply | Threaded
Open this post in threaded view
|

Re: macro language bug in v1.44h?

Bill Christens-Barry
In reply to this post by Bill Christens-Barry
Gabriel, Ben,

Thanks for pointing out that I should explicitly cast the array elements as floats, and the right way to do it.

I did it this way to explore working with data in text files, and why the implicit casting is apparently different for strings having "values" above or below 10. Does this suggest that the forced/implicit cast to float (as in my example) is done differently than is done using an explicit parseFloat() as Ben describes? I suppose Is this just a basic java concept or might it from ImageJ code?

Bill

> On Saturday 25 September 2010, Bill Christens-Barry wrote:
> > The following macro code produces odd results using MacOS 10.6.4:
> >     x = newArray("3.3", "4.4", "11.1", "33.3", "22.2", "9.9", "3.3");
>
> Shouldn't that be:
>  x = newArray(3.3, 4.4, 11.1, 33.3, 22.2, 9.9, 3.3);
>
>
> G.
> 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.