• 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. Bug or feature?

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 142
  • Views 6077
  • 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

Bug or feature?

Slawa
Slawa over 14 years ago

 Hello

 In my script the following is used
x1=y/0.01
x1t=truncate(x1)
If x1 - an integer that x1t should be equal in a case x1 but

if y=1308.1 then
x1=130810.0
x1t=130809

Why??

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 14 years ago

    It's not a bug. This is a normal consequence of floating point calculations in any language (C, Tcl, perl - you name it). Many things on the web about this, but this is a good reference:

    http://docs.sun.com/source/806-3568/ncg_goldberg.html

    Try doing x1-130810 and you'll see that x1 is a tiny amount below 130810 and hence when truncated it ends up as 130809. It's caused by the fact that 0.01 is an infinitely recurring sequence in binary, rather like 1/3 is 0.333 recurring in base 10 - and so if you truncate the number to a finite precision, you end up with rounding errors.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • skillUser
    skillUser over 14 years ago

    Hi,

    Neither a bug or a feature!  You show x1 as being 130810.0, but it may actually be internally represented as 130809.999997 (say), so it may display as 130810.0, but when you truncate the fractional part to make it an integer, you see 130809.  You can print more digits of a floating point number, e.g. using printf() to check this for yourself, something like the following:

     printf("%6.8f" x1) 
     => 130809.99999700

    The default print representation of a floating point may give you up to 6 digits of precision, but only for about 7 significant digits, so if the number is already 6 digits 'wide', then you will only get one digit of precision and the number is rounded when it is presented to you.

    I hope that this helps to answer your question, or at least helps you to understand what is happening.

    Regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Slawa
    Slawa over 14 years ago

     Many thanks for so detailed explanations and for the reference to very useful article

     

    Best regards

    Slawa 

    • 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