Floating-point and endianness
On some machines, while integers were represented in little-endianform, floating-point numbers were represented in big-endian form. [3]Because there are many floating formats, and a lack of a standard"network" representation, no standard for transferring floating pointvalues has been made. This means that floating point data written onone machine may not be readable on another, and this is the case evenif both use IEEE 754 floating point arithmetic since the endian-ness of the memory representation is not part of the IEEE specification. [4]
http://en.wikipedia.org/wiki/Endianness#Floating-point_and_endianness
Floating point의 endian(byte order)는 IEEE 표준에서 정의하고 있지 않아서 같은 IEEE 실수 표현을 사용하는 system 사이에서도 memory representaion이 다를 수 있다고 한다.
그럼 이기종 사이에서 floating point data를 공유하려면 ascii text로 기록 또는 전송하는 방법 외에는 뾰족한 방법이 없을것 같다. 만약 network 전송이라면 XDR도 한 가지 방법일 것이고..
-추가-
ASCII test로 변환해서 전송하거나 기록한 후 다시 float로 변환하는 과정에서 오차가 발생했다. 그래서 configure script에서 float가 어떤 endian으로 저장되는지 직접 확인하고 기록할 때는 big endian으로 변환하도록 구현했다.
아래는 configure script 내용이다.
AC_TRY_RUN([
#include <stdio.h>
union test {
float f;
unsigned char c[sizeof(float)];
};
int main(void)
{
union test t;
t.f = -1;
if (t.c[0] != 0)
return 1;
return 0;
}], [AC_MSG_RESULT(no)],
[AC_MSG_RESULT(yes); AC_DEFINE([FLOAT_BIG_ENDIAN], [1], [Big endian floating point system])])

comments
comments rss (+댓글 쓰러가기)