• 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. 'mod'operation on two floating point numbers

Stats

  • Locked Locked
  • Replies 6
  • Subscribers 142
  • Views 7761
  • 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

'mod'operation on two floating point numbers

Mallikarjun032
Mallikarjun032 over 6 years ago

Hi, 

Please tell me how a 'mod' function can be written for two floating point numbers. 

Thanks, 

Mallikarjun

  • Cancel
Parents
  • skillUser
    skillUser over 6 years ago

    Mallikarjun,

    there is a 'modf' function:

    modf(
    f_flonum1
    f_flonum2
    )
    => f_result

    Returns the floating-point remainder of the division of f_flonum1 by f_flonum2.

    Best regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Mallikarjun032
    Mallikarjun032 over 6 years ago in reply to skillUser

    Hi Lawrence,

    Thanks.

    I'm facing another issue when using this function.

    Why is it that the function, when executed directly in ICFB returns one value, and when executed inside a SKILL script, returns a different value?

    Thanks,

    Mallikarjun

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 6 years ago in reply to Mallikarjun032

    Hi Mallikarjun,

    I rather doubt that it's really doing this (I can't see how it would be possible). It's either that you're not seeing all the precision when numbers are displayed in the CIW (try doing sstatus(fullPrecision t) to change the default print representation - that doesn't affect the accuracy of the results, just how they're printed), or that the arguments you're providing to the function are not exactly the same (to full precision).

    Can you give an example which illustrates this problem?

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 6 years ago in reply to Mallikarjun032

    Hi Mallikarjun,

    I rather doubt that it's really doing this (I can't see how it would be possible). It's either that you're not seeing all the precision when numbers are displayed in the CIW (try doing sstatus(fullPrecision t) to change the default print representation - that doesn't affect the accuracy of the results, just how they're printed), or that the arguments you're providing to the function are not exactly the same (to full precision).

    Can you give an example which illustrates this problem?

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
  • Mallikarjun032
    Mallikarjun032 over 6 years ago in reply to Andrew Beckett

    Hi Andrew,

    I can give an example where the function 'modf' is not giving the expected result.

    I have two numbers 296.64 and 0.08, and 296.64 is perfectly divisible by 0.08 yielding a zero remainder.

    But, I don't get 'zero' as result, when I use 'modf'.

    Please find a screenshot of the function execution below...

    Thanks,

    Mallikarjun

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 6 years ago in reply to Mallikarjun032

    Hi Malikarjun,

    Due to floating point rounding errors, the result is actually very slightly smaller than 0.08. This is because it's very hard to exactly represent decimal floating point numbers exactly in IEEE double precision floating point representation. So if you do:

    result=modf(296.64 0.08)
    result-0.08

    you get -1.981748e-14

    Or, put another way:

    > sstatus(fullPrecision t)
    t
    > modf(296.64 0.08)
    0.07999999999998018

    The same thing happens if you were to write a C program using the fmod() function. You probably need to do some amount of small rounding to correct for such potential rounding errors. Alternatively if these are representing coordinates, you could convert to integer (say, multiply by 1000 if the DBUperUU is 1000) and then use mod before dividing by 1000 again:

    mod(round(296.64*1000) 80)/1000.0

    (I'm assuming the 80 is a fixed number).

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Mallikarjun032
    Mallikarjun032 over 6 years ago in reply to Andrew Beckett

    Hi Andrew,

    Thanks for your suggestions. I will multiply the number 296.64 by an appropriate multiplier depending on the value of DBUperUU.

    You are right, that 80 is a fixed number and 296.64 is an x-coordinate of a pin obtained from layout.

    Thanks,

    Mallikarjun

    • 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