• 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. Is there any SKILL command to find the MIN and MAX value...

Stats

  • Locked Locked
  • Replies 6
  • Subscribers 143
  • Views 6958
  • 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

Is there any SKILL command to find the MIN and MAX value in a list/array (containing numbers) ?

RFStuff
RFStuff over 5 years ago

Dear All,

Is there any SKILL command to find the MIN and MAX value in a list/array (containing numbers).

Kind Regards,

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 5 years ago

    Providing the list doesn't have more than about 260,000 elements, you can just do:

    apply('max theList)
    apply('min theList)

    Otherwise you could just do:

    procedure(CCFmin(lst)
      let((theMin)
        theMin=car(lst)
        foreach(elem cdr(lst)
          theMin=min(theMin elem)
        )
        theMin
      )
    )

    procedure(CCFmax(lst)
      let((theMax)
        theMax=car(lst)
        foreach(elem cdr(lst)
          theMax=max(theMax elem)
        )
        theMax
      )
    )

    Then just use CCFmin(myList) or CCFmax(myList). These have no upper limit to the length of the list.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • RFStuff
    RFStuff over 5 years ago in reply to Andrew Beckett

    Thanks a lot.

    Can you tell how to find the index of the max or min  element in the list. 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 5 years ago in reply to RFStuff

    You can use the lindex function to do this. Find the min or max using the methods I described earlier, and then pass the value found as the second argument to the lindex function, with the list being searched as the first. The index starts from 1, so you'd use nthelem rather than nth to find it again. Or you could write a function similar to CCFmin or CCFmax above which kept a count and returned the index instead.

    That said, needing to find the index suggests to me that you might be using the wrong data structure. In general any time you're accessing a list element via its index suggests that you are treating it as a random-access rather than a sequential data structure (you might want to watch my video Writing Good SKILL Code)

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • RFStuff
    RFStuff over 5 years ago in reply to Andrew Beckett

    Thanks Andrew. Sure, I will watch your video.

    Kind Regards,

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • RFStuff
    RFStuff over 4 years ago in reply to RFStuff

    Dear Andrew,

    Is there a way to find the max/min value in an array A[6][8]  (created by using abMultiDimArray.il).

    I want to find the min/max of A[0] [] (0th row)  and min/max of A[][0] (0th column).

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 4 years ago in reply to RFStuff

    I could probably come up with a complicated macro or function to generalise this, but don't have time right now. So assuming it's a simple two-dimensional array, something like:

    procedure(CCFfindMinMaxForRow(array func row)
      let((current)
        current=array[row][0]
        for(ind 1 length(array[row])-1
          current=funcall(func current array[row][ind])
        )
        current
     )
    )
    
    procedure(CCFfindMinMaxForCol(array func col)
      let((current)
        current=array[0][col]
        for(ind 1 length(array)-1
          current=funcall(func current array[ind][col])
        )
        current
     )
    )

    Then use CCFfindMinMaxForRow(A 'min 0) or CCFfindMinMaxForCol(A 'max 0) for example. You can even use the same functions to add up all the entries in a column or row by passing 'plus instead of 'min or 'max

    Andrew.

    • 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