Re: 'Favourite' methods for scanning/parsing input data?
- From: Mark Borgerson <mborgerson.at.comcast.net>
- Date: Tue, 22 Aug 2006 10:21:59 -0700
In article <lrale25lcidj58dk1502iakn3qju7ind6s@xxxxxxx>, keinanen@xxxxxx
says...
On Mon, 21 Aug 2006 21:09:41 -0700, Mark Borgerson
<mborgerson.at.comcast.net> wrote:
My thinking is that if bad things happen as a result of bad values,
sanity check them, regardless of how they are parsed.
Limit-checking a few dozen input floating-point numbers can add
a lot of machine cycles to an otherwise efficient input processor.
As long as the limits are fixed at compile time, the limit checking of
a floating point value does not cost much, even with 8 bit integer
instructions only. No floating point subtraction (which involves
costly denormalisation) is required.
To check if a received floating point value is above a limit, just
compare the exponent part of the value with the exponent part of the
limit. If the value exponent is greater, the whole value is greater
than the limit. If the value exponent is less than the limit exponent,
the value is definitively less than the limit. Only when the value
exponent and the limit exponent are the same, there is a need to
compare the mantissa parts. Starting with the most significant part
compare bytes/words until a difference is found.
I think that would work pretty well in the most common cases that
I encounter: A gyro rate that should be inside +/-300 deg/sec
ends up at 85314---or some other very large number.
The problem with your test algorithm where error density is
low is that it requires the most cycles when values are inside
limits.
I may have to try your approach, but limit it to just the
exponent test, then see what percentage of the actual
errors it catches. Since the numbers go through a
digital filter, error values which are less than
2X the limiting value won't have as much disruptive
effect as numbers that are 2000 times the limit.
Since my particular limits are symmetric about zero,
I may even be able to work a bit of magic with the
sign bit and perform only one test.
(magic = as-yet-undefined shifts and masking operations)
Mark Borgerson
.
- Follow-Ups:
- Re: 'Favourite' methods for scanning/parsing input data?
- From: Steve at fivetrees
- Re: 'Favourite' methods for scanning/parsing input data?
- From: Paul Keinanen
- Re: 'Favourite' methods for scanning/parsing input data?
- References:
- 'Favourite' methods for scanning/parsing input data?
- From: Mike G
- Re: 'Favourite' methods for scanning/parsing input data?
- From: Steve at fivetrees
- Re: 'Favourite' methods for scanning/parsing input data?
- From: BobH
- Re: 'Favourite' methods for scanning/parsing input data?
- From: Steve at fivetrees
- Re: 'Favourite' methods for scanning/parsing input data?
- From: BobH
- Re: 'Favourite' methods for scanning/parsing input data?
- From: Mark Borgerson
- Re: 'Favourite' methods for scanning/parsing input data?
- From: Paul Keinanen
- 'Favourite' methods for scanning/parsing input data?
- Prev by Date: Re: PIC "interrupt-on-change" combined with normal input?
- Next by Date: Re: PIC "interrupt-on-change" combined with normal input?
- Previous by thread: Re: 'Favourite' methods for scanning/parsing input data?
- Next by thread: Re: 'Favourite' methods for scanning/parsing input data?
- Index(es):
Relevant Pages
|
Loading