Re: FLoating value from native
"sharmila inamdar" <[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.tini |
|---|---|
| Message-ID | <003e01c417ce$4ed43b50$046464c7@sharmila> |
Thanks a lot Shawn and Thomas !
yes, I got it. By returning int from native we have to just call
Float.intBitsToFloat() to get the float value from 32bit IEEE754 format.
Here is a sample java class and a native method.
public class FloatRetMath
{
// static method with parameters float and return type int
public static native int processFloat(float f);
public static void main(String[] args)
{
System.loadLibrary("FloatRetMath.tlib");
// attempt to load our native library
float f = 5.0f;
try
{
System.out.println("Through Native call passing float " + f );
int k = processFloat(f);
System.out.println("Processed Result in integer format is (IEEE754) "
+ k);
System.out.println("Processed Result in float is " +
Float.intBitsToFloat(k));
}
catch(Throwable t)
{
System.out.println(t);
}
System.out.println("Exiting FloatRetMath");
}
}
;***************************************************************************
*
Native_processFloat:
clr a ; request first parameter
lcall NatLib_LoadPrimitive ; point to parameter
;
; we just popped the param into
; R3:R0 - let's just return them
; as the result
clr a ; indicate "no exception"
ret ;
;*************************************************************
-----Original Message-----
From: Thomas Chenot <tom.chenot-6tN4nzCoH/[email protected]>
To: sharmila inamdar <[email protected]>
Cc: tini <tini-6tN4nzCoH/[email protected]>
Date: Wednesday, March 31, 2004 9:35 PM
Subject: Re: [TINI]FLoating value from native
>sharmila inamdar wrote:
>
>>I am using DS80c390. I want to know whether we can get direct floating
point
>>value form native layer ? How should it be returned in native and which
>>format?
>>
>There is no support for floating point in the native API. The basics
>(+,-,*,/, SQRT) are handled via the JVM. The rest is handled at the
>library level. The format is described in IEEE Std 754-1985. Single
>precision values are 32 bits and are therefore passed in and returned
>just as "int" values are passed and returned. Double precision values
>are 64 bits and therefore are handled in the same manner as "long" values.
>
>>
>>The native example given with the TSDK talks about long and int return
>>values. How do I handle float values ? Or I have to return a byte array
and
>>then process it on the JVM layer?
>>
>>
>>..sharmila
>>
>>
>>
>--
>Thomas Chenot
>
_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini