Connecting Tech Pros Worldwide Help | Site Map

Is there already a discrete range class?

Sim Nanda
Guest
 
Posts: n/a
#1: Jul 19 '05
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
WW
Guest
 
Posts: n/a
#2: Jul 19 '05

re: Is there already a discrete range class?


Sim Nanda wrote:[color=blue]
> 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.[/color]

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.

--
WW aka Attila


Sim Nanda
Guest
 
Posts: n/a
#3: Jul 19 '05

re: Is there already a discrete range class?


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
WW
Guest
 
Posts: n/a
#4: Jul 19 '05

re: Is there already a discrete range class?


Sim Nanda wrote:[color=blue]
> 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?[/color]

Look at http://www.boost.org

--
WW aka Attila


Closed Thread


Similar C / C++ bytes