473,473 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
1 2434
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ron Holmes | last post by:
I posted this question on the Crystal Reports Support site and I am still waiting for an answer. Using Crystal Reports 9.0 Developer Full edition: My Crystal report .RPT file has a Picture box...
24
by: hjbortol | last post by:
Hi! Is the expression "a >= b" equivalent to "a - b >= 0" in C/C++? Is this equivalence an IEEE/ANSI rule? Or is this machine/compiler dependent? Any references are welcome! Thanks in...
289
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
3
by: JimM | last post by:
I am trying to create a method in VS 2003 that validates an object argument is of the proper type and within a range of values. I am trying to use a Type to define the casting and object type for...
0
by: ASP Developer | last post by:
For some reason when I direct my users to a word document via Response.ContentType = "application/word" the spell check is turned off. Does anyone know which smart tag needs to be mofied to have it...
4
by: Manuel | last post by:
I think I can't find this on google/books because is soooooooo basic... This function assign a listner pointer to an image widget: ------------------------------------------------------ void...
4
by: Mike Duffy | last post by:
I just recently realized that the comparison operator "is" actually works for comparing numeric values. Now, I know that its intended use is for testing object identity, but I have used it for a...
7
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have an image which I'm trying to save using my_image.Save(some_path, System.Drawing.Imaging.ImageFormat.Path); and then I get the error "Parameter is not valid". What could be the reason...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.