s48_ieee_endianness.m4 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ### s48_ieee_endianness.m4 --- S48_IEEE_ENDIANNESS macro -*- Autoconf -*-
  2. # serial 1
  3. dnl
  4. AC_DEFUN([S48_IEEE_ENDIANNESS], [dnl
  5. build_universal="$1"
  6. AC_MSG_CHECKING([IEEE floating-point endianness])
  7. if test "$build_universal" = "1";
  8. then
  9. AC_MSG_RESULT([building Universal Binary; using compiler defined macros instead])
  10. else
  11. AC_TRY_RUN([#include <stdio.h>
  12. #include <inttypes.h>
  13. typedef uint32_t word32_t;
  14. typedef union { double d; word32_t word[2]; } double_overlay;
  15. #define DOUBLE_WORD0(x) ((double_overlay*)&(x))->word[0]
  16. #define DOUBLE_WORD1(x) ((double_overlay*)&(x))->word[1]
  17. int
  18. main(void)
  19. {
  20. double n = 0.3;
  21. /* least significant byte first */
  22. if ((DOUBLE_WORD0(n) == 0x33333333) && (DOUBLE_WORD1(n) == 0x3fd33333))
  23. return 0;
  24. /* most significant byte first */
  25. else if ((DOUBLE_WORD1(n) == 0x33333333) && (DOUBLE_WORD0(n) == 0x3fd33333))
  26. return 1;
  27. else {
  28. fprintf(stderr, "WARNING: unknown IEEE format; assuming IEEE with least significant byte first\n");
  29. return 0;
  30. }
  31. }], ieee_endianness="least first", ieee_endianness="most first", ieee_endianness="least first")
  32. AC_MSG_RESULT([$ieee_endianness])
  33. if test "$ieee_endianness" = "most first"; then
  34. AC_DEFINE([IEEE_MOST_FIRST], 1, [Define if IEEE doubles are stored with most-significant byte first.])
  35. fi
  36. fi
  37. ])dnl
  38. ### s48_ieee_endianness.m4 ends here