Data Type limits

 

Just found exceeding the data type max and min values doesn't trigger any kind of error message... just silently wraps around :/

e.g.

int a = 2147483647;
int b = a+1;  //b is -2147483648 !?

Are there are any simple ways of safeguarding against this?

 
Yes, don't play with the limits
 
alladir: Just found exceeding the data type max and min values doesn't trigger any kind of error message... just silently wraps around :/
  1. Same as every machine running in the last 60 years.
  2. What are you doing that you need to go anywhere near the limits?
 
WHRoeder:
  1. Same as every machine running in the last 60 years.
  2. What are you doing that you need to go anywhere near the limits?


Most languages at least tell you that it happened.

I'm summing, times and squaring dates (x axis) for simple linear regression. Even with bar numbers, I can't get over 1000, so I'm changing to excel style dates.

I know you'll tell me to use a high timeframe, but why not get higher resolution. I'll do it by dll

Still, no way of warning about vars wrapping around?

 
alladir:


Most languages at least tell you that it happened.

I'm summing, times and squaring dates (x axis) for simple linear regression. Even with bar numbers, I can't get over 1000, so I'm changing to excel style dates.

  1. False. Very few do. Some do with debug mode.
  2. If you're doing linear regression you're going to be using doubles not ints. No problems.
Reason: