unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* gcc optimisation breaks guile floating point
@ 2002-08-27 21:10 Gary Houston
  2002-08-27 22:30 ` Han-Wen Nienhuys
  0 siblings, 1 reply; 12+ messages in thread
From: Gary Houston @ 2002-08-27 21:10 UTC (permalink / raw)


Floating point seems somewhat broken in latest CVS if compiled with
recent gcc (e.g., version 3.2):

guile> 3.2
0.0

The problem is in libguile/numbers.c:scm_make_real, and only if
scm_double_cell is inlined (so it isn't a problem in Guile 1.5).

Compiling with the -fno-strict-aliasing option fixes it.  Here's a
similar kind of problem code:

#include <stdlib.h>
#include <string.h>

static void * make_z (double x)
{
  void *z = malloc (50);

  memset (z, 0, 50);
  *((unsigned long *) z) = 0;
  *((double *) z) = x;
  return z;
}

main ()
{
  void *z = make_z (3.2);
  double d = *((double *) z);
  int i;

  for (i = 0; i < sizeof (double); i++)
    {
      printf ("%d\n", ((unsigned char *) &d)[i]);
    }
  return 0;
}

Apparently, "according to ANSI C" (no direct quotation available), the
compiler can assume that *((unsigned long *) z) and *((double *) z)
refer to different locations and reorder the statements!

I don't know what would be needed to make Guile conform to such
stringent interpretation of the standard, but I don't think it would
be easy to determine that it was correct and that it would always stay
that way.  Perhaps we should just add the -fno-strict-aliasing option
if the compiler supports it?



_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2002-10-03 12:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-27 21:10 gcc optimisation breaks guile floating point Gary Houston
2002-08-27 22:30 ` Han-Wen Nienhuys
2002-08-28 20:26   ` Marius Vollmer
2002-08-28 22:53     ` Han-Wen Nienhuys
2002-08-30 17:44       ` Gary Houston
2002-09-05 21:10         ` Han-Wen Nienhuys
2002-09-12  1:46           ` Carl R. Witty
2002-09-13 21:20             ` Han-Wen Nienhuys
2002-09-24 22:32             ` Gary Houston
     [not found]             ` <200209242233.PAA04201@onyx.he.net>
2002-10-02 22:40               ` Marius Vollmer
2002-10-02 23:34                 ` Gary Houston
     [not found]                 ` <200210022336.QAA18265@onyx.he.net>
2002-10-03 12:33                   ` Marius Vollmer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).