I think I am looking for functionality that is contained with the Interval library, but am having a hard time digesting the documentation for this particular library. I would like an Interval that goes from a min_value to a max_value, where each value is the previous value + N. For example, the interval {2, 6, 10, 14, 18} has a minimum value of 2, a maximum value of 18, and increments by 4. Given this interval, I would like a function, Foo, that works as follows: Interval(2, 18, 4) i; i.Foo(2) == 2 i.Foo(6) == 2 i.Foo(0) == 2 i.Foo(18) == 18 i.Foo(20) == 18 i.Foo(5) == 6 i.Foo(3) == 6 Is this something that can be done with the Interval library, or am I missing the point? :) Thanks in advance for your help! David Brownell
Le mer 21/01/2004 à 23:22, David Brownell a écrit :
I think I am looking for functionality that is contained with the Interval library, but am having a hard time digesting the documentation for this particular library.
I would like an Interval that goes from a min_value to a max_value, where each value is the previous value + N.
It isn't possible. For the library, the definition of an interval is a closed and *convex* set of data. As soon as you put this stride N, the set is not convex anymore. Moreover, you can't define any arithmetic on such an "interval" (the library is an interval *arithmetic* library). What you are looking for is probably a "Range" library (this name has shown up a few times on the Boost mailing-list).
For example, the interval {2, 6, 10, 14, 18} has a minimum value of 2, a maximum value of 18, and increments by 4. Given this interval, I would like a function, Foo, that works as follows:
Interval(2, 18, 4) i;
i.Foo(2) == 2 i.Foo(6) == 2 i.Foo(0) == 2 i.Foo(18) == 18 i.Foo(20) == 18 i.Foo(5) == 6 i.Foo(3) == 6
I must be misunderstanding something, because I don't understand at all what this function is supposed to do. Is it a random function?
Is this something that can be done with the Interval library, or am I missing the point? :)
Sorry; but you are.
Thanks in advance for your help! David Brownell
Regards, Guillaume
On 1/21/04 5:22 PM, "David Brownell"
I would like an Interval that goes from a min_value to a max_value, where each value is the previous value + N.
I think std::valarray<> has something like this.
For example, the interval {2, 6, 10, 14, 18} has a minimum value of 2, a maximum value of 18, and increments by 4. Given this interval, I would like a function, Foo, that works as follows:
Interval(2, 18, 4) i;
I think the val-array slice goes "start, length, stride", so the values for the slice object would be (2, 5, 4).
i.Foo(2) == 2 i.Foo(6) == 2 i.Foo(0) == 2 i.Foo(18) == 18 i.Foo(20) == 18 i.Foo(5) == 6 i.Foo(3) == 6 [TRUNCATE]
What problem are you trying to solve? Also, I can't see any pattern for the "Foo" function. -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com
My apologies everyone, I guess I wasn't very clear of what I was hoping that
the function Foo would return.
If I have the interval {2, 6, 10, 14, 18 }, I would like Foo(N) to return
the value in the interval that is >= N, but less than the max value in the
interval. I am looking over my examples, and I think a typo of mine clouded
the issue as well..
i.Foo(2) == 2
i.Foo(6) == 6 <-- Should have been 6, I erroneously typed 2 on my previous
message
i.Foo(0) == 2
i.Foo(18) == 18
i.Foo(20) == 18
i.Foo(5) == 6
i.Foo(3) == 6
Thanks,
David Brownell
-----Original Message-----
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of Daryle Walker
Sent: Saturday, January 24, 2004 4:20 PM
To: Boost Users mailing list
Subject: Re: [Boost-users] Interval Library?
On 1/21/04 5:22 PM, "David Brownell"
I would like an Interval that goes from a min_value to a max_value, where each value is the previous value + N.
I think std::valarray<> has something like this.
For example, the interval {2, 6, 10, 14, 18} has a minimum value of 2, a maximum value of 18, and increments by 4. Given this interval, I would like a function, Foo, that works as follows:
Interval(2, 18, 4) i;
I think the val-array slice goes "start, length, stride", so the values for the slice object would be (2, 5, 4).
i.Foo(2) == 2 i.Foo(6) == 2 i.Foo(0) == 2 i.Foo(18) == 18 i.Foo(20) == 18 i.Foo(5) == 6 i.Foo(3) == 6 [TRUNCATE]
What problem are you trying to solve? Also, I can't see any pattern for the "Foo" function. -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Daryle Walker
-
David Brownell
-
Guillaume Melquiond