public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Float to Int Conversions
@ 2002-02-26  8:14 Stephen Pisuk
  2002-02-26  8:38 ` John Love-Jensen
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Pisuk @ 2002-02-26  8:14 UTC (permalink / raw)
  To: gcc-help

Hello,

I have a question regarding the conversion of floats
to integers. The problem is that GCC (version 2.95
3.0.2)  produce different results than Microsoft's Visual Studio
6.0.  First of all, its a matter of who is right, and then
second can they be made consistent.


For example
double x = pow(2,32) + 10;
unsigned int    y = ((unsigned int) x);

Under MS VS y = 10
however under linux with GCC y=2^31 or 0x80000000

I assume the difference is in how the FPU control
word is set with the various error masks.

Is there any way so alter the functionality of GCC
to produce the first result?

Any help would be greatly appreciated. We write code
under both platforms, and its less of an issue of who
is right or wrong, but rather consistency.

Thanks
__________________________________________________
Stephen Pisuk
MIT Lincoln Laboratory, Room C-472
244 Wood St., Lexington, MA   02420-9108
voice: (781)-981-3682   fax: (781)-981-4583
e-mail:   smp@ll.mit.edu


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

* Re: Float to Int Conversions
  2002-02-26  8:14 Float to Int Conversions Stephen Pisuk
@ 2002-02-26  8:38 ` John Love-Jensen
  2002-02-26  8:42   ` Stephen Pisuk
  2002-02-26  9:35   ` building on MacOS 10.1.3? sbloch
  0 siblings, 2 replies; 5+ messages in thread
From: John Love-Jensen @ 2002-02-26  8:38 UTC (permalink / raw)
  To: Stephen Pisuk; +Cc: gcc-help

Hi Stephen,

Have you set IEEE 754 compliance on both compilers?

GCC -ffloat-store

I don't know what MSVC uses.

--Eljay


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

* Re: Float to Int Conversions
  2002-02-26  8:38 ` John Love-Jensen
@ 2002-02-26  8:42   ` Stephen Pisuk
  2002-02-26 11:11     ` John Love-Jensen
  2002-02-26  9:35   ` building on MacOS 10.1.3? sbloch
  1 sibling, 1 reply; 5+ messages in thread
From: Stephen Pisuk @ 2002-02-26  8:42 UTC (permalink / raw)
  To: John Love-Jensen; +Cc: gcc-help

No I had not, but it didn't help

If the result of the conversion is an INT
the conversion saturates at 0x80000000
however if the result is an UNSIGNED INT
the conversion is correct;


> Hi Stephen,
>
> Have you set IEEE 754 compliance on both compilers?
>
> GCC -ffloat-store
>
> I don't know what MSVC uses.
>
> --Eljay
>
>

__________________________________________________
Stephen Pisuk
MIT Lincoln Laboratory, Room C-472
244 Wood St., Lexington, MA   02420-9108
voice: (781)-981-3682   fax: (781)-981-4583
e-mail:   smp@ll.mit.edu


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

* building on MacOS 10.1.3?
  2002-02-26  8:38 ` John Love-Jensen
  2002-02-26  8:42   ` Stephen Pisuk
@ 2002-02-26  9:35   ` sbloch
  1 sibling, 0 replies; 5+ messages in thread
From: sbloch @ 2002-02-26  9:35 UTC (permalink / raw)
  To: gcc-help

I'm not sure if this message got to the list when I tried it before.

I just upgraded my Mac to MacOS 10.1.3.  I downloaded the standard
developer package from Apple, including "make", "cc", etc. but I've
been unable to build GNU make, gcc, et al.

GNU make: I get compiler errors on the source file gettext.c because
LC_MESSAGES is undefined.  It's referred to in some places, protected by
an #ifdef LC_MESSAGES, but in other places there is no such protection.

GCC: I get compiler errors on the source file function.c because
DEFAULT_ABI is undefined.  I haven't poked around to see what's going
on here.

Any suggestions?  I have no idea what these symbols are supposed to
mean, so I'm hesitant to go around defining them myself.

-- 
                                                 Stephen Bloch
                                               sbloch@adelphi.edu
                                         http://www.adelphi.edu/sbloch/
                                        Math/CS Dept, Adelphi University

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

* Re: Float to Int Conversions
  2002-02-26  8:42   ` Stephen Pisuk
@ 2002-02-26 11:11     ` John Love-Jensen
  0 siblings, 0 replies; 5+ messages in thread
From: John Love-Jensen @ 2002-02-26 11:11 UTC (permalink / raw)
  To: Stephen Pisuk; +Cc: gcc-help

Hi Stephen,

According to C++ Programming Language by Stroustrup, section C.6.2.6 --
the behavior is UNDEFINED (implementation dependent) if the truncated
value cannot be represented in the destionation type.

Not what you wanted to hear.  If you want consistent behavior, you'll
have to write a helper subroutine that catches the boundary cases.

--Eljay


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

end of thread, other threads:[~2002-02-26 17:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-26  8:14 Float to Int Conversions Stephen Pisuk
2002-02-26  8:38 ` John Love-Jensen
2002-02-26  8:42   ` Stephen Pisuk
2002-02-26 11:11     ` John Love-Jensen
2002-02-26  9:35   ` building on MacOS 10.1.3? sbloch

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).