Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: float to int (kinda OT)



If you're on a two's-complement CPU (i.e. any modern computer) and you use a reasonably modern compiler, you have nothing to fear... right-shift will sign-extend. The C standard doesn't require it because when the standard was written, there were still some one's-complement CPUs in existence.

Honestly, most people's code would have huge numbers of errors if we ever decided to port it to a one's-complement CPU anyway, so I wouldn't worry about it. If you rely on signed right-shifts, your code WILL work on Intel, PowerPC, 68K, MIPS, and any other CPU that you might want to use. It won't work on a computer from the 60s, but there are probably 20 other valid reasons why it won't work on that 60s computer as well.


On Oct 22, 2004, at 8:05 AM, Holger Bettag wrote:

 There is still a portability problem with the shift,
though, because AFAIK there is no guarantee that rightshifts do the
expected thing with the sign bit on every platform (i.e. some machines
might not implement both signed and unsigned shift primitives, but I
think all do nowadays).

_______________________________________________ Do not post admin requests to the list. They will be ignored. PerfOptimization-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/perfoptimization-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: float to int (kinda OT) (From: Sanjay Patel <email@hidden>)
 >Re: float to int (kinda OT) (From: Holger Bettag <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.