467,074 Members | 844 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,074 developers. It's quick & easy.

Proper way to check that a numerical range "is valid"

Hey all, I have an app, that could take two numbers of any type of
numerical type int, long, double, float, uint, ulong, etc. I want to
check that the numbers are part of a range that I consider "valid".
For my circumstances, I don't consider float.PositiveInfinity valid,
nor do I consider the two numbers valid if the second number is smaller
than the first. In other words, I want to check that the range is
valid.

I notice that while float and double have PositiveInfinity int does
not. Does int have no comparable concept? They obviously have
MaxValue and MinValue, but I'm looking for a concept similar to
positive or negative infinity.

In summary, I just want to make my valid range check code as robust and
thorough as possible.

Thanks,
Novice

Aug 18 '06 #1
  • viewed: 2161
Share:
1 Reply
<il***********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hey all, I have an app, that could take two numbers of any type of
numerical type int, long, double, float, uint, ulong, etc. I want to
check that the numbers are part of a range that I consider "valid".
For my circumstances, I don't consider float.PositiveInfinity valid,
nor do I consider the two numbers valid if the second number is smaller
than the first. In other words, I want to check that the range is
valid.

I notice that while float and double have PositiveInfinity int does
not. Does int have no comparable concept? They obviously have
MaxValue and MinValue, but I'm looking for a concept similar to
positive or negative infinity.

In summary, I just want to make my valid range check code as robust and
thorough as possible.
MinValue and MaxValue are as close as you can get for Int (or any
non-floating point type). These types simply have no concept of infinity -
all possible bit patterns of their representations correspond to valid
integers within their domain.

-cd
Aug 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

24 posts views Thread by hjbortol@mat.puc-rio.br | last post: by
289 posts views Thread by napi | last post: by
3 posts views Thread by JimM | last post: by
4 posts views Thread by Manuel | last post: by
4 posts views Thread by Mike Duffy | last post: by
7 posts views Thread by =?Utf-8?B?Sm9hY2hpbQ==?= | last post: by
3 posts views Thread by =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.