• 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: Confused about floats
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Confused about floats


  • Subject: Re: Confused about floats
  • From: Velocityboy <email@hidden>
  • Date: Tue, 5 Oct 2010 08:26:08 -0700

Both C and Objective-C support implicit casting for the primitive types.

float f = 100.0f;
f += 100;

will give the expected result, because the compiler will see (float) + (int) and cast the int to a float automatically. The conversion rules are part of the ANSI C standard and apply in Objective-C as well. Any modern compiler will also warn if you use an implicit conversion that could result in a loss of precision.
On Oct 5, 2010, at 8:16 AM, Shawn Bakhtiar wrote:

>
>
> Eh?
>
> Did you just call typecasting  "*completely* unnecessary and pointless"...
>
> Can you please explain?
>
> I have plenty of C code, in *.c files that would disagree with you.
>
> You may be correct in that in Objective-C this may no longer be an issue, as the compiler does your work for you, but that was not an assumption I was making.
>
>> Subject: Re: Confused about floats
>> From: email@hidden
>> Date: Tue, 5 Oct 2010 08:56:45 -0600
>> CC: email@hidden
>> To: email@hidden
>>
>> On Oct 5, 2010, at 8:51 AM, Shawn Bakhtiar wrote:
>>
>>> Also if x is a float, make sure you use the proper type cast, or values, ie  ( x = x + 120.00) or (x = y + (double)z , where x and y are double and z is an int).
>>
>> That is *completely* unnecessary and pointless.
>>
>> --
>> Scott Ribe
>> email@hidden
>> http://www.elevated-dev.com/
>> (303) 722-0567 voice
>>
>>
>>
>>
> 		 	   		  _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Confused about floats (From: Gregory Weston <email@hidden>)
 >RE: Confused about floats (From: Shawn Bakhtiar <email@hidden>)
 >Re: Confused about floats (From: Scott Ribe <email@hidden>)
 >RE: Confused about floats (From: Shawn Bakhtiar <email@hidden>)

  • Prev by Date: Re: Confused about floats
  • Next by Date: Re: Unable to play a .mp3 file directly using QTMovie
  • Previous by thread: Re: Confused about floats
  • Next by thread: Re: Confused about floats
  • Index(es):
    • Date
    • Thread