Re: CGFloat and literal floats in Swift
Re: CGFloat and literal floats in Swift
- Subject: Re: CGFloat and literal floats in Swift
- From: Tim Fletcher <email@hidden>
- Date: Mon, 27 Jul 2015 05:58:29 +0000
Slightly off topic; I would love to see some form of what Scala calls
implicits in swift. For exactly this reason.
On Mon, 27 Jul 2015 05:10 Rick Mann <email@hidden> wrote:
>
> > On Jul 26, 2015, at 20:57 , Jens Alfke <email@hidden> wrote:
> >
> >
> >> On Jul 26, 2015, at 4:50 PM, Quincey Morris <
> email@hidden> wrote:
> >>
> >> No. Swift doesn’t convert between numeric types automatically, so
> Double —> CGFloat produces an error.
> >
> > I’m guessing this is only a problem when building 32-bit? Because in
> 64-bit, CGFloat is equivalent to Double, so there shouldn’t be a problem
> there.
>
> I don't think this is a 32- vs 64-bit issue. For example, both of these
> fail:
>
> let f : CGFloat = Float(1.0)
> let g : CGFloat = Double(1.0)
>
> > Rick: You could just define your own CGFloat constant equal to M_PI.
> (You could even name it π …!)
>
> I guess, but that's not really the problem. I think it would not be
> unusual for code in one place to produce Double (or other arithmetic type)
> values that you then want to pass to CG. But you have to explicitly convert
> them. Seems very clunky to me. I prefer C's approach where a conversion
> that doesn't lose data is allowed, and you can turn on warnings for ones
> that might lose data.
>
> >
> > —Jens
> > _______________________________________________
> >
> > 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
>
>
> --
> Rick Mann
> 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
_______________________________________________
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