Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Jan 2000 15:49:09 +0100
From:      Martin Cracauer <cracauer@cons.org>
To:        Kelly Yancey <kbyanc@posi.net>
Cc:        Martin Cracauer <cracauer@cons.org>, Markus Holmberg <saska@acc.umu.se>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: Should -mieee-fp equal fpsetmask(0) to avoid SIGFPE on FreeBSD?
Message-ID:  <20000104154909.A5444@cons.org>
In-Reply-To: <Pine.BSF.4.05.10001040934070.32954-100000@kronos.alcnet.com>; from kbyanc@posi.net on Tue, Jan 04, 2000 at 09:36:59AM -0500
References:  <20000104121459.A8959@cons.org> <Pine.BSF.4.05.10001040934070.32954-100000@kronos.alcnet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In <Pine.BSF.4.05.10001040934070.32954-100000@kronos.alcnet.com>, Kelly Yancey wrote: 
> > 
> > #include <stdio.h>
> > #include <limits.h>
> > #include <floatingpoint.h>
> > 
> > int main(void)
> > {
> >   double bla;
> >   int foo;
> > 
> >   fpsetmask(0);
> >   bla = (double)INT_MAX + 1.0;
> >   foo = bla;
> > 
> >   printf("Result: %d\n", foo);
> > 
> >   return 0;
> > }
> > 
> > Result: -2147483648
> > 
> > 
> 
>   Actually, this the same value (INT_MIN = -2147483648) you would get if
> you just said foo = INT_MAX + 1 since in 2's complement notation INT_MIN =
> INT_MAX + 1. 

Try
  bla = (double)INT_MAX * 13.0;

>It definately isn't garbage.

No, you're mislead by my example that happens to choose a value
combination that *looks* explainable. It in reality the results of
float->int conversions without range check are neither explainable nor
can you depend on them. They are just garbage when you disabled
exceptions. 

You can draw some conclusions what happens on integer aritmetic
overflows (when you know the size of the operands). That is very
different from the float->int conversion results, which do not behave
in the usual integer overflow manner (although my first example looked
like they would).

Martin
-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer/
  Tel.: (private) +4940 5221829 Fax.: (private) +4940 5228536


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000104154909.A5444>