• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. skill assoc : How does assoc command of skill work with...

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 14430
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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

Giora Karni
Giora Karni over 12 years ago
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
  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 12 years ago

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

    If I do:

    > printf("%.20g\n" 50n)
    5.0000000000000004355e-08

    > printf("%.20g\n" 5e-8)
    4.9999999999999997737e-08

    And If I do 

    > printf("%.20g\n" 50*1e-9)
    5.0000000000000004355e-08

    In 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)<epsilon))
    )

    Then you can use myAssoc instead of assoc in the above examples (this is using an absolute error criteria, but you could write it to have a relative error criteria if you preferred).

    Kind Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 12 years ago

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

    If I do:

    > printf("%.20g\n" 50n)
    5.0000000000000004355e-08

    > printf("%.20g\n" 5e-8)
    4.9999999999999997737e-08

    And If I do 

    > printf("%.20g\n" 50*1e-9)
    5.0000000000000004355e-08

    In 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)<epsilon))
    )

    Then you can use myAssoc instead of assoc in the above examples (this is using an absolute error criteria, but you could write it to have a relative error criteria if you preferred).

    Kind Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information