[Tinyos-help] Calculation precision (in micaz and telosb)

Michael Schippling schip at santafe.edu
Mon Jun 8 09:27:39 PDT 2009


Using fractions in integer arithmetic is a non-starter...
specifically (1/4) * 100 will give you 0 because 1 divided
by 4 in integer is 0. Although  0.25 * 100 would probably
force a floating point operation resulting in 25.0 which
would then be truncated to 25 if assigned to an integer.
In that case the compile might complain about missing
casts, or not...

There are software floating point libraries for the motes
but they are rather slow. A better solution is to use fixed
point calculations by shifting all your values up a few bits.

MS


Rémi Villé wrote:
> Hi,
> 
> In TinysOS there's only integer type to get calculation results. I think 
> because of microcontroller/CPU coercions.
> But I would like to know if there is a precision during the calculation, 
> I mean if I do (1/4) * 100 (using brackets to obtain 0.25 before the 
> multiplication), will I obtain 25 or 0 ?
> 
> Is there logarithm and exponential functions in TinyOS ?
> Is it possible to do ln(0.7) and obtain a good result precision ?
> 
> Thanks,
> 
> Rémi
> 
> PS : sorry, I forgot [Tinyos-help] in the subject msg again
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tinyos-help mailing list
> Tinyos-help at millennium.berkeley.edu
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help


More information about the Tinyos-help mailing list