[Tinyos-devel] Fw: Re: Tinyos-devel Digest, Vol 54, Issue 11

Hristo Bojkov hbojkov at idxs.eu
Wed Oct 10 00:41:13 PDT 2007


Sorry...plain text problem in previous one.... 

-------Original Message------- 
> 
>Date: Tue, 9 Oct 2007 09:07:50 -0700 
>From: "David Gay" <dgay42 at gmail.com> 
>Subject: [Tinyos-devel] external (nx*) types and floating point 
>To: "TinyOS Development" <tinyos-devel at millennium.berkeley.edu> 
>Message-ID: 
> <f331126a0710090907s75748d7at376ea4abf09cddb7 at mail.gmail.com> 
>Content-Type: text/plain; charset=ISO-8859-1 
> 
>There's currently no nx_float / nx_double type that would allow use of 
>floating point in protocols. 
> 
>Two questions: 
>- how necessary are such types? (w/o them, you have to figure out some 
>integer encoding for any real numbers you have to deal with) 
> 
>- does anybody have some portable code (and not too large...) for 
>converting an array of bytes to a float/double? (that's the main 
>sticking point as far as I'm concerned) 
> 
>Some additional comments: 
>- specifying these types as IEEE 32 and 64-bit numbers seems reasonable 
> 
>- I'm reluctant to include platform-specific code w/ the nesC 
>distribution to deal with nx_float/nx_double, as it feels like it 
>would make nesC maintenance more painful 
> 
>- we could actually define nx_float/nx_double in TinyOS (on a 
>per-chip or per-platform basis, e.g.) - external types are defined by 
>a magic (undocumented) attribute, so can fairly easily be added 
>independent of nesC 
> 
>David Gay 
 
By speaking about " IEEE 32 and 64-bit numbers " do you mean IEEE 754? 
If so? I have some funcs about single precision. They can be included in
float module, if you like them.

The good thing is that C# library function in System.BitConverter.ToSingle,
uses same way to convert them, I am not good in Java, but their ToSingle
should be compatible too... 
 
I just have a question ... What about small float with 16bit precision which
is presented in IEEE 754r? 
 
/* 
* Just to present as float 
*/ 
Float ByteArrayToFloat(uint8_t* pbBuffer) 
{ 
Return *((float*)pbBuffer); 
} 
 
/* 
* To copy contents in float location 
*/ 
Void CopyByteArrayToFloat(uint8_t* pbBuffer, float* pfTarget) 
{ 
Memcpy((void*)pfTarget, pbBuffer, 4); 
} 
 
/* 
* Just to present as byte array 
*/ 
Uint8_t* FloatToByteArray(float fSource) 
{ 
Void* pvRet = (void*)&fSource; 
Return (uint8_t*)pvRet; 
} 
 
/* 
* To copy float in byte array 
*/ 
Void CopyFloatToByteArray(float fSource, uint8_t* pbBuffer) 
{ 
Memcpy(pbBuffer, (void*)&pfSource, 4); 
} 
 
 
 
Hristo Bojkov 
 
Platform: WinXp/Cygwin 
TinyOS: 2.0.2 
Device: Tmote 
 
. 
 
 


More information about the Tinyos-devel mailing list