| 1 |
# exponentf.m4 |
| 2 |
# serial 3 |
| 3 |
dnl Copyright (C) 2007-2008, 2010-2026 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
AC_DEFUN_ONCE([gl_FLOAT_EXPONENT_LOCATION], |
| 9 |
[ |
| 10 |
AC_CACHE_CHECK([where to find the exponent in a 'float'], |
| 11 |
[gl_cv_cc_float_expbit0], |
| 12 |
[ |
| 13 |
AC_RUN_IFELSE( |
| 14 |
[AC_LANG_SOURCE([[ |
| 15 |
#include <float.h> |
| 16 |
#include <stddef.h> |
| 17 |
#include <stdio.h> |
| 18 |
#include <string.h> |
| 19 |
#define NWORDS \ |
| 20 |
((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) |
| 21 |
typedef union { float value; unsigned int word[NWORDS]; } memory_float; |
| 22 |
static unsigned int ored_words[NWORDS]; |
| 23 |
static unsigned int anded_words[NWORDS]; |
| 24 |
static void add_to_ored_words (float x) |
| 25 |
{ |
| 26 |
memory_float m; |
| 27 |
size_t i; |
| 28 |
/* Clear it first, in case |
| 29 |
sizeof (float) < sizeof (memory_float). */ |
| 30 |
memset (&m, 0, sizeof (memory_float)); |
| 31 |
m.value = x; |
| 32 |
for (i = 0; i < NWORDS; i++) |
| 33 |
{ |
| 34 |
ored_words[i] |= m.word[i]; |
| 35 |
anded_words[i] &= m.word[i]; |
| 36 |
} |
| 37 |
} |
| 38 |
int main () |
| 39 |
{ |
| 40 |
size_t j; |
| 41 |
FILE *fp = fopen ("conftest.out", "w"); |
| 42 |
if (fp == NULL) |
| 43 |
return 1; |
| 44 |
for (j = 0; j < NWORDS; j++) |
| 45 |
anded_words[j] = ~ (unsigned int) 0; |
| 46 |
add_to_ored_words (0.25f); |
| 47 |
add_to_ored_words (0.5f); |
| 48 |
add_to_ored_words (1.0f); |
| 49 |
add_to_ored_words (2.0f); |
| 50 |
add_to_ored_words (4.0f); |
| 51 |
/* Remove bits that are common (e.g. if representation of the first mantissa |
| 52 |
bit is explicit). */ |
| 53 |
for (j = 0; j < NWORDS; j++) |
| 54 |
ored_words[j] &= ~anded_words[j]; |
| 55 |
/* Now find the nonzero word. */ |
| 56 |
for (j = 0; j < NWORDS; j++) |
| 57 |
if (ored_words[j] != 0) |
| 58 |
break; |
| 59 |
if (j < NWORDS) |
| 60 |
{ |
| 61 |
size_t i; |
| 62 |
for (i = j + 1; i < NWORDS; i++) |
| 63 |
if (ored_words[i] != 0) |
| 64 |
{ |
| 65 |
fprintf (fp, "unknown"); |
| 66 |
return (fclose (fp) != 0); |
| 67 |
} |
| 68 |
for (i = 0; ; i++) |
| 69 |
if ((ored_words[j] >> i) & 1) |
| 70 |
{ |
| 71 |
fprintf (fp, "word %d bit %d", (int) j, (int) i); |
| 72 |
return (fclose (fp) != 0); |
| 73 |
} |
| 74 |
} |
| 75 |
fprintf (fp, "unknown"); |
| 76 |
return (fclose (fp) != 0); |
| 77 |
} |
| 78 |
]])], |
| 79 |
[gl_cv_cc_float_expbit0=`cat conftest.out`], |
| 80 |
[gl_cv_cc_float_expbit0="unknown"], |
| 81 |
[gl_cv_cc_float_expbit0="word 0 bit 23"]) |
| 82 |
rm -f conftest.out |
| 83 |
]) |
| 84 |
case "$gl_cv_cc_float_expbit0" in |
| 85 |
word*bit*) |
| 86 |
word=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word //' -e 's/ bit.*//'` |
| 87 |
bit=`echo "$gl_cv_cc_float_expbit0" | sed -e 's/word.*bit //'` |
| 88 |
AC_DEFINE_UNQUOTED([FLT_EXPBIT0_WORD], [$word], |
| 89 |
[Define as the word index where to find the exponent of 'float'.]) |
| 90 |
AC_DEFINE_UNQUOTED([FLT_EXPBIT0_BIT], [$bit], |
| 91 |
[Define as the bit index in the word where to find bit 0 of the exponent of 'float'.]) |
| 92 |
;; |
| 93 |
esac |
| 94 |
]) |