Issues working with FloatingPoint

Hello,
I'm having some trouble using FloatingPoint (Apple Swift 5.1.3):

  1. Expressions like (9*a1*a2 - 27*a3 - 2*a1*a1)/54, where a1 and a2 are FloatingPoint hang the compiler (I get the infamous "fails to resolve it in reasonable time" message)
  2. Many math functions don't have a FloatingPoint version (although they do have implementations for each concrete types). For e.g.: cos, acos, pow, cbrt

Are these known issues? Any workarounds (for 1, splitting the expression works, but...)? As things look now, i feel like it's almost impossible to make use of FloatingPoint and it's a shame since it's really useful.

It is somewhat known, that long arithmetic expression (without concrete type) is not good with Swift right now.

Try to make one of them concrete type. Annotating result type would work as well.

let a: Float = (9*a1*a2 - 27*a3 - 2*a1*a1)/54

I can't really do that since I don't want the result to be a Float. Plus, it seems it doesn't help anyhow. The only thing that works is splitting the expression, but it looks horrendous.

Something that is workable would be to annotate the type at certain strategic points, for this one

((9*a1*a2) as T - 27*a3 - 2*a1*a1) / 54 as T

It would take trail-and-error, and you may even need multiple annotations (though, much the same as splitting expression), but that's as much as I can suggest with the requirement.

Terms of Service

Privacy Policy

Cookie Policy