Jump to content
  • Advertisement
Sign in to follow this  
Amadeus H

Stroke of integer genius

This topic is 1985 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

Advertisement

I'm not sure what's worse here. The fact that "gb" can only take two different values (zero or one) on 32-bit systems, or the lack of rounding causing huge accuracy problems (0.99GB anyone?)

 

Probably should make those floats or doubles anyway. That way you can't screw up! (but you still will)

Share this post


Link to post
Share on other sites

Sadly reminiscent of a certain company's installers which - last time I checked - still hadn't been updated for that magical moment when drives > 2gb became not only possible, but also commonplace.  Shudder.

Share this post


Link to post
Share on other sites

I should never have digged through this part of the code base.

In a function (EstimateTime), a background thread with a while(true) loop (terminated using Abort() -- yeah, Abort), at the end I found this comment:

 

Thread.Sleep(500); // Estimate time every 5 seconds.

 

Yeah, that's not how milliseconds work.

And why not use the built in C# class Timer?

 

I don't know. I give up.

Edited by Amadeus H

Share this post


Link to post
Share on other sites

I should never have digged through this part of the code base.

In a function (EstimateTime), a background thread with a while(true) loop (terminated using Abort() -- yeah, Abort), at the end I found this comment:

 

Thread.Sleep(500); // Estimate time every 5 seconds.

 

Yeah, that's not how milliseconds work.

And why not use the built in C# class Timer?

 

I don't know. I give up.

 

Thanks for these examples.  I use them as "warm up" exercises for the C# programming class I teach.   My 16-17 year old students wondered why anybody in their right mind would have used an int for that disk space operation if you were working with numbers that should easily be 2+ billion.   One of my female students chimed in and wondered why they would do that given that integer division will result in truncated remainders.. she thought it would dramatically skew the calculation.  I wonder how many of them would have caught it if it was a debugging exercise as part of a larger project example though.

Share this post


Link to post
Share on other sites

Granted this question is dependent on when that code was written, but int is normally 2^(number of bits in the CPU). So on a modern processor (64 bit) an unsigned int or even int shouldn't be a problem.

Though to be clear, I know a long would be the better and safer choice.

Edited by Alpha_ProgDes

Share this post


Link to post
Share on other sites

Actually, int remains 32-bits for most languages and compilers out there.

 

Really? I thought it was based on the CPU and you had to target the compiler to 32-bit or whatever XX-bit.

Share this post


Link to post
Share on other sites

Actually, int remains 32-bits for most languages and compilers out there.

 

Really? I thought it was based on the CPU and you had to target the compiler to 32-bit or whatever XX-bit.

Aye, on practically all compilers I know of (other than for more obscure chips), int is a 32-bit value. GCC and Clang treat long as a 64-bit value on 64-bit systems, but MSVC requires you do use long long. In C++, at least. Languages like C#, int is 32-bit, long is 64-bit.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!