Re: FLoating value from native
"sharmila inamdar" <[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.tini |
|---|---|
| Message-ID | <003901c4189d$be1c8a10$046464c7@sharmila> |
no ,it did not worked. If I pass float value as 5.5 ad read it back as float it comes out to be1.8xxxxxx or something like this. If I give call to intbitsToFloat ,then only it works. What's wrong ? -----Original Message----- From: Thomas Chenot <tom.chenot-6tN4nzCoH/[email protected]> To: sharmila inamdar <[email protected]> Cc: tini <tini-6tN4nzCoH/[email protected]> Date: Thursday, April 01, 2004 10:55 PM Subject: Re: [TINI]FLoating value from native >sharmila inamdar wrote: > >>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. >> >If you simply declare the return type of the native method to be float, >you do not have to call intBitsToFloat. The native method declaration >would look something like: > >public static native float processFloat(float f); > >You would not have to change anything in your native method implementation. > >> >>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 >> >> >> > > >-- >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 _______________________________________________ TINI mailing list TINI-6tN4nzCoH/[email protected] To UNSUBSCRIBE, edit your profile, or see list archives: http://lists.dalsemi.com/mailman/listinfo/tini