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

**URL:** <https://community.haxe.org/t/float-seems-to-be-double-for-c-target-how-about-float-externs/1662>\
**Category:** Haxe\
**Tags:** haxe-cs\
**Created:** [April 6, 2019, 9:46am UTC](https://community.haxe.org/t/float-seems-to-be-double-for-c-target-how-about-float-externs/1662 "2019-04-06T09:46:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pshtif](https://community.haxe.org/user_avatar/community.haxe.org/pshtif/32/783_2.png) [@pshtif](https://community.haxe.org/u/pshtif)\
**Post date:** [April 6, 2019, 9:46am UTC](https://community.haxe.org/t/float-seems-to-be-double-for-c-target-how-about-float-externs/1662/1 "2019-04-06T09:46:55Z")

</div>

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#?

---

<div class="post-metadata">

**Author:** ![nadako](https://community.haxe.org/user_avatar/community.haxe.org/nadako/32/5_2.png) [@nadako](https://community.haxe.org/u/nadako)\
**Post date:** [April 6, 2019, 9:48am UTC](https://community.haxe.org/t/float-seems-to-be-double-for-c-target-how-about-float-externs/1662/2 "2019-04-06T09:48:39Z")

</div>

Have you tried `Single`?

---

<div class="post-metadata">

**Author:** ![pshtif](https://community.haxe.org/user_avatar/community.haxe.org/pshtif/32/783_2.png) [@pshtif](https://community.haxe.org/u/pshtif)\
**Post date:** [April 6, 2019, 12:30pm UTC](https://community.haxe.org/t/float-seems-to-be-double-for-c-target-how-about-float-externs/1662/3 "2019-04-06T12:30:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pshtif](https://community.haxe.org/user_avatar/community.haxe.org/pshtif/32/783_2.png) [@pshtif](https://community.haxe.org/u/pshtif)\
**Post date:** [April 6, 2019, 12:37pm UTC](https://community.haxe.org/t/float-seems-to-be-double-for-c-target-how-about-float-externs/1662/4 "2019-04-06T12:37:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pshtif](https://community.haxe.org/user_avatar/community.haxe.org/pshtif/32/783_2.png) [@pshtif](https://community.haxe.org/u/pshtif)\
**Post date:** [April 6, 2019, 2:07pm UTC](https://community.haxe.org/t/float-seems-to-be-double-for-c-target-how-about-float-externs/1662/5 "2019-04-06T14:07:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pshtif](https://community.haxe.org/user_avatar/community.haxe.org/pshtif/32/783_2.png) [@pshtif](https://community.haxe.org/u/pshtif)\
**Post date:** [April 7, 2019, 10:50am UTC](https://community.haxe.org/t/float-seems-to-be-double-for-c-target-how-about-float-externs/1662/6 "2019-04-07T10:50:54Z")

</div>

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:

```haxe
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’
