Home > Community > Forums > Custom IC SKILL > skill assoc : How does assoc command of skill work with anumerical value ?

## 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

# skill assoc : How does assoc command of skill work with anumerical value ?

Last post Mon, May 13 2013 5:38 AM by Giora Karni. 2 replies.
 Started by Giora Karni 11 May 2013 10:29 AM. Topic has 2 replies and 545 views
• #### Sat, May 11 2013 10:29 AM

• Giora Karni
• Joined on Tue, Jul 27 2010
• Haifa, Israel
• Posts 4
• Points 65
skill assoc : How does assoc command of skill work with anumerical value ?
 How does assoc command of skill work ? After looking closely into several numerical examples, I got the following findings: a = '( ( 20n   xx xx) ( 40n yy yy) (50n zz zz) ) assoc( 2e-08 a)   returns:    (2e-08 xx xx) assoc( 4e-08 a)   returns:    (4e-08 yy yy) assoc( 5e-08 a)   returns:    nil  ß       ????? but if I try:a = '( ( 20e-09   xx xx) ( 40e-09 yy yy) (50e-09 zz zz) ) assoc( 2e-08 a)   returns:    (2e-08 xx xx) assoc( 4e-08 a)   returns:    (4e-08 yy yy)assoc( 5e-08 a)   returns:    (5e-08 zz zz)   I suspect that there is a numerical bug here. It looks like 5e-08 ≠ 50n . I noticed that for 20n,40n,80n,160n (power of 2) the problem doesn't appear.virtuoso version ICADV12.1-64b 03/15/2013 18:29 (sjfnl166)Giora Karni
• Post Points: 20
• #### Sat, May 11 2013 3:30 PM

Re: skill assoc : How does assoc command of skill work with anumerical value ?
 Hi Giora,It's not a numerical bug.  It appears to be a rounding error, within the bounds of what might be expected.assoc simply uses equal() (which is the same as the == operator) to compare the values, and one should never use equal on floating point numbers because there is a possibility of rounding errors (there have been posts related to this before on this forum). Note that this is not something peculiar to SKILL, but in many languages (including C).It appears that there has been a subtle change in ICADV12.1 (and IC616) in how the suffix notation is converted to a floating point number.If you do: 50n-5e-8 you'll see there is a small residual error -  6.617444900424221e-24If I do:> printf("%.20g\n" 50n)5.0000000000000004355e-08> printf("%.20g\n" 5e-8)4.9999999999999997737e-08And If I do > printf("%.20g\n" 50*1e-9)5.0000000000000004355e-08In general, as I said, you should not use equal (or assoc) to compare floating point numbers, because a small rounding error (often just due to a single bit difference in the mantissa) can mean they are no longer precisely equal.You could use something like:procedure(myAssoc(val lst @optional (epsilon 1e-15))  car(exists(entry lst abs(car(entry)-val)
• Post Points: 20
• #### Mon, May 13 2013 5:38 AM

• Giora Karni
• Joined on Tue, Jul 27 2010
• Haifa, Israel
• Posts 4
• Points 65
Re: skill assoc : How does assoc command of skill work with anumerical value ?
 Hi Andrew,Thank you for a full explanation and solution.with regards,Giora
• Post Points: 5