On Fri, Aug 19, 2011 at 11:32 AM, Geo Gkolfin <geo198...@gmail.com> wrote:
> Thanks for your answer! > Actually it almost worked! > %lu prints 3354000128 instead of 3354000112. > %lx prints c7e9fb00 which is 3354000128 hex. > This can drive you crazy! Any ideas please? > Without explicitly stepping through the code and seeing what it is doing, we would be guessing. > > On Thu, Aug 18, 2011 at 12:58 AM, Michael Schippling <sc...@santafe.edu>wrote: > >> That is a little odd... >> >> I guess the implicit casting is trying to help you by >> returning the largest value for the uint16 when converting >> from a too-big float. When you change to uint32 you >> should get 0xC7E9FAF0 in your integer (which is what >> my Widows calculator shows as the correct conversion >> for decimal 354000112). Then, because the top bit is >> set and you asked for a signed decimal output "%ld" >> you should get a negative value, but it's off by 16... >> -940967168d == 0xC7E9FB00 >> so I'm not sure what is going on. >> >> Try printing %lu or %lx and see what you get. >> >> MS >> >> Geo Gkolfin wrote: >> >>> Hello! >>> >>> I am using telosb motes and tinyos-2.1.0. I have an application in which >>> some floating point operations are done and I wish to print (using >>> PrintfClient) only the decimal part of the result. Since the printed value >>> is not what it should be -it is always 65535- I wrote a simple program where >>> I have: >>> >>> float y; >>> uint16_t x; >>> >>> y=4354.542134509; >>> x=y; >>> printf("int(4354.542134509)=%**u\n",x); >>> printfflush(); >>> >>> I run >>> java net.tinyos.tools.PrintfClient -comm serial@/dev/ttyUSB0:telosb >>> >>> and I get the 4354! >>> >>> If I change the value stored in y to: >>> y=3354000112.542134509 then the printf returns 65535 -the same value as >>> in my application! So I guess this is because the value does not "fit" into >>> a uint16_t. I change x definition to uint32_t and %u to %ld (make is okay >>> with that), but then the printed value is -940967168! >>> What is the problem? >>> >>> Thanks in advance, >>> Georgia >>> >>> >>> ------------------------------**------------------------------** >>> ------------ >>> >>> ______________________________**_________________ >>> Tinyos-help mailing list >>> Tinyos-help@millennium.**berkeley.edu<Tinyos-help@millennium.berkeley.edu> >>> https://www.millennium.**berkeley.edu/cgi-bin/mailman/** >>> listinfo/tinyos-help<https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help> >>> >> > > _______________________________________________ > Tinyos-help mailing list > Tinyos-help@millennium.berkeley.edu > https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help > -- Eric B. Decker Senior (over 50 :-) Researcher
_______________________________________________ Tinyos-help mailing list Tinyos-help@millennium.berkeley.edu https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help