Wiselib
Public Types | Static Public Member Functions | Static Public Attributes
wiselib::FpSerialization< OsModel_P, WISELIB_LITTLE_ENDIAN, BlockData_P, double, 4 > Struct Template Reference

#include <floating_point.h>

List of all members.

Public Types

typedef OsModel_P OsModel
typedef BlockData_P BlockData
typedef double Type
typedef OsModel::size_t size_t

Static Public Member Functions

static size_t write (BlockData *target, Type &value)
 When a 4-byte double value is written, it is automatically transformed into an 8-byte one (as expected when dealing with double-precision floating points).
static Type read (BlockData *target)
 When a 4-byte double value is written, it is automatically transformed into an 8-byte one (as expected when dealing with double-precision floating points).

Static Public Attributes

static const int Size = 4

template<typename OsModel_P, typename BlockData_P>
struct wiselib::FpSerialization< OsModel_P, WISELIB_LITTLE_ENDIAN, BlockData_P, double, 4 >


Member Typedef Documentation

template<typename OsModel_P , typename BlockData_P >
typedef BlockData_P wiselib::FpSerialization< OsModel_P, WISELIB_LITTLE_ENDIAN, BlockData_P, double, 4 >::BlockData
template<typename OsModel_P , typename BlockData_P >
typedef OsModel_P wiselib::FpSerialization< OsModel_P, WISELIB_LITTLE_ENDIAN, BlockData_P, double, 4 >::OsModel
template<typename OsModel_P , typename BlockData_P >
typedef OsModel::size_t wiselib::FpSerialization< OsModel_P, WISELIB_LITTLE_ENDIAN, BlockData_P, double, 4 >::size_t
template<typename OsModel_P , typename BlockData_P >
typedef double wiselib::FpSerialization< OsModel_P, WISELIB_LITTLE_ENDIAN, BlockData_P, double, 4 >::Type

Member Function Documentation

template<typename OsModel_P , typename BlockData_P >
static Type wiselib::FpSerialization< OsModel_P, WISELIB_LITTLE_ENDIAN, BlockData_P, double, 4 >::read ( BlockData target) [inline, static]

When a 4-byte double value is written, it is automatically transformed into an 8-byte one (as expected when dealing with double-precision floating points).

Therefore, +------+------+------+------+------+------+------+------+ |byte 0|byte 1|byte 2|byte 3|byte 4|byte 5|byte 6|byte 7| S| E | F | +------+------+------+------+------+------+------+------+ 1|<--11-->|<-----------------52 bits------------------->| <-----------------------64 bits-------------------------> DOUBLE-PRECISION FLOATING-POINT must be shrunk to +-------+-------+-------+-------+ |byte 0 |byte 1 |byte 2 |byte 3 | SINGLE-PRECISION S| E | F | FLOATING-POINT NUMBER +-------+-------+-------+-------+ 1|<- 8 ->|<-------23 bits------>| <------------32 bits------------>

This works as follows:

  • S (sign bit) is copied
  • Bit 0 of E is copied
  • Bits 1..3 of E are skipped
  • Bits 4..10 of E are copied (resulting in 8 bits)
  • Copy the first 23 bits of F; skip the rest

However, since source F starts at bit 9, it requires a lot bit shifting, especially because of the additional transformation from little to big endian :(

template<typename OsModel_P , typename BlockData_P >
static size_t wiselib::FpSerialization< OsModel_P, WISELIB_LITTLE_ENDIAN, BlockData_P, double, 4 >::write ( BlockData target,
Type value 
) [inline, static]

When a 4-byte double value is written, it is automatically transformed into an 8-byte one (as expected when dealing with double-precision floating points).

Therefore, +-------+-------+-------+-------+ |byte 0 |byte 1 |byte 2 |byte 3 | SINGLE-PRECISION S| E | F | FLOATING-POINT NUMBER +-------+-------+-------+-------+ 1|<- 8 ->|<-------23 bits------>| <------------32 bits------------> must be expanded to +------+------+------+------+------+------+------+------+ |byte 0|byte 1|byte 2|byte 3|byte 4|byte 5|byte 6|byte 7| S| E | F | +------+------+------+------+------+------+------+------+ 1|<--11-->|<-----------------52 bits------------------->| <-----------------------64 bits-------------------------> DOUBLE-PRECISION FLOATING-POINT

This works as follows:

  • S (sign bit) is directly copied
  • Bit 1 of source E is directly copied
  • If Bit 1 of source E is 1, copy 000 target E else if Bit 1 of source E is 0, copy 000 target E
  • Copy the rest of the bits of E
  • At last, the source F is directly copied to the beginning of target F, with the rest of the target set to 0

However, since source F starts at bit 9, it requires a lot bit shifting, especially because of the additional transformation from little to big endian :(


Member Data Documentation

template<typename OsModel_P , typename BlockData_P >
const int wiselib::FpSerialization< OsModel_P, WISELIB_LITTLE_ENDIAN, BlockData_P, double, 4 >::Size = 4 [static]

The documentation for this struct was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines