[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] Problem of the week: testing a testing tool
From: |
Greg Chicares |
Subject: |
Re: [lmi] Problem of the week: testing a testing tool |
Date: |
Tue, 09 Jan 2007 16:36:56 +0000 |
User-agent: |
Thunderbird 1.5.0.4 (Windows/20060516) |
On 2007-1-8 19:56 UTC, Ericksberg, Richard wrote:
[...]
> double const w = std::min(std::log10(v), static_cast<double>(ULONG_MAX));
> unsigned long int const x = static_cast<unsigned long int>(w);
> double const volatile y = std::pow(10.0, static_cast<double>(x));
> unsigned long int const z = static_cast<unsigned long int>(y);
[...]
> The erroneous output happens when the result of std::log10(v)
> is negative and then cast to an unsigned long int.
> Example [test using 0.001 for max_seconds_ and no mpatrol]:
>
> [Overhead]
> v: 0.0501144
> trial_time: 0.0199543
> max_seconds: 0.001
> frequency: 3192150000
>
> ULONG_MAX: 4294967295
> v: 0.0501144
> log10(v): -1.30004
> w: -1.30004
> cast of w: 4294967295
> x: 4294967295
> y: 1.#INF
> z: 0
>
> In this case, when the negative result of std::log10(v) is
> cast as an unsigned long int, it's getting the largest value
> of an unsigned long int [ULONG_MAX]. This happens when the
> integer value is one or greater. When the integer value is
> zero, you get 0 from the cast.
We've found at least one problem in a four-line block of code.
That block serves a single purpose, and it's kind of tricky to
get it right.
Above, you're exploring it by adding print statements--and
manually changing 'input_test.cpp' in order to create the
conditions you want to test. That demonstrates the problem at
hand. I think it'd be easier to fix it--and make sure it stays
fixed--if that block were a function with its own tests, so
I've made such a change in cvs. (Please review it--did I
reshuffle everything correctly?)
Now that we've isolated that aspect of the problem, how should
we fix it?
- RE: [lmi] Problem of the week: testing a testing tool, Boutin, Wendy, 2007/01/05
- Re: [lmi] Problem of the week: testing a testing tool, Greg Chicares, 2007/01/08
- RE: [lmi] Problem of the week: testing a testing tool, Ericksberg, Richard, 2007/01/08
- RE: [lmi] Problem of the week: testing a testing tool, Ericksberg, Richard, 2007/01/10
- Re: [lmi] Problem of the week: testing a testing tool, Greg Chicares, 2007/01/18