"Relaxed" floating-point operators

I'm curious if you've tried (and if so, does it work and how you'd feel about it) the freestanding macro idea. That is:

  • Have _Relaxed.sum(_:_:), etc. as the actual entrypoint

  • Have a macro #fp(.relaxed) or some such, which emits locally:

@inline(always)
private func &+ <T: FloatingPoint>(lhs: T, rhs: T) -> T { _Relaxed.sum(lhs, rhs) }
  • At the use site:
#fp(.relaxed)
let sum = a &+ b // etc.
1 Like