[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-chat] Bug in atof shipped with avr-libc?

From: Matt.Vandewerken
Subject: [avr-chat] Bug in atof shipped with avr-libc?
Date: Thu, 24 Feb 2011 18:42:58 +1100

Hi all:

I think I've found a bug in the version of atof that ships with the latest/last 
version of Winavr. 

When I pass it a string with a floating point number, the number it returns is 

For example, I can pass it '-1033\0', and the result is something like -15640. 
Similarly, I can pass it '0.33', and the result is 16000 and something. It 
seems that the only thing it gets right are the sign and when the input string 
is '0.00'.

I have reimplemented atof as my_atof, and it works perfectly.

Note that this incorrect behaviour is also apparent in avr-gcc shipped with 
ubuntu 10.04.2.

An example of code that demonstrates the behaviour is below:

float atof_test(void){
        static char buf[10];
        char* pbuf = buf;

        buf[0] = '-';
        buf[1] = '0';
        buf[2] = '.';
        buf[3] = '3';
        buf[4] = '3';
        buf[5] = '\0';

        return atof(pbuf);

Matt van de Werken
Electronics Engineer
Mining Geoscience, CSIRO Earth Science and Resource Engineering
1 Technology Ct   Pullenvale   QLD   4069
P: 07 3327 4142  F: 07 3327 4455  M: 0400 538 608
E: address@hidden
"Those that do not understand UNIX are condemned to reinvent it, poorly"
  - Henry Spencer

reply via email to

[Prev in Thread] Current Thread [Next in Thread]