List Info

Thread: Fix a problem, another one springs up




Fix a problem, another one springs up
country flaguser name
United States
2007-05-05 05:50:50

The workaround for the list item problem returns the correct result
but I am now back to the original problem of the "duration >
duration_threshold" comparison returning the incorrect result.

The following slightly bizarre code seems to fix both problems:

feature -- Measurement

onset_time: REAL

offset_time: REAL

duration: REAL is
--
do
Result := offset_time - onset_time
end

is_threshold_exceeded (duration_threshold: REAL): BOOLEAN is
--
local
l_duration: REAL
do
l_duration.set_item (duration)

-- Assignment doesn't work
-- l_duration := duration

if l_duration > duration_threshold then
Result := true
end
end

__._,_.___
.

__,_._,___
Finally a workaround that really works
country flaguser name
United States
2007-05-05 08:17:21

A problem with the "l_duration.set_item (duration)" idea is that
l_duration became zero for certain values of duration.

After noticing that (duration - duration_threshold) was a very small
number that was not zero I hit on the idea of the following code that
gets rid of a tiny difference that seems to be hidden from the debugger.

It seems to solve all my problems for the time being.

duration: REAL is
--
do
Result := offset_time - onset_time
Result := (Result * 1.0e5).floor * 1.0e-5
end

Finnian wrote:
>
> The workaround for the list item problem returns the correct result
> but I am now back to the original problem of the "duration >
>; duration_threshold" comparison returning the incorrect result.
>
> The following slightly bizarre code seems to fix both problems:
>
>
> feature -- Measurement
>
> onset_time: REAL
>;
> offset_time: REAL
>;
> duration: REAL is
> --
> do
> Result := offset_time - onset_time
> end
>
> is_threshold_exceeded (duration_threshold: REAL): BOOLEAN is
> --
> local
> l_duration: REAL
>; do
> l_duration.set_item (duration)
>
> -- Assignment doesn't work
>; -- l_duration := duration
>
> if l_duration > duration_threshold then
>; Result := true
>; end
> end
>

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )