• 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 Design
  3. Calculator function that returns the sign of the number

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 125
  • Views 18107
  • 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

Calculator function that returns the sign of the number

acbalbason
acbalbason over 13 years ago

Hi All,

I was wondering if there exists a way or a function from the calculator which will return if the number is positive or negative. Or at least something close to that.

Regards,

Alfonso

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 13 years ago

    If you want this to work on waveforms - to give (say) 1 or 0 depending on whether it's positive or not, you could use:

    abApplyToWave(lambda((val) if(plusp(val) 1 0)) myWaveform)

    where myWaveform is your expression. This uses this code below. If the lambda frightens you, you could do:

    procedure(abPositive(val)
      if(drIsWaveform(val) || famIsFamily(val) then
        abApplyToWave('abPositive val)
      else
        if(plusp(val) 1 0)
      )
    )

    And then use:

    abPositive(yourExpression)

    This will work if it's a number or a waveform - it uses abApplyToWave inside. I wrote the example above in C syntax to make it easier if you're not familiar with the LISP syntax - but the abApplyToWave is written using LISP-style. See the comments at the top.

    /* abApplyToWave.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       May 24, 2011 
    Modified   A.D.Beckett 
    By         May 31, 2011 
    
    Function to apply a unary function to every element
    in a waveform. For example:
    
    abApplyToWave('round waveform)
    
    Can also add to the Skill User Defined Function using:
    
    abRegApplyToWaveSpecialFunction()
    
    ***************************************************
    
    SCCS Info: @(#) abApplyToWave.il 05/31/11.17:24:41 1.2
    
    */
    
    /***************************************************************
    *                                                              *
    *                  (abCreateApplyToWaveForm)                   *
    *                                                              *
    *      Create the form needed to enter the function name       *
    *                                                              *
    ***************************************************************/
    (defun abCreateApplyToWaveForm ()
      (let (func)
        (setq func (ahiCreateStringField
                     ?name 'func
                     ?prompt "Function"
                     ?value "round"
                     )
              )
        (calCreateSpecialFunctionsForm
          'abApplyToWaveForm
          (list (list func 0:0 280:20 140))
          )
        )
      )
    
    /***************************************************************
    *                                                              *
    *               (abApplyToWaveSpecialFunctionCB)               *
    *                                                              *
    *            Callback for the registration function            *
    *                                                              *
    ***************************************************************/
    (defun abApplyToWaveSpecialFunctionCB ()
      (calCreateSpecialFunction
        ?formSym 'abApplyToWaveForm
        ?formInitProc 'abCreateApplyToWaveForm
        ?formTitle "Apply to Wave"
        ?formCallback "abApplyToWaveFormCB()"
        )
      )
    
    /********************************************************************
    *                                                                   *
    *                       (abApplyToWaveFormCB)                       *
    *                                                                   *
    * Callback for the form. Bit complicated because need the arguments *
    * to be with the waveform not first, and with a single quote before *
    *                        the function name.                         *
    *                                                                   *
    ********************************************************************/
    (defun abApplyToWaveFormCB ()
      (let (form)
        (setq form (hiGetCurrentForm))
        (calCalcInput
          'expression
          (sprintf nil "abApplyToWave('%s %s)"
                   (concat (getq (getq form func) value))
                   (calGetBuffer))
          )
        t
        )
      )
    
    /******************************************************************
    *                                                                 *
    *                (abRegApplyToWaveSpecialFunction)                *
    *                                                                 *
    * Function to actually register the user defined special function *
    *                                                                 *
    ******************************************************************/
    (defun abRegApplyToWaveSpecialFunction ()
      (calRegisterSpecialFunction
        (list "abApplyToWave" 'abApplyToWaveSpecialFunctionCB)
        )
      t
      )
    
    /******************************************************************
    *                                                                 *
    *                    (abApplyToWave func arg)                     *
    *                                                                 *
    *  And finally, the function that does the work. You give it the  *
    *  name of a unary function (takes one argument) which works on   *
    * numbers, and then this is applied to all members of a waveform. *
    *                      Handles families too.                      *
    *                                                                 *
    ******************************************************************/
    (defun abApplyToWave (func arg)
      (cond 
        ((numberp arg) (funcall func arg))
        ((drIsDataVector arg) (vecMap 'abApplyToWave func arg))
        ((drIsWaveform arg) 
         ;-------------------------------------------------------------------
         ; Create new waveform, but transfer units if not set on 
         ; new waveform already. This ensures plotting on the same y-axis
         ;-------------------------------------------------------------------
         (let (new yVec)
           (setq new (wfMap 'abApplyToWave func arg))
           (setq yVec (drGetWaveformYVec new))
           (unless (getq yVec units)
             (putpropq yVec (getq (drGetWaveformYVec arg) units) units)
             )
           new
           )
         )
        ((famIsFamily arg) (famMap 'abApplyToWave func arg))
        (t
          (error "abApplyToWave: can't apply %L to %L\n"
                 func arg)
          )
        )
      )
    
    
     

     

     

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

    If you want this to work on waveforms - to give (say) 1 or 0 depending on whether it's positive or not, you could use:

    abApplyToWave(lambda((val) if(plusp(val) 1 0)) myWaveform)

    where myWaveform is your expression. This uses this code below. If the lambda frightens you, you could do:

    procedure(abPositive(val)
      if(drIsWaveform(val) || famIsFamily(val) then
        abApplyToWave('abPositive val)
      else
        if(plusp(val) 1 0)
      )
    )

    And then use:

    abPositive(yourExpression)

    This will work if it's a number or a waveform - it uses abApplyToWave inside. I wrote the example above in C syntax to make it easier if you're not familiar with the LISP syntax - but the abApplyToWave is written using LISP-style. See the comments at the top.

    /* abApplyToWave.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       May 24, 2011 
    Modified   A.D.Beckett 
    By         May 31, 2011 
    
    Function to apply a unary function to every element
    in a waveform. For example:
    
    abApplyToWave('round waveform)
    
    Can also add to the Skill User Defined Function using:
    
    abRegApplyToWaveSpecialFunction()
    
    ***************************************************
    
    SCCS Info: @(#) abApplyToWave.il 05/31/11.17:24:41 1.2
    
    */
    
    /***************************************************************
    *                                                              *
    *                  (abCreateApplyToWaveForm)                   *
    *                                                              *
    *      Create the form needed to enter the function name       *
    *                                                              *
    ***************************************************************/
    (defun abCreateApplyToWaveForm ()
      (let (func)
        (setq func (ahiCreateStringField
                     ?name 'func
                     ?prompt "Function"
                     ?value "round"
                     )
              )
        (calCreateSpecialFunctionsForm
          'abApplyToWaveForm
          (list (list func 0:0 280:20 140))
          )
        )
      )
    
    /***************************************************************
    *                                                              *
    *               (abApplyToWaveSpecialFunctionCB)               *
    *                                                              *
    *            Callback for the registration function            *
    *                                                              *
    ***************************************************************/
    (defun abApplyToWaveSpecialFunctionCB ()
      (calCreateSpecialFunction
        ?formSym 'abApplyToWaveForm
        ?formInitProc 'abCreateApplyToWaveForm
        ?formTitle "Apply to Wave"
        ?formCallback "abApplyToWaveFormCB()"
        )
      )
    
    /********************************************************************
    *                                                                   *
    *                       (abApplyToWaveFormCB)                       *
    *                                                                   *
    * Callback for the form. Bit complicated because need the arguments *
    * to be with the waveform not first, and with a single quote before *
    *                        the function name.                         *
    *                                                                   *
    ********************************************************************/
    (defun abApplyToWaveFormCB ()
      (let (form)
        (setq form (hiGetCurrentForm))
        (calCalcInput
          'expression
          (sprintf nil "abApplyToWave('%s %s)"
                   (concat (getq (getq form func) value))
                   (calGetBuffer))
          )
        t
        )
      )
    
    /******************************************************************
    *                                                                 *
    *                (abRegApplyToWaveSpecialFunction)                *
    *                                                                 *
    * Function to actually register the user defined special function *
    *                                                                 *
    ******************************************************************/
    (defun abRegApplyToWaveSpecialFunction ()
      (calRegisterSpecialFunction
        (list "abApplyToWave" 'abApplyToWaveSpecialFunctionCB)
        )
      t
      )
    
    /******************************************************************
    *                                                                 *
    *                    (abApplyToWave func arg)                     *
    *                                                                 *
    *  And finally, the function that does the work. You give it the  *
    *  name of a unary function (takes one argument) which works on   *
    * numbers, and then this is applied to all members of a waveform. *
    *                      Handles families too.                      *
    *                                                                 *
    ******************************************************************/
    (defun abApplyToWave (func arg)
      (cond 
        ((numberp arg) (funcall func arg))
        ((drIsDataVector arg) (vecMap 'abApplyToWave func arg))
        ((drIsWaveform arg) 
         ;-------------------------------------------------------------------
         ; Create new waveform, but transfer units if not set on 
         ; new waveform already. This ensures plotting on the same y-axis
         ;-------------------------------------------------------------------
         (let (new yVec)
           (setq new (wfMap 'abApplyToWave func arg))
           (setq yVec (drGetWaveformYVec new))
           (unless (getq yVec units)
             (putpropq yVec (getq (drGetWaveformYVec arg) units) units)
             )
           new
           )
         )
        ((famIsFamily arg) (famMap 'abApplyToWave func arg))
        (t
          (error "abApplyToWave: can't apply %L to %L\n"
                 func arg)
          )
        )
      )
    
    
     

     

     

    • 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