By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,006 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

Checking for invalid floating point numbers

P: n/a
LSW
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.
Jun 8 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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_limits' 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
Jun 8 '07 #2

P: n/a
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
Jun 8 '07 #3

P: n/a
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

Jun 8 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.