• 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: Kyle Sluder <email@hidden>
  • Date: Tue, 5 Oct 2010 08:20:35 -0700

On Tue, Oct 5, 2010 at 8:16 AM, Shawn Bakhtiar <email@hidden> wrote:
>
>
> Eh?
>
> Did you just call typecasting  "*completely* unnecessary and pointless"...

No, he called the specific casting you were performing unnecessary and
pointless, which it is.

The arithmetic conversion rules say that the integer literals will be
promoted to the appropriate floating point type. So this is perfectly
fine and does exactly what you expect:

int main(int argc, char **argv) {
  float x = 2.5;
  x += 5;
  printf("%f\n", x); // prints "7.500000"
  return 0;
}

--Kyle Sluder
_______________________________________________

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

  • Follow-Ups:
    • Re: Confused about floats
      • From: Kyle Sluder <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: Confused about floats
  • Previous by thread: RE: Confused about floats
  • Next by thread: Re: Confused about floats
  • Index(es):
    • Date
    • Thread