Re: [Tinyos-help] Wrong printed value
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.eduwrote: 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.eduTinyos-help@millennium.berkeley.edu https://www.millennium.**berkeley.edu/cgi-bin/mailman/** listinfo/tinyos-helphttps://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
Re: [Tinyos-help] Wrong printed value
There are not so many steps to be made. The functionality is described in my first mail. On Fri, Aug 19, 2011 at 9:38 PM, Eric Decker cire...@gmail.com wrote: 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.eduwrote: 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.eduTinyos-help@millennium.berkeley.edu https://www.millennium.**berkeley.edu/cgi-bin/mailman/** listinfo/tinyos-helphttps://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
Re: [Tinyos-help] Wrong printed value
ahI think the number of significant digits for a float is 24 bits so the cast may be rounding. See: http://en.wikipedia.org/wiki/Floating_point#Rounding_modes MS Geo Gkolfin wrote: There are not so many steps to be made. The functionality is described in my first mail. On Fri, Aug 19, 2011 at 9:38 PM, Eric Decker cire...@gmail.com mailto:cire...@gmail.com wrote: On Fri, Aug 19, 2011 at 11:32 AM, Geo Gkolfin geo198...@gmail.com mailto: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 mailto: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 mailto: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 mailto: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 ___ Tinyos-help mailing list Tinyos-help@millennium.berkeley.edu https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help