The Implicit type conversions section in the help states that Any numeric type will be automatically converted to Any numeric type.
However, I’ve got a method which takes doubles, Function AreEqual:Void(expected:Double, actual:Double), and if I try to pass floats in, AreEqual(123.45, 123.45), the compiler compains with “can’t find overload … with argument types (float, float)”.
The same thing happens with other numeric data types, e.g. declared as Long and passing Int.
Am I missing something or have I misunderstood?
This works fine here:
Function AreEqual:Void(expected:Double, actual:Double)
If you have defined several overloads of ‘AreEqual’ you may have problems if the compiler can’t work out which one you are meaning to call, eg: if you define AreEqual( Double,Double ) and AreEqual( Long,Long ) then you’ll get an error as AreEqual( 123.45,123.45 ) is ambiguous.
Yep – I have a Long overload as you guessed – that’ll be the problem 🙂
I was hoping that I’d just need Double and Long overloads and then could pass in any of the numeric types – something like how C# does it where it’ll implicity convert to “larger” types, but you need to explicity convert to “smaller” types: https://msdn.microsoft.com/en-us/library/y5b434w4.aspx
But it’s not really a problem adding overloads for the other numeric types.
For testing these (and other) functions is there any way to specify a double literal in code? e.g. Java and C# let you use 123.45f for float, 123.45d for double, 123L for long etc.
I’ve sorted it now using generics 🙂
You must be logged in to reply to this topic.
Monkey2 is an easy to use, cross platform, games oriented programming language from Blitz Research.