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
    • Recent
    • Tags
    • Users
    • Register
    • Login

    StringToReal not accurate??

    Scheduled Pinned Locked Moved SDK Help
    4 Posts 0 Posters 320 Views
    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 Offline
      Helper
      last edited by

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

      On 26/04/2005 at 20:53, xxxxxxxx wrote:

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

      ---------
      Hello all, I'm trying to turn the C4D serial into a number.
      I get the C4D serial just fine, but when I use StringToReal, I get the number, but just a little off.

      For example, I tried 12345678900 and ended up with 12345678848.

      I've even tried setting up my own version of the StringToReal function and the same thing happens.

      Tried in both 8.5 and 9.1.

      Does C4D lose accuracy with numbers that large?
      Has anyone experienced this before or know what's going on?
      Is there a way around it?

      -Chris

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

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

        On 26/04/2005 at 21:27, xxxxxxxx wrote:

        Floating point values (on all computers) are approximations using a Mantissa and Exponent stored in 4 bytes (or 8 for double/long double). FP accuracy is not guaranteed past the number of Mantissa bits (I forget how many that is).

        You should be treating the value as a long double real and use your own StringToDLong() to convert.

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

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

          On 26/04/2005 at 21:37, xxxxxxxx wrote:

          Well I appreciate that info Robert. The StringToReal function I set up is pretty crude, so I guess I'll work on that. I'll be sure to post it if I get it in working order.

          I noticed that I started to get the inaccuracies once the number got into the 100 millions.

          Just for fun, I ported the code I was using to VB and it worked just fine, which suprised the hell out of me.

          Oh well.

          -Chris

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

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

            On 26/04/2005 at 21:43, xxxxxxxx wrote:

            VB is probably doing auto conversion to maintain appropriate storage. The double reals have 64-bits of mantissa which should be more than sufficient for accuracy in this situation - I hope! 🙂 long double reals (Microsoft specific) has 80-bits of mantissa.

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