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

    modulo - behind the scenes

    Cinema 4D SDK
    r19 r20 c++
    2
    3
    547
    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.
    • C4DSC
      C4DS
      last edited by

      While cleaning up some code, both in R19 and R20, I noticed I sometimes use a % b to calculate a modulo, and sometimes LModulo(a, b) (where a and b are both Int32 variables or values).
      Obviously, the LModulo is defined in the Cinema 4D SDK and thus preferred. But what is the benefit of using it over the regular modulus operator, or put differently, what are the cons of using the modulus operator?

      Just wondering.

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by

        Hi Daniel, thanks for reaching out us.

        With regard to the LModulo function, being it part of the cinema.framework, you can see, by looking at the implementation, that it:

        • it's the specialized version for integers with either Int32 or Int64 parameters' data-type;
        • handles properly the case of the first argument being negative;
        • handles gracefully the case where the second argument is zero.

        The code, available in the framework is:

        if (!b)
        	return 0;
        if (a >= 0)
        	return a % b;
        
        a -= (a / b) * b;
        if (a < 0)
        	a += b;
        
        return a;
        

        Cheers, Riccardo

        1 Reply Last reply Reply Quote 1
        • C4DSC
          C4DS
          last edited by

          Thanks for the info.

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