• 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: Swift struggles with arithmetic ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swift struggles with arithmetic ?


  • Subject: Re: Swift struggles with arithmetic ?
  • From: Quincey Morris <email@hidden>
  • Date: Sat, 29 Aug 2015 20:55:59 +0000

On Aug 29, 2015, at 13:05 , Gavin Eadie <email@hidden> wrote:
>
> I’ve been using Swift and moving some Obj-C code over to it, but I’m concerned that it thinks this is “too complex to be solved in reasonable time”:
>
>    import Foundation
>    let y = 1.0 * sin(1.0) + 1.0 * sin(1.0) + 1.0 * sin(1.0)
>
> The above is simplified from the original (original didn’t have constants under the sin function).

I think you can assume that the error message is in effect a secondary error. The expression complexity isn’t the issue, but rather the (internal) path Swift follows to compile it.

Still, there is quite a bit of complexity hidden behind the scenes, since your constants are convertible to at least 3 different types (Double, Float and CGFloat) and there are two variants of ‘sin’ (one that takes a Float, and one that takes a Double). The tree of possibilities is not entirely trivial, so it’s probably hitting some internal limit that seems otherwise reasonable. (Simplistically, there are at least 3 * 2 *3 * 3 * 2 * 3 * 3 * 2 * 3 different type analyses to decide between.)

Interestingly, the following compiles without error:

> 	let y = 1 * sin(1.0) + 1 * sin(1.0) + 1 * sin(1.0)


Also, in:

> 	let one = 1.0
> 	let y = 1.0 * sin(one) + 1.0 * sin(one) + 1.0 * sin(one)
> 	let z = one * sin(1.0) + one * sin(1.0) + one * sin(1.0)

can you guess which of the last 2 lines doesn’t compile?

I also occasionally get the same “too complex to be solved in reasonable time” error for expressions that don’t terribly complicated, but I don’t see there’s much you can do about it except to break up the expression, until the compiler is fixed/improved.



_______________________________________________

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: Swift struggles with arithmetic ?
      • From: Gavin Eadie <email@hidden>
References: 
 >setting tab stops in swift (From: Boyd Collier <email@hidden>)
 >Re: setting tab stops in swift (From: Jens Alfke <email@hidden>)
 >Re: setting tab stops in swift (From: Boyd Collier <email@hidden>)
 >Re: setting tab stops in swift (From: Jens Alfke <email@hidden>)
 >Re: setting tab stops in swift (From: Quincey Morris <email@hidden>)
 >Re: setting tab stops in swift (From: Jens Alfke <email@hidden>)
 >Swift struggles with arithmetic ? (From: Gavin Eadie <email@hidden>)

  • Prev by Date: Swift struggles with arithmetic ?
  • Next by Date: Re: Swift struggles with arithmetic ?
  • Previous by thread: Swift struggles with arithmetic ?
  • Next by thread: Re: Swift struggles with arithmetic ?
  • Index(es):
    • Date
    • Thread