473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Checking for invalid floating point numbers

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
3 3679
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon Reye | last post by:
Is there a way to force a floating point value to be invalid? I'm reading floating points from a device and every now and then I get an invalid number, but it is too few and far between for me to...
4
by: Dave | last post by:
Hi folks, I am trying to develop a routine that will handle sphere-sphere and sphere-triangle collisions and interactions. My aim is to develop a quake style collision engine where a player can...
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
10
by: Shawn | last post by:
Hello all, I apologize as I am sure this has probably been dealth with before... but I am doing an exercise from "Practical C Programming" and I have been unable to get it to work perfectly due to...
21
by: Allin Cottrell | last post by:
OK, I realize that what I am asking here is not likely to have a answer within the C standard. Nonetheless, it is not specific to any particular platform, so I'll hazard the question anyway. A...
7
by: Vinoth | last post by:
I'm working in an ARM (ARM9) system which does not have Floating point co-processor or Floating point libraries. But it does support long long int (64 bits). Can you provide some link that would...
15
by: michael.mcgarry | last post by:
Hi, I have a question about floating point precision in C. What is the minimum distinguishable difference between 2 floating point numbers? Does this differ for various computers? Is this...
32
by: ma740988 | last post by:
template <class T> inline bool isEqual( const T& a, const T& b, const T epsilon = std::numeric_limits<T>::epsilon() ) { const T diff = a - b; return ( diff <= epsilon ) && ( diff >= -epsilon );...
4
by: H.S. | last post by:
Hello, I am trying out a few methods with which to test of a given number is practically zero. as an example, does the following test correctly if a given number is zero within machine...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.