generic *= operator


(J.E. Schotsman) #1

Hello,

I can define a custom *= operator like this:

func *=( inout lhs:UInt32, rhs:Float )->UInt32
  {
  lhs = UInt32( roundf( Float(lhs)*rhs ) )
  }

but my attempts to make this generic have failed.

I would like something like

func *=<X:SomeIntegerProtocol,Y:SomeFloatProtocol>( inout X, rhs:Y)-> X
  {
  lhs = X( (Y(lhs)*rhs).round() )
  }

that works for all integer types and all floating point types.

Is this feasible?

Jan E.