• 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. If condition error

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 142
  • Views 6347
  • 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

If condition error

dakuang01
dakuang01 over 2 years ago

Hi,

I could use some help.

I copied a part of the skill codes I've been writing. Basically I'm trying to the short metal ends going beyond a via.

The problem is the following if condition doesn't give me true and I don't know the reason. The step result says the values are the same like in the image. 
 
if(getX1(d~>bBox)==caar(d~>points)-d~>width/2.0 then ;vertical line

Could you give me some advice on this? getX1 is giving me X1 number of a bBox list((X1 Y1) (X2 Y2))

foreach(d l_lineOnTheVia
    if(d~>objType == "path" then
        l_points = d~>points
       ;numberp(getX1(d~>bBox))
       ;numberp(caar(d~>points)-d~>width/2.0)
       if(getX1(d~>bBox)==caar(d~>points)-d~>width/2.0 then 
           if(x_centerY-getY1(d~>bBox) <= getY2(d~>bBox)-x_centerY then 
               l_replace = list(getX1(d~>points) getY1(a~>bBox)) 
              rplaca(nthcdr(sub1(1) l_points) l_replace)
              d~>points = l_points
           else
               l_replace = list(getX2(d~>points) getY2(a~>bBox))
               rplaca(nthcdr(sub1(d~>nPoints) l_points) l_replace)
               d~>points = l_points
);endif
);endif
);foreach




Thanks,
Jane

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 2 years ago

    Jane,

    This is almost certainly due to a floating point rounding error. You should (almost) never use == to compare floating point numbers, unless you can guarantee that they were created the same way. So for example, comparing two coordinates in the database is safe because they will have both been converted from the underlying database units (which are integer underneath) in the same way.

    In this case you are comparing:

    getX1(d~>bBox)

    to

    caar(d~>points)-d~>width/2.0

    The first comes directly from the database, but the second does a maths operation on a database value which can certainly lead to a tiny numerical error.

    The correct way to compare numbers in this case would be to convert to database units and compare as integers. So to do this in your code somewhere:

    dbu=cv~>DBUPerUU

    and then have a function:

    procedure(CCFcompareCoord(val1 val2 dbu)
      round(val1*dbu)==round(val2*dbu)
    )

    and do:

    if(CCFcompareCoord(getX1(d~>bBox) caar(d~>points)-d~>width/2.0 dbu) then

    The idea here is that you are finding the database unit size and converting the numbers to integer which can be safely compared. The database is really stored as integers so this is safe.

    The simpler (although not really the right solution) could be to use the nearlyEqual function instead - although this doesn't really account for using suitable tolerances for the database, it will probably work OK:

    if(nearlyEqual(getX1(d~>bBox) caar(d~>points)-d~>width/2.0) then

    Personally I'd compare the coordinates as integers.

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • dakuang01
    dakuang01 over 2 years ago in reply to Andrew Beckett

    Hi Andrew,

    Thank you very much. I never knew I shouldn't compare floating point numbers.

    And with the code you provided it works!

    Thanks,
    Jane

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 2 years ago in reply to dakuang01

    Hi Jane,

    dakuang01 said:
    Thank you very much. I never knew I shouldn't compare floating point numbers.

    Note that this is not specific to SKILL - it's a problem in any language that uses IEEE floating point representation. For example in Python:

    >>> 0.1*33==3.3
    False

    >>> 0.1*33-3.3
    4.440892098500626e-16

    Anyway, glad the code I provided helped!

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • dakuang01
    dakuang01 over 2 years ago in reply to Andrew Beckett

    Oh I see. I've coded for over 10 years whenever needed and haven't run into this kind of errors. Glad now I know!

    Thanks,
    Jane

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

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