473,396 Members | 1,929 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,396 software developers and data experts.

can NAN be assigned?

consider the simplifed code fragment;

enum Endianness
{
BigEndian, ///<BigEndian
LittleEndian,///< LittleEndian
#if defined(BOOST_BIG_ENDIAN)
HostEndianness = BigEndian ///< Current host's Endiannnes.
#elif defined(BOOST_LITTLE_ENDIAN)
HostEndianness = LittleEndian
#else
#error we only supports big and little endian systems.
#endif
};
class ByteWrapper{
public:
template<typename T>
void put(T& t)
{
verify(sizeof t);
memcpy(&_buffer[_pos],reinterpret_cast< unsigned char*>(&t),sizeof
t);
_pos+=sizeof t;
}
template<typename T>
T get()
{
verify(sizeof(T));
T retval;
memcpy(&retval,&_buffer[_pos],sizeof(T));
_pos+=sizeof(T);
return retval;

}
private:
vector<unsigned char_buffer;
size_t _pos;

};
template<typename T,Endianness Endian=LittleEndian>
class HLAgeneric
{
public:
void encode(ByteWrapper& byteWrapper)
{
if (HostEndianness!=Endian)
{
BYTESWAP(_value);
byteWrapper.put<T>(_value);
BYTESWAP(_value);
return;

}
byteWrapper.put<T>(_value);

}
void decode(ByteWrapper& byteWrapper)
{
_value=byteWrapper.get<T>();
if (HostEndianness!=Endian)
{
BYTESWAP(_value);
}

}
private:
T _value;
};
Well, Bytewrapper class is responsible for extracting and inserting
data from a network buffer, the thing is
for some floating point values, the data extracted from the buffer
could be NAN on the host machine(1.QNAN on my platform) because of the
Endianness.HLAgeneric can sort out the Endianness issue.However when i
get<T>() from ByteWrapper the memory representation of the returned
value changes.(it only changes in one bit but that's enough for
malfunction). I think it undergoes to some conversion, but i expected
it to be copied bitwise since the types are the same. What is the
expected behaviour here? Can I assign NAN to another variable ? if
not, how can i approach the problem?. I thought of specializing get
and creating retval on the heap but it won't fit or look good with the
rest of design.

Any pointers would be greatly appreciated...
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 20 '07 #1
1 2335
In article <11*********************@57g2000hsv.googlegroups.c om>,
hurcan solter <hs*****@gmail.comwrote:
Well, Bytewrapper class is responsible for extracting and inserting
data from a network buffer, the thing is
for some floating point values, the data extracted from the buffer
could be NAN on the host machine(1.QNAN on my platform) because of the
Endianness.HLAgeneric can sort out the Endianness issue.However when i
get<T>() from ByteWrapper the memory representation of the returned
value changes.(it only changes in one bit but that's enough for
malfunction). I think it undergoes to some conversion, but i expected
it to be copied bitwise since the types are the same. What is the
expected behaviour here? Can I assign NAN to another variable ? if
not, how can i approach the problem?. I thought of specializing get
and creating retval on the heap but it won't fit or look good with the
rest of design.

Any pointers would be greatly appreciated...
My first suggestion is the format provided by C99's %[aA] format
specifier, a lossless hexidecimal representation of the floating point
number. If you require the client to write in this format and you can
read it then the problem of endianness, non IEE754 format etc are
eliminated at the source.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: anonymousnerd | last post by:
Hi all, In Python, some functions can be assigned to variables like this: length=len Why is it that print cannot be assigned to a variable like this? (A syntax error is declared.) Thanks, ...
4
by: David Sworder | last post by:
With a standard enum, values are automatically assigned. public enum MyEnum{Happy,Sad,Angry,Grandpa}; ....but what about a bitflag enum? public enum MyEnum:int{ FalseTeeth=0x00000001...
8
by: Jason Bell | last post by:
Give the following custom attribute: public class WidgetEventAttribute : System.Attribute { protected Cegui.EventHandler mEventHandler = null; public WidgetEventAttribute( string...
1
by: Glenn | last post by:
Are control IDs dynamically assigned each time a page loads for .NET controls? So, if there's a text box which has been assigned the ID "_ctl0_txtName" and I refer to that name in javascript,...
2
by: Andrew Backer | last post by:
I have a series of class variables that are assigned to through reflection. Every time I compile one of these classes I get this warning : warning CS0649: Field 'xxx' is never assigned to, and...
2
by: hui | last post by:
Here is a problem I am having with web form designer. I have a database control in the form, and setup the connection string as a dynamic property. It compiles and runs fine. I close the aspx...
5
by: Mats Larsson | last post by:
Hi, I have an example in C# for testing if a handler has been assigned to the delegate, I would like to do the same in VB.NET but I don't understand how. The C# code is copied from the Northwind...
4
by: Brian Henry | last post by:
I want to tell if a date is invaid (not assigned yet) right now i am doing this dim aDate as datetime if aDate.date = #12:00:00 AM# ' not assigned else
3
by: nd3r | last post by:
I have a problem in my code. Let's say we have a variable named X, and X must be tested if any value is assigned to it, and if not, then X is assigned. I need to tell you that X is in fact a...
3
by: emalcolm_FLA | last post by:
Hello and Thanks in advance for any help. I have been tasked with rewriting a christmas assistance database using Access 2003. The old system used pre-assigned case numbers to identify...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.