<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I encountered this issue as well; for now I'm using the following transformation:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">long tmp = input >>> 1;</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">double output = ((double) tmp) * 2.0 + (tmp & 1);</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I... *think* it's correct but I'm not 100% sure and have a long-standing TODO to try and figure it out...</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Nov 5, 2022 at 7:17 PM Johannes Kuhn <<a href="mailto:info@j-kuhn.de">info@j-kuhn.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">When I tried to implement an WASM transpiler, I noticed some missing <br>
conversion methods from unsigned types to floating point, for example <br>
from unsigned long to a double.<br>
<br>
For the meaning of unsigned long, see Long.toUnsignedString(long i).<br>
<br>
Converting between unsigned long and floating point is not a trivial <br>
task, as it probably requires some bit manipulation.<br>
<br>
In particular, I would love to see the following methods added*:<br>
<br>
- double Double.fromUnsignedLong(long i)<br>
- long Double.toUnsignedLong(double d)<br>
- float Float.fromUnsignedLong(long i)<br>
- long Float.toUnsignedLong(float f)<br>
<br>
* Subject to bikeshedding - I don't care about the name, or if it is <br>
added to the Long class.<br>
<br>
Currently, I don't think that additional methods for unsigned int are <br>
necessary - as it is possible to cast between long and int, but feel <br>
free to correct me.<br>
<br>
In WASM, the specification for those methods can be found here:<br>
<br>
<a href="https://www.w3.org/TR/wasm-core-1/#op-trunc-u" rel="noreferrer" target="_blank">https://www.w3.org/TR/wasm-core-1/#op-trunc-u</a><br>
<a href="https://www.w3.org/TR/wasm-core-1/#op-convert-u" rel="noreferrer" target="_blank">https://www.w3.org/TR/wasm-core-1/#op-convert-u</a><br>
<br>
Note that the WASM specification is undefined for some values, notably <br>
NaN, infinities, and values that fall out of the range.<br>
<br>
As *I* want to use it to implement WASM instructions, I do not have any <br>
strong opinion on the undefined cases - for example, returning the <br>
nearest unsigned long value or throwing an exception is fine for me.<br>
<br>
What do you think?<br>
<br>
- Johannes<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">- DML • he/him<br></div></div>