[Nestedvm] Possible to pass floats in call in NestedVM?

skinhat skinhat skinhat at hotmail.com
Thu Mar 28 00:02:12 EDT 2013

Something I'm finding that works is to use 'user_info' if you want to pass floats to and from a function. For example 

C code call tryit
char *user_info[1024];


    float *g;
   g=(float *)(user_info[0]);

   printf("%f\n",  *g);

   return 0;

Java code that calls tryit. It passes the float 2.5f to the nestedVM code and the nested VM function changes it to 28

public static byte [] float2ByteArray (float value)

     return ByteBuffer.allocate(4).putFloat(value).array();

                 rt = (Runtime) Class.forName("tests.tryit").newInstance();
                 int fontAddr = rt.malloc(font.length);


                 int ret = rt.getUserInfo(0);
                 byte[] bytes = new byte[4];
                 rt.copyin(ret, bytes, bytes.length);     
                 float f=ByteBuffer.wrap(bytes).getFloat();  
                 System.out.println(f);  // prints 28

 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.

CC: nestedvm at lists.hcoop.net
From: ehrmann at gmail.com
Subject: Re: [Nestedvm] Possible to pass floats in call in NestedVM?
Date: Tue, 19 Mar 2013 17:31:16 -0700
To: skinhat at hotmail.com

Well that's...lossy.

On Mar 19, 2013, at 5:22 PM, skinhat skinhat <skinhat at hotmail.com> wrote:

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 

    synchronized int bind_double(long stmt, int pos, double v) throws SQLException {
        return bind_text(stmt, pos, Double.toString(v)); // TODO

   synchronized double value_double(Function f, int arg) throws SQLException {
        return Double.parseDouble(value_text(f, arg)); // TODO

I might have to do the same.

> Date: Tue, 19 Mar 2013 23:11:22 +0100
> From: fratz at inf.uni-konstanz.de
> To: skinhat at hotmail.com
> Subject: Re: [Nestedvm] Possible to pass floats in call in NestedVM?
> Hi,
> Thinking about it, it may be possible to do
> float foo = *((float *) &integer);
> in C to get that float back, but I never tried anything like that.
> However, there is a sqlite java interface (sqlite jdbc) that uses nestedvm,
> and that thing definitely has to pass floating point values to C, so it may
> be worth having a look at the relevant code.
> regards
> Matthias

Date: Mon, 18 Mar 2013 14:19:36 -0700
Subject: Re: [Nestedvm] Possible to pass floats in call in NestedVM?
From: ehrmann at gmail.com
To: skinhat at hotmail.com
CC: nestedvm at lists.hcoop.net

On Mon, Mar 18, 2013 at 1:04 PM, skinhat skinhat <skinhat at hotmail.com> wrote:

I have tried converting the float into raw int bits:

in runtime.java but just comes out to a huge integer.
  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.
Nestedvm mailing list
Nestedvm at lists.hcoop.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.hcoop.net/pipermail/nestedvm/attachments/20130328/6da18ede/attachment.htm 

More information about the Nestedvm mailing list