Boost logo

Boost :

Subject: Re: [boost] [boost::endian] Summary of discussion #1
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-06-02 13:23:43


Tomas Puverle wrote:
>
> Unanswered question:

No opinion.

> Beside the two functions swap<>() and swap_in_place<>(),

Your swap<>() takes a value and converts it to another of the same type, but endian swapped. That looks a lot like a cast, though the type doesn't change in your design, so naming it something like "endian_cast" is not unreasonable. If you pick up my ideas for allowing the input and output types to change, within limits, then it looks even more like a cast.

I still dislike the name "swap_in_place." If you agree to "endian_cast," then this is easy: rename swap_in_place<>() to "swap." Otherwise, swap_in_place<>() could be named "swap" while your swap<>() could be named something like "swapped_copy." IOW, the more efficient function should be the one to encourage and the other should emphasize the casting or copying nature of the operation in its longer name.

> Floating point values:
> There is a potential issue with swapping floating point
> values. This will be resolved by limiting the contexts in
> which swap<>, from<> and to<> can be used.

That's certainly the easiest solution. I wonder if there are papers on this subject.

According to Wikipedia:

"On some machines, while integers were represented in little-endian form, floating point numbers were represented in big-endian form. Because there are many floating point formats, and a lack of a standard "network" representation, no standard for transferring floating point values has been made. This means that floating point data written on one machine may not be readable on another, and this is the case even if both use IEEE 754 floating point arithmetic since the endianness of the memory representation is not part of the IEEE specification."

An interesting discussion of some points raised here, but has merit for deciding whether and how to support floating point swapping: <http://www.dmh2000.com/cpp/dswap.shtml>.

>From the latter, there is room to consider using a class template to manage an appropriate integer type to hold a swapped floating point value and have the swap functions return that when swapping floating point values. The reverse is also possible if the swapping functions recognize the intermediate swapped type on input and return the corresponding floating point type.

That is, something like the following might be possible:

   template <class E, class T>
   typename swapped_floating_point<T>
   endian_cast(T);

   template <class E, class T>
   T
   endian_cast(typename swapped_floating_point<T>);

(with suitable additional line noise to ensure that T is a floating point type.)

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk