Re: 'Favourite' methods for scanning/parsing input data?



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

.



Relevant Pages

  • Re: Favourite methods for scanning/parsing input data?
    ... Limit-checking a few dozen input floating-point numbers can add ... No floating point subtraction (which involves ... compare the exponent part of the value with the exponent part of the ... compare the mantissa parts. ...
    (comp.arch.embedded)
  • Re: fixed-point
    ... First ask yourself "what is the purpose of a floating point number?" ... Adjust the numbers so that both numbers have the same exponent ... The 16 in the macro refers to the multiplication factor. ... function call in so far as the paramter conversion is concerned. ...
    (comp.lang.c)
  • Re: Fastest way to compute floating point log and exp
    ... So far I've found that with a few tables and floating point MUL and ADD ... You didn't mention how much precision you need, nor for that matter what the log base is to be. ... bit easier than other bases because the floating point exponent is the integer portion of the log. ...
    (comp.arch.fpga)
  • Re: Invalid results from exp2 function (C math library)
    ... You are asking your floating point library to do something it isn't ... In my specific case I only take exponent of negative values. ... I expect that some intermediate calculation hurled ... It depends on your compiler. ...
    (comp.lang.c)
  • Re: representations
    ... The exponent is the exponent, ... IEEE standard floating point number use something very similar to scientific notation. ... There is one exception to this rule, zero, so zero is represented specially by all bits zero. ... Finally there are a few special representations for infinity, not a number, and what are called denormalised numbers, but you can ignore those for now. ...
    (comp.lang.c)

Loading