Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Real to INT = error....sometimes

    SDK Help
    0
    5
    436
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 14/06/2004 at 21:44, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   8.207 
      Platform:   Windows  ;   
      Language(s) :     C++  ;

      ---------
      Guess this:
      Vector pos;
      pos = pobj->GetPos();
      Ok....nice so far. I snapped the grid to 1.0, so I only get full coordinates, no float values.
      INT x = pos.x;
      Also sounds ok.
      Guess pos.x = 29.0000 ( this is what vc debug says ) Then, x = 29...in most cases, sometimes its 28!!!!!!!
      Any ideas?????????????????????

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 14/06/2004 at 22:02, xxxxxxxx wrote:

        Hm, SAVELONG( ) seems to solve the problem.....but why is it a problem? I always wrote int = float without thinking about it....did I not understand something essential, or whats going on?

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 17/06/2004 at 20:18, xxxxxxxx wrote:

          Floating point numbers only have finite precision. Since the INT conversion just scraps the decimals, it might happen that you lose 0.9999. Use something like "INT x = pos.x + 0.5" if you want to round to the closest integer.
          (Btw, please limit the number of consecutive punctuation marks to three, in order to reduce forum bandwidth use.)

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 17/06/2004 at 23:08, xxxxxxxx wrote:

            Yes about the 0.9999 I did of course know, I just wondered because I set the initial objects position to 0/0/0, and move it with grid width 1.0, so decimal places should be all zero. Even if I debug it, they are zero, I thought the debug of vc shows the exact values of the variables, but not only an approximate value

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 18/06/2004 at 00:55, xxxxxxxx wrote:

              you could also use Ceil() for example (or Floor() for the vice-versa result)

              1 Reply Last reply Reply Quote 0
              • First post
                Last post