List matching wont work for one number

Hello,

I’m having a problem with List.AllIndicesOf.
I am looking for the index of a number in a sublist.
It works fine for every number tested so far but for some reason 125 wont work.
As shown below i isolate the variables and test if equal, wich they are.
So why wont they show up on the List.AllIndicesOf node?

Hi @MelleH ,

I have done some testing and I am getting weird results when I use @L2 and @L1, it seems to cut of the last item of my second list. No idea why this happens.

It seems to work correctly when I use @L2 and @L2 though:

1 Like

Hey thanks for your reply,

I tried changing the settings but it still does not solve my problem.
As shown below it is still not working for me.
I’ve found a work around tho. Using the equal node and getting all indices of true of those results.
But still weird it doesn’t work with the index node.

Hi @MelleH are all the same object type ?

1 Like

Yes they are all Double

1 Like

Likely a floating point error then. Try rounding both sets of numbers to 3 digits of precision first.

3 Likes

Amigo @MelleH, buenas. Are you sure that all the numbers have the same type, because List.IndexOf Fail when you try to compare 2 diferents datatypes, a few monts ago @sovitek and @christian.stan help me to figure out and give me 2 alternatives solutions, check the post!!

1 Like

Thanks! Thats it.

Winds up that computers are really bad at math (not a Dynamo thing either, try this in excel: =1*(0.5-.04-0.1)).

Any time you are working with doubles being converted from other platforms I find it’s a best practice to round off the values to the level of precision your application needs, otherwise accuracy might suffer.

This does not mean always use as many digits of precision as you can. Typically 3 is sufficient for most project units (0.001mm = 1 mitochondrion; 0.001inches = 3 red blood cells; 0.001 feet = 3 thicknesses of paper), but larger intervals (meters and up) might be better suited for 4 or more. I have not seen a functional need to go larger than 6. If I am unsure but know you might be working in say miles (0.001 miles = as tall as napoleon; 0.000001 miles = a strand of spagetti), I might use 6.

2 Likes