From: Satoshi Nakagawa Date: 2007-08-23T20:06:22+09:00 Subject: [ruby-dev:31623] Re: strtod の精度 --Apple-Mail-16--893429749 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-2022-JP 中川です。 strtod の件で追加です。 gcc のソースを確認したところ、Mac OS X でしか __BIG_ENDIAN__ を define してくれないようなので、CPU ごとのエンディアン判定を わかる範囲で追加しました。 また、Win32 環境の判定がコンパイラ限定でうまくないので、型判定に 統合しました。 -- Satoshi Nakagawa http://d.hatena.ne.jp/Psychs/ --Apple-Mail-16--893429749 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name=utilc_endian.patch Content-Disposition: attachment; filename=utilc_endian.patch Index: util.c =================================================================== --- util.c (revision 13236) +++ util.c (working copy) @@ -814,6 +814,37 @@ * the result overflows to +-Infinity or underflows to 0. */ +#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) + +/* PA-RISC */ +#if defined(__hppa__) || defined(__hppa) +#define __BIG_ENDIAN__ +#endif + +/* MIPS */ +#if defined(_MIPSEB) || defined(MIPSEB) +#define __BIG_ENDIAN__ +#elif defined(_MIPSEL) || defined(MIPSEL) +#define __LITTLE_ENDIAN__ +#endif + +/* Motorola 68000 */ +#if defined(__mc68000__) || defined(mc68000) +#define __BIG_ENDIAN__ +#endif + +/* Power PC */ +#if defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) || defined(__ppc) || defined(_M_PPC) +#define __BIG_ENDIAN__ +#endif + +/* SPARC */ +#if defined(__sparc__) || defined(__sparc) || defined(sparc) +#define __BIG_ENDIAN__ +#endif + +#endif + #ifdef __BIG_ENDIAN__ #define IEEE_BIG_ENDIAN #else @@ -834,7 +865,14 @@ #undef Long #undef ULong -#if SIZEOF_INT == 4 +#if defined(__int32) +#define Long __int32 +#define ULong unsigned __int32 +#if defined(__int64) +#define Llong __int64 +#define ULLong unsigned __int64 +#endif +#elif SIZEOF_INT == 4 #define Long int #define ULong unsigned int #elif SIZEOF_LONG == 4 @@ -842,12 +880,6 @@ #define ULong unsigned long int #endif -#if defined(_MSC_VER) || defined(__BORLANDC__) -#define Long __int32 -#define ULong unsigned __int32 -#define IEEE_LITTLE_ENDIAN -#endif - #ifdef DEBUG #include "stdio.h" #define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);} @@ -927,7 +959,7 @@ #endif #if defined(IEEE_LITTLE_ENDIAN) + defined(IEEE_BIG_ENDIAN) + defined(VAX) + defined(IBM) != 1 -Exactly one of IEEE_LITTLE_ENDIAN, IEEE_BIG_ENDIAN, VAX, or IBM should be defined. +#error "Exactly one of IEEE_LITTLE_ENDIAN, IEEE_BIG_ENDIAN, VAX, or IBM should be defined." #endif typedef union { double d; ULong L[2]; } U; --Apple-Mail-16--893429749 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII --Apple-Mail-16--893429749--