Victor said:
Are you concerned with less typing, and not with implementing it
correctly *logically*? Do you consider "a single loop" better or more
efficient in some way?
You either failed to understand what I wrote or you are intentionally trying
to misrepresenting what I said. No one claimed that it is better to use
code which is logically incorrect if it provides a way to save on typing. I
don't know where you came up with that nonsense.
"Crude-ish"? Really?
Really.
<shrug> Using an infinity value in that manner is
crudish, IMNSHO.
What happened to logical correctness? And do you also believe that, if the
objective was to get the largest non-negative number, initializing it to
zero or even any negative number would also be crudish?
It suggests that (a) infinity is not a valid value for
any set element to be associated with (which might be true in your
model, but doesn't necessarily sound right in all cases),
Zero is also not valid in a considerable number of cases, and yet variables
are still set by default as zero.
and (b) that
the maximum value from the elements of an empty set is infinity, which
is a number (if you divide by it, you get 0).
As a side note, and nit-picking a bit, this isn't true. Infinity isn't a
number, and k/infinity is meaningless. The k/infinity = 0 is only valid
because it was a specific indeterminate form which is often defined as
lim{x->infinity} k/x.
Similarly, division by zero has also been defined as k/0 = infinity, but
this doesn't mean it's a good idea to hold this as true. For a start, this
would mean that infinity*0 = k.
I'd probably use NaN for
that, although by definition of "seeking a maximum associated floating
point number" should *not* be allowed for an empty set, such search
shouldn't return a value.
<another shrug> I have. But it's still not right. You can use any
other designated value that can never be found in your set. And if you
don't have any identifiable value to use, don't. Use *logic*.
Why is it "not right"? Is there actually a valid technical reason behind
your assertion?
Essentially you're trying to have a mapping of yourtype values to
double/float values without
std::map<double, yourtype const*> yourmap;
. And you're trying to figure out a hack to get
(*yourmap.rbegin()).first without checking whether the 'yourmap' is
empty or not. <third shrug>
Again, you either failed to understand what I wrote or you are intentionally
trying to misrepresent what I said. No one claimed that the set in question
could be empty, and somehow you felt the need to attribute that claim, which
you invented, to someone else.
So, to avoid any more misconceptions or any attempts to misrepresent
anything, here is a clear description of this case.
- there is a non-empty set of data.
- there is a set of operators which map each element of that set to a
floating point number.
- the objective is to evaluate which is the minimum value of the codomain of
a particular operator.
I suggested the following approach:
<pseudo-ish code>
float minimum = std::numeric_limits<float>::infinity();
for(auto element: element_list)
{
if( operator(element) < minimum)
minimum = operator(element);
}
</pseudo-ish code>
Then, I asked if it was a good idea to do this. In other words, if there
was any reason that would made it a bad idea. Until now, no reason has been
given.
I also asked if there was a better way to get the minimum value.
Simple as that.
Rui Maciel