BRL-CAD
#include "common.h"
#include <stdio.h>
#include <assert.h>
#include "bu/cv.h"
#include "bu/endian.h"
#include "bu/log.h"
Include dependency graph for htond.c:

Go to the source code of this file.

Macros

#define OUT_IEEE_ZERO
 
#define OUT_IEEE_NAN
 

Functions

void bu_cv_htond (register unsigned char *out, register const unsigned char *in, size_t count)
 
void bu_cv_ntohd (register unsigned char *out, register const unsigned char *in, size_t count)
 

Detailed Description

Convert doubles to host/network format.

Library routines for conversion between the local host 64-bit ("double precision") representation, and 64-bit IEEE double precision representation, in "network order", i.e., big-endian, the MSB in byte [0], on the left.

As a quick review, the IEEE double precision format is as follows: sign bit, 11 bits of exponent (bias 1023), and 52 bits of mantissa, with a hidden leading one (0.1 binary).

When the exponent is 0, IEEE defines a "denormalized number", which is not supported here.

When the exponent is 2047 (all bits set), and: all mantissa bits are zero, value is infinity*sign, mantissa is non-zero, and: msb of mantissa=0: signaling NAN msb of mantissa=1: quiet NAN

Note that neither the input or output buffers need be word aligned, for greatest flexibility in converting data, even though this imposes a speed penalty here.

These subroutines operate on a sequential block of numbers, to save on subroutine linkage execution costs, and to allow some hope for vectorization.

On brain-damaged machines like the SGI 3-D, where type "double" allocates only 4 bytes of space, these routines still return 8 bytes in the IEEE buffer.

Definition in file htond.c.

Macro Definition Documentation

#define OUT_IEEE_ZERO
Value:
{ \
*out++ = 0; \
*out++ = 0; \
*out++ = 0; \
*out++ = 0; \
*out++ = 0; \
*out++ = 0; \
*out++ = 0; \
*out++ = 0; \
continue; \
}
goto out
Definition: nmg_mod.c:3846

Definition at line 33 of file htond.c.

Referenced by bu_cv_htond().

#define OUT_IEEE_NAN
Value:
{ /* Signaling NAN */ \
*out++ = 0xFF; \
*out++ = 0xF0; \
*out++ = 0x0B; \
*out++ = 0xAD; \
*out++ = 0x0B; \
*out++ = 0xAD; \
*out++ = 0x0B; \
*out++ = 0xAD; \
continue; \
}
goto out
Definition: nmg_mod.c:3846

Definition at line 46 of file htond.c.

Referenced by bu_cv_htond().

Function Documentation

void bu_cv_htond ( register unsigned char *  out,
register const unsigned char *  in,
size_t  count 
)

Definition at line 60 of file htond.c.

References BU_BIG_ENDIAN, bu_bomb(), bu_byteorder(), BU_LITTLE_ENDIAN, OUT_IEEE_NAN, OUT_IEEE_ZERO, and SIZEOF_NETWORK_DOUBLE.

Here is the call graph for this function:

void bu_cv_ntohd ( register unsigned char *  out,
register const unsigned char *  in,
size_t  count 
)

Definition at line 366 of file htond.c.

References BU_BIG_ENDIAN, bu_bomb(), bu_byteorder(), BU_LITTLE_ENDIAN, and SIZEOF_NETWORK_DOUBLE.

Here is the call graph for this function: