So as a concrete example, consider a signal that changes from the value
(3/5.) to the value (1000/3.).

The "exact" double-precision floating-point values formatted as decimals
with 17 digits of precision are:
    5.99999999999999978e-01   # 3/5 = .600...
    3.33333333333333314e+02   # 1000/3 = 333.3...

The "exact" single-precision floating-point values formatted as decimals
with 7 digits of precision are:
    6.0000002e-01
    3.3333334e+02

And the values that could arise from a read which gets a half-modified
value are:
    6.00000063578287723e-01
    3.33333300781249989e+02

Here, I arrange them next to the single-precision values for eyeball
comparison:
    6.00000063578287723e-01
    6.0000002e-01

    3.33333300781249989e+02
    3.3333334e+02
.. only the digit that corresponds to the least significant digit in
single-precision floating point differs.

And that's why doing nothing is probably best, even if it's got
theoretical problems.

Jeff
PS Here's Python code for word-swapping a pair of doubles, and for
forcing a Python floating-point value to 'float' precision:

import struct

def mix(v1, v2):
    s = struct.pack("2d", v1, v2)
    v1h, v1l, v2h, v2l = struct.unpack("4I", s)
    t = struct.pack("4I", v1h, v2l,  v2h, v1l)
    return struct.unpack("2d", t)

def force_float(v):
    return struct.unpack("f", struct.pack("f", v))[0]

PPS It occurred to me to wonder what becomes of special values like inf and
nan, even though we never intend to store them on hal pins:
>>> mix(inf, nan)
(nan, inf)
>>> mix(inf, 3.14)
(3.1399993896484375, nan)
>>> mix(nan, 3.14)
(3.1399993896484375, nan)
so it's interesting to note that an inf can get turned into a nan when this
problem bites.

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to