Victor Bazarov
11/13/2008 4:33:00 PM
Matthias wrote:
> Hi Hendrik, hi Group.
>
> Thanks for the answer, sorry that it took me so long to respond ...
>
> On 11 Nov., 11:25, Hendrik Schober <spamt...@gmx.de> wrote:
>> Matthias wrote:
>>> On Nov 7, 10:31 am, James Kanze <james.ka...@gmail.com> wrote:
>>> [... code example ...]
>>>> (But depending on what he's doing, a simple runtime check might
>>>> be sufficient, and is a lot simpler.)
>>> Yes, exactly. The is_integer solution might work, but in my case it's
>>> overkill.
>>> I would prefer a simple runtime check.
>> I'm not sure what "simple runtime check" is supposed to mean.
>> Does it mean you want a simple check done at run-time or does
>> it mean run-time checks are (supposed to be) simpler?
>
> I didn't really think so much about the use of the word "simple", but
> I guess I meant simple in the sense that it's easy to implement and
> easy to read and understand.
> I think in this respect my initial proposal is "simpler", but I still
> don't know if I can use it safely.
>
>> There's two dependencies here, from my POV: the one on the
>> string, which indeed is a run-time one, and the one on the
>> data type, which is known at compile-time.
>> I see no problem in checking the type dependency at runtime.
>> The string parsing has to be done at run-time, but what's to
>> be done with the result when the data type is an integer
>> could well be decided at compile-time.
>
> But everything depends on the input string AND on the data type.
> If the data type is an integer, it should only return successfully if
> the given number is a multiple of 1000.
>
> Now the question is still: How do I check this reliably?
> And it would be nice if it's still "simple" ...
> Would be nice if that could be done in only very few lines of code.
>
> Can anyone tell me if my initial proposal is good or bad?
> Here it is again (by the way, I forgot the "return true;" in my
> original posting):
>
> if (temp / 1000 * 1000 != temp) return false;
> else output = temp / 1000;
> return true;
So, let me get this straight. When you parse your string, the number
that you input can (internally) be of two different types? How do you
make your determination? Presence of the decimal separator? So, if the
input contains "1.5H", it's floating point, and if it's "1M", it's an
integer? Why? What if your algorithm always inputs a floating point
and if there is a suffix, converts the number to seconds and only then
checks if it has a fractional part? You still can do it, can't you?
What is the range of times you're hoping to process? What's the maximum
time? What's the minimum time? Even 1000H is only 3.6e6 seconds and
can be determined to have (or not to have) a fraction if converted to an
integer ('unsigned long' should suffice)...
I believe you're trying to solve a wrong problem here.
Also, have you read the FAQ section 35 (templates)? Also, did you see
my response to your original post?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask