Is there already a discrete range class?

S

Sim Nanda

Hello All,
I'm looking for a data class that can take a
floating point input and round it to the nearest
float based on a predefined set of boundaries.
In other words, an arbitrary float comes in and only
a discrete set of floats come out.

Something to the effect of----
//Given the float breakpoints,
float boundaries[] = {
11.5
,22.0
,24.0
,28.0
,39.0
};

//And the following code
DiscreteRange discreteFloat(boundaries);

discreteFloat.set(26.0);
float floatAnswer = discreteFloat.get();

//Here the 'floatAnswer' would equal 28.0

Anyone know of a class (set of classes) that already provides such
functionality? I've searched the web, but I don't think I'm
using the right terminology for such a critter. It'd be nice
if it was a template, and allowed for rounding up or down.
Any suggestions??

And it seems trivial, but if it already exists
and has been tested...why reinvent.

Happy Friday,
Slarty
 
W

WW

Sim said:
Hello All,
I'm looking for a data class that can take a
floating point input and round it to the nearest
float based on a predefined set of boundaries.
In other words, an arbitrary float comes in and only
a discrete set of floats come out.

I don't knwo of any existing class.

Do you want to make it always round up (or always down)? Because then if I
am not mistaking then you can use the lower_bound/upper_bound functions of
the standard library.
 
S

Sim Nanda

Thanks for the reply.
I was hoping there'd be a full featured class
with everything I'd ever dreamed of (much like
that whole soul mate scam).
I hadn't thought of lower_bound/upper_bound
they will be helpful in writing the class.

Let's say I come up with a dynamite class for
this functionality and I wanted to share it,
where is the best place to put it up?

I guess that's a general question I've had,
what sites (if any) does everyone for C++ code sharing?

bye,
Slarty
 
W

WW

Sim said:
Thanks for the reply.
I was hoping there'd be a full featured class
with everything I'd ever dreamed of (much like
that whole soul mate scam).
I hadn't thought of lower_bound/upper_bound
they will be helpful in writing the class.

Let's say I come up with a dynamite class for
this functionality and I wanted to share it,
where is the best place to put it up?

I guess that's a general question I've had,
what sites (if any) does everyone for C++ code sharing?

Look at http://www.boost.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top