Home > Community > Forums > Custom IC SKILL > floating point issue

## Email

Recipients email * (separate multiple addresses with commas)

Message *

 Send yourself a copy

## Subscribe

Intro copy of the newsletter section here, some intro copy of the newsletter. Instruction of how to subscribe to this newsletter.

First Name *

Last Name *

Email *

Company / Institution *

 Send Yourself A Copy

# floating point issue

Last post Wed, Oct 24 2012 5:00 AM by Andrew Beckett. 1 replies.
 Started by Rojalin 24 Oct 2012 01:48 AM. Topic has 1 replies and 563 views
• #### Wed, Oct 24 2012 1:48 AM

• Rojalin
• Joined on Wed, Nov 30 2011
• Posts 41
• Points 775
floating point issue
 hi,I have one list of floating numbers like below:A= (0.0 0.36 1.44 1.8 2.16    2.52 3.6 3.96 4.32 4.68    5.76 6.12 6.48 6.84 7.92    8.28 8.64 9.0 )i have another floating number which comes from Xcoordinate of centerBox of a pin object which is 8.887.I want to execute the following function: y=xCoord(centerBox(obj~>bBox))for(k 0 length(A)if(lessp(nth(k A) y) then printf("%.2f" nth(k A))k=k+1)this is giving an error message as followsError lessp:cant handle(nil <8.887)can someone help me how to solve this?thanks
• Post Points: 20
• #### Wed, Oct 24 2012 5:00 AM

Re: floating point issue
 Before I get to the fact that that the approach you're using is wrong and rather inefficient, the reason it is failing is that your loop is going off the end of the list. There's two reasons for that - one is the fact that your loop goes to length(A) rather than length(A)-1 - and the other is the k=k+1 which also passes the end of the list. If the length of the list is L then nth(L A) will return nil - because it is zero-index.Using nth() to access a list is inefficient for anything other than very small lists, because lists are sequential. It's not clear to me precisely what you're trying to do with the k=k+1 bit, but doing this would be better:foreach(elem A  if(lessp(elem y) then printf("%.2f " elem)))Regards,Andrew.
• Post Points: 5