seivan/ScalarArithmetic

UInt32

stsievert opened this issue · 3 comments

I was using this in [my project][swix] and was generating a random number:

var x = arc4random() / pow(2, 32)

This generates a random number between 0 and 1 and relies on UInt32 / Double meaning I had to wrap arc4random() in Int(.), exactly what ScalarArithmetic tries to avoid.

@scottsievert Will write a test case for so you can try it out with a solution. If it works, we'll merge it. But I need to get home first. I'll be on it in about 2 hours.

Alright I've done a fix for this.

Int16, Int32, Int64 and UInt16, UInt32, UInt64
When any of these match with a Double, you get a double back.

However between UInt32 and Int16 you still have to do a cast yourself, because I feel that it's better to be explicit there.

@scottsievert This 7671dd5#diff-b0e4ce0cd008a7623478b39eb4b01370R23 should fix the issue. I'll tag it 1.1