Float seems to be double for C# target, how about float externs?

What is the correct way to write externs for C# libraries that actually use real floats? All the implementations I tried like abstracts always end up with a lot of allocation in C# at runtime due to the conversion.

Is there a way to use single precision in Haxe for C#?

Have you tried Single?

Thanks for the fast response nadako, I’ve tried to avoid it as it just means the problem will go one level up. To put more context into my problem is that the whole framework is written using haxe Floats so if I type externs using Single the high level framework will still use Floats and therefore there will be a problem to go from Float to Single.

I assumed this would result in similar issue as writing abstracts over it and doing this.x = x where this.x is native float and x is haxe Float? Which means a lot of allocation going on? Or am I wrong?

Tried a quick test and sending Float from high level class to extern using Single will result in cannot convert from “haxe.lang.Null” to “float” so it seems it doesn’t even do it implicitly like when using abstracts.

There seems to be an issue with default parameters, Haxe always transpiles them as global::haxe.lang.Null for some reason even though they are not using the questionmark ?p_parameter = 0 syntax. Shouldn’t optional parameters like p_parameter = 0 be transpiled as the native nonnullable type?

It is actually getting even more complicated due to this default parameter issue Reflection doesn’t work on specific types with such constructors in C#.

For example this code will crash:

class Something {
   public new(p_value:Float = 0) {}

Type.createInstance(Something, [0.0]);

Because it will assume that the float is not directly assignable to the costructor parameter as it is a nonullable type on static target. And it will end up with EmptyObject as the most rated method inside reflection. Which will crash as:

Invalid cast from ‘System.Double’ to ‘haxe.lang.EmptyObject’