Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Lode

Modulo and negative parameters for arrays?

This topic is 5902 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When trying to make a texturing algorithm for a raytracer, I got a 32*32 array for a texture and did some calculations to see what pixel of the array I must call. The texture array had ONLY pixels with color black and fully bright red but one of the many failed attempts of the algorithm showed up OTHER COLORS!!!! :o These other colors were darker red (no other colors because the texture only had a red channel). Here's a screenshot of this scary stuff: I got the textures working properly now but I still don't understand why: I take modulo %32 of an integer, so the result should be between 0 and 31, is that right? Or does it give problems for numbers < 0? Then I use the result as parameter for a 32x32 array so that should never give problems, right? But then why doesn't my program give an error and shows me some weird stuff that I know are not inside the array? Was I seeing other memory locations? [edited by - Lode on July 29, 2002 9:58:23 AM]

Share this post


Link to post
Share on other sites
Advertisement
I don''t know if compilers in general handles mod the same way, but VC++ doesn''t turn negative numbers into positive when taking the modulus. In effect -13%10 = -3.

-Neophyte

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!