/****************************************************************************** $Id: swapfloat.c,v 1.1 2013/02/14 16:58:03 pascal Exp $ *****************************************************************************/ #include #include "config.h" #include "EndianSwap/swapfloat.h" #include "EndianSwap/swapint.h" #include "EndianSwap/swap.h" /****************************************************************************** ES_swap_float ############### Swap a float value from big-endian representation to little-endian IN: const float *val : pointer to the float value represented as big-endian RETURN: float : float value represented as little-endian. *****************************************************************************/ float ES_swap_float(const float * val) { #if SIZEOF_FLOAT == SIZEOF_INT int tmp_int; float tmp_float; tmp_int = ES_swap_int((int*)val); tmp_float = *((float*)&tmp_int); return tmp_float; #elif SIZEOF_FLOAT == SIZEOF_SHORT short tmp_short; float tmp_float; tmp_short = ES_swap_short((int*)val); tmp_float = *((float*)&tmp_short); return tmp_float; #else float tmp_float = *val; ES_swap(&tmp_float, SIZEOF_FLOAT); return tmp_float; #endif } /****************************************************************************** ES_swap_double ############### Swap a double value from big-endian representation to little-endian IN: const double *val : pointer to the double value represented as big-endian RETURN: double : double value represented as little-endian. *****************************************************************************/ double ES_swap_double(const double * val) { #if SIZEOF_DOUBLE == SIZEOF_INT int tmp_int; double tmp_double; tmp_int = ES_swap_int((int*)val); tmp_double = *((double*)&tmp_int); return tmp_double; #elif SIZEOF_DOUBLE == SIZEOF_SHORT short tmp_short; double tmp_double tmp_short = ES_swap_short((int*)val); tmp_double = *((double*)&tmp_short); return tmp_double; #else double tmp_double = *val; ES_swap(&tmp_double, SIZEOF_DOUBLE); return tmp_double; #endif }