Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Checking for invalid floating point numbers

Reply
Thread Tools

Checking for invalid floating point numbers

 
 
LSW
Guest
Posts: n/a
 
      06-08-2007
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.
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-08-2007
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


 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      06-08-2007
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 <cmath> or <math.h> and 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
 
Reply With Quote
 
Puppet_Sock
Guest
Posts: n/a
 
      06-08-2007
On Jun 8, 12:25 pm, LSW <nospam> wrote:
[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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
checking for close enough floating point values. pereges C Programming 7 05-31-2008 07:24 AM
floating point problem... floating indeed :( teeshift Ruby 2 12-01-2006 01:16 AM
Fixed-point format for floating-point numbers Motaz Saad Java 7 11-05-2005 05:33 PM
When I try to run WinMpg I get a "invalid floating point operation" window ... what now???? Thanks Daveyboy Computer Support 1 10-28-2003 04:58 AM



Advertisments