Checking for invalid floating point numbers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • LSW

    Checking for invalid floating point numbers

    I'm using Borland Turbo C++ 3.0 to develop an embedded system to shift
    data around a network. At the moment we receive a string of bytes over a
    serial line and reassemble them into floating point values.

    If the bytes are not assembled correctly then it's possible to produce
    some floating point values that aren't 'genuine' numbers. Does anyone
    have any suggestions on how to check a float/double is valid (i.e.
    checking for NANs, infinity etc.)?

    Turbo C++ doesn't seem to have much support for this.

    Thanks,
    --
    L.
  • Victor Bazarov

    #2
    Re: Checking for invalid floating point numbers

    LSW wrote:
    I'm using Borland Turbo C++ 3.0 to develop an embedded system to shift
    data around a network. At the moment we receive a string of bytes
    over a serial line and reassemble them into floating point values.
    >
    If the bytes are not assembled correctly then it's possible to produce
    some floating point values that aren't 'genuine' numbers. Does anyone
    have any suggestions on how to check a float/double is valid (i.e.
    checking for NANs, infinity etc.)?
    Implementation-specific stuff. Ask in the newsgroup for your compiler.
    The IEEE 754 specification leaves very little to interpretation. If
    the system for which you're programming supports it, you can make the
    checking yourself.
    Turbo C++ doesn't seem to have much support for this.
    <shrug The standard has 'std::numeric_l imits' that do include the
    stuff like 'infinity' or 'isNaN' or some such, RTFM. If your compiler
    doesn't implement them it's either non-compliant, or that stuff is
    implementation-specific (allowed not to be implemented), or both.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    • =?ISO-8859-1?Q?Erik_Wikstr=F6m?=

      #3
      Re: Checking for invalid floating point numbers

      On 2007-06-08 18:25, LSW wrote:
      I'm using Borland Turbo C++ 3.0 to develop an embedded system to shift
      data around a network. At the moment we receive a string of bytes over a
      serial line and reassemble them into floating point values.
      >
      If the bytes are not assembled correctly then it's possible to produce
      some floating point values that aren't 'genuine' numbers. Does anyone
      have any suggestions on how to check a float/double is valid (i.e.
      checking for NANs, infinity etc.)?
      >
      Turbo C++ doesn't seem to have much support for this.
      Include <cmathor <math.hand use isnan(), isinf(), etc.

      By they way, I don't know much about Borland compilers but isn't 3.0
      quite old? It might be worthwhile to look into upgrading.

      --
      Erik Wikström

      Comment

      • Puppet_Sock

        #4
        Re: Checking for invalid floating point numbers

        On Jun 8, 12:25 pm, LSW <nospamwrote:
        [snip]
        Does anyone
        have any suggestions on how to check a float/double is valid (i.e.
        checking for NANs, infinity etc.)?
        Other than what Victor said (which was great) I have
        a couple thoughts.

        How do you know that the transmitted data isn't actually
        a NAN etc.? Is it impossible for such things to get pushed
        into the other end of the pipe? So, if you reject a NAN,
        maybe you are rejecting the intended data.

        What about some sort of CRC or other similar check? That
        would be appropriate for some length of message chunks.
        They get packaged somehow at that end, then reassembled
        at this end, and the CRC checked.
        Socks

        Comment

        Working...