• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Range of 32 bit values
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Range of 32 bit values


  • Subject: Re: Range of 32 bit values
  • From: Greg Guerin <email@hidden>
  • Date: Thu, 5 Apr 2007 22:57:33 -0700

Luigi Castelli wrote:

>I multiply big float values and - after being appropriately cast -
>assign them to the above variable.
>
>Example:
>
>int value = (int)(32768. * 65536.)    // (and bigger)
>
>I just so happens that when the result of the multiplication exceed the
>size of the value that a 32 bit int type variable is able to represent
>the value is clipped to -2147483648. I have noticed that the cast
>(either explicit or implicit) is what causes the value to be clipped,
>because if I cast to a bigger value (i.e. 64 bit) then the value is
>wrapped until the 64 bit maximum is reached. Then the value is clipped
>again.
>
>In any case for the algorithm I am developing I would like the int
>value to be wrapped, not clipped. I would like after reaching the
>value's maximum limit to go back and start again from its minimum.

This seems like a simple answer: don't use float arithmetic.
Only use operands that are 32-bit ints, not floats.

You might also look into the Intel-specific behavior of casting floats to
ints (overrange type-narrowing conversions).  If CodeWarrior-compiled code
wrapped around, it may be a side-effect of the CPU arch (PPC), and not at
all related to CW vs. Xcode.  As I vaguely recall, these kinds of
conversions are unspecified by the C spec, but you really should check a
spec, or just use ints.

  -- GG


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Range of 32 bit values
      • From: Luigi Castelli <email@hidden>
  • Prev by Date: makefile - xcode - C++ macro error
  • Next by Date: Changing the icon
  • Previous by thread: Range of 32 bit values
  • Next by thread: Re: Range of 32 bit values
  • Index(es):
    • Date
    • Thread