<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Something I'm finding that works is to use 'user_info' if you want to pass floats to and from a function. For example <br><br>C code call tryit<br>char *user_info[1024];<br><br>main()<br>{<br><br> float *g;<br> g=(float *)(user_info[0]);<br><br> printf("%f\n", *g);<br> *g=28;<br><br> return 0;<br>}<br><br><br>Java code that calls tryit. It passes the float 2.5f to the nestedVM code and the nested VM function changes it to 28<br><br>public static byte [] float2ByteArray (float value)<br>{ <br><br> return ByteBuffer.allocate(4).putFloat(value).array();<br>}<br><br> rt = (Runtime) Class.forName("tests.tryit").newInstance();<br> <br> rt.start();<br> font=float2ByteArray(2.5f);<br> int fontAddr = rt.malloc(font.length);<br> rt.copyout(font,fontAddr,font.length); <br> rt.setUserInfo(0,fontAddr);<br><br> rt.execute();<br><br> int ret = rt.getUserInfo(0);<br> byte[] bytes = new byte[4];<br> rt.copyin(ret, bytes, bytes.length); <br> float f=ByteBuffer.wrap(bytes).getFloat(); <br> System.out.println(f); // prints 28<br> <br><br> In this example I'm using main() but should work using NestedVM calls so could create a tryit function in C and have it access user_info.<br><br><br><br><div><div id="SkyDrivePlaceholder"></div><hr id="stopSpelling">CC: nestedvm@lists.hcoop.net<br>From: ehrmann@gmail.com<br>Subject: Re: [Nestedvm] Possible to pass floats in call in NestedVM?<br>Date: Tue, 19 Mar 2013 17:31:16 -0700<br>To: skinhat@hotmail.com<br><br><div>Well that's...lossy.<br><br>On Mar 19, 2013, at 5:22 PM, skinhat skinhat <<a href="mailto:skinhat@hotmail.com">skinhat@hotmail.com</a>> wrote:<br><br></div><blockquote><div>
<style><!--
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Tahoma;}
--></style>
<div dir="ltr">
I looked at the SQLLite code and looks like they convert floats to
strings and back. For example in NestedDB.java of SQLLite source its
got:<br><br><br> synchronized int bind_double(long stmt, int pos, double v) throws SQLException {<br> return bind_text(stmt, pos, Double.toString(v)); // TODO<br> }<br><br><br> synchronized double value_double(Function f, int arg) throws SQLException {<br> return Double.parseDouble(value_text(f, arg)); // TODO<br> }<br><br>I might have to do the same.<br><br>> Date: Tue, 19 Mar 2013 23:11:22 +0100<br>> From: <a href="mailto:fratz@inf.uni-konstanz.de">fratz@inf.uni-konstanz.de</a><br>> To: <a href="mailto:skinhat@hotmail.com">skinhat@hotmail.com</a><br>> Subject: Re: [Nestedvm] Possible to pass floats in call in NestedVM?<br>> <br>> Hi,<br>> <br>> Thinking about it, it may be possible to do<br>> float foo = *((float *) &integer);<br>> in C to get that float back, but I never tried anything like that.<br>> <br>> However, there is a sqlite java interface (sqlite jdbc) that uses nestedvm,<br>> and that thing definitely has to pass floating point values to C, so it may<br>> be worth having a look at the relevant code.<br>> <br>> regards<br>> Matthias<br>> <br><br><div><div id="ecxSkyDrivePlaceholder"></div><hr id="ecxstopSpelling">Date: Mon, 18 Mar 2013 14:19:36 -0700<br>Subject: Re: [Nestedvm] Possible to pass floats in call in NestedVM?<br>From: <a href="mailto:ehrmann@gmail.com">ehrmann@gmail.com</a><br>To: <a href="mailto:skinhat@hotmail.com">skinhat@hotmail.com</a><br>CC: <a href="mailto:nestedvm@lists.hcoop.net">nestedvm@lists.hcoop.net</a><br><br>On Mon, Mar 18, 2013 at 1:04 PM, skinhat skinhat <span dir="ltr"><<a href="mailto:skinhat@hotmail.com">skinhat@hotmail.com</a>></span> wrote:<br><div class="ecxgmail_quote"><blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex">
<div><div dir="ltr">I have tried converting the float into raw int bits:<br>ia[i]=Float.floatToRawIntBits(f);<br><br>in runtime.java but just comes out to a huge integer.<br></div></div></blockquote><div> </div><div> <span style="color:rgb(34,34,34);font-family:arial,sans-serif">That's probably correct. Floats are stored very differently than ints, and the int version of a float will always look nothing like the float. The only exception I can think of is positive zero looking like an int zero. Negative zero looks completely different.</span></div>
</div></div>                                            </div>
</div></blockquote><blockquote><div><span>_______________________________________________</span><br><span>Nestedvm mailing list</span><br><span><a href="mailto:Nestedvm@lists.hcoop.net">Nestedvm@lists.hcoop.net</a></span><br><span><a href="https://lists.hcoop.net/listinfo/nestedvm" target="_blank">https://lists.hcoop.net/listinfo/nestedvm</a></span><br></div></blockquote></div>                                            </div></body>
</html>