ATOF doesn't work

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ATOF doesn't work

7,992 Views
TroyCorser
Contributor III
The function ATOF and also ATOI and ATOL don't works.
this is the sample code I take from CW help System:
 
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
   int i;
   long int j;
   float f;
   static char si[] = "-493", sli[] = "63870";
   static char sf[] = "1823.4034";

   f = atof(sf);
   i = atoi(si);
   j = atol(sli); 
 
 
   return 0;
}
The Output I get on debug mode on DSP56F8367  is :

72659.2
0
0
 
WTF?? :smileyindifferent:
Labels (1)
Tags (1)
0 Kudos
10 Replies

1,830 Views
CrasyCat
Specialist III
Hello
 
- Which CPU are you targeting (HC08, HC12, Coldfire, ..)
- Which version of CodeWarrior are you using?
  To retrieve that info:
  - Start CodeWarrior
  - Select Help -> About Freescale CodeWarrior
  - Click on "Install Products"
  - CodeWarrior version used is displayed on top in the Installed Products dialog.
 
CrasyCat
0 Kudos

1,830 Views
TroyCorser
Contributor III
Hi CrasyCat,
 
     with a little change to the example ATOI and ATOL now works
    
     I've changed this :
 
"    static char si[] = "-493", sli[] = "63870";
     static char sf[] = "1823.4034";
"
 
with this:
 
" char si[] = "-493", sli[] = "63870"; 
  char sf[] = "1823.4034";
"
The Output I get on debug mode on DSP56F8367  is :

72659.2
-493
63870
 
but ATOF the main function that I need to use, as you can see in the output results, still doesn't work!
 
The CPU I'm using is : DSP56F8367
 
CodeWarrior 56800/E Hybrid Controller version 7.3
ROHS USBTAP Update v1.0, build 60405
 
 
0 Kudos

1,830 Views
J2MEJediMaster
Specialist I
The function atof() is supposed to return the values as a double. I'd try changing the type declaration of f from float to double and see what happens.

---Tom
0 Kudos

1,830 Views
TroyCorser
Contributor III
I've tryed to change from float to double.. but I get the same result... wrong output!!
:smileysad:
 
I see that the wrong value I get sometimes don't change with the input data,
indipendently of the input type, float or double:
 
now with this input in sf the output is:
 
sf = "1823.4034" output= -2.346737e-19
 
sf = "-23.4"         output= -2.346737e-19
 
sf = 22.4"            output= -2.346737e-19
 
always the same output...
 
I need to use this function... how can it be that I can't use it with CodeWarrior ?!?
:smileysad:
 
I'm going carzy! :smileymad:
0 Kudos

1,830 Views
TroyCorser
Contributor III
I've cheked the global variable "errno" that returns always 34: "ERANGE" after the call to ATOF with any value of input...
 
Overflow bit of the __strtold is high (1)


Message Edited by Troy Corser on 2007-12-03 08:43 AM
0 Kudos

1,830 Views
TroyCorser
Contributor III
Problem solved!!!
Now it works! :smileyvery-happy:
 
The point was:
 
on the "Idm internal memory with pRom-to-xRAM copy Settings"
in the sub-menu:
 
M56800E Target settings
 
the field processor was setted on "generic"
 
now I've setted it on my specific processor M56F8367
 
Thanks to all who partecipate to this discussion!
0 Kudos

1,830 Views
J2MEJediMaster
Specialist I
Thanks for telling us how you solved the problem. And I'm sorry our suggestions didn't work.

---Tom
0 Kudos

1,830 Views
TroyCorser
Contributor III
I'm here again...:smileysad:
 
What I thought It worked now don't!..
The first tests was going well...but some time later...
atof didn't work...
 
In the first step It look likes as atof work on numbers >1.0 and didn't work with number <1.0
 
for example atof(0.02) = 0.0
 
but after a big number of attempts I see that also atof(X) with x  > 1.0 sometimes don't work...
 
So I'm stiil losing time tring to solve this problem!
 
Example : atof("1.7")
 
atof call the function strtod   =>  return(strtod(str, NULL));
 
strtod call => __strtold(INT_MAX, &__StringRead, (void *)&isc, &count, &overflow);
 
after the execution of __strtold
 
 overflow = 1 , count =3, value = -1.173368e-19
 
Any help.. how can happen this...?! :smileysurprised:
 
Added information : the sistem I'm using is integrated with microC/OS-II  RTOS
I've already tried the atof function with OS interrupt enabled and disabled.




Message Edited by Troy Corser on 2007-12-10 10:09 AM
0 Kudos

1,830 Views
TroyCorser
Contributor III
 
 
Example : atof("1.7")
 
atof call the function strtod   =>  return(strtod(str, NULL));
 
strtod call => __strtold(INT_MAX, &__StringRead, (void *)&isc, &count, &overflow);
 
after the execution of __strtold
 
 overflow = 1 , count =3, value = -1.173368e-19
 
inside the function  __strtoold there is a tree that entered without a resonable reason :
"
 else if (result > LDBL_MAX)
  {
   *overflow = 1;
   result    = HUGE_VAL;
  } 
  "
 
result is "1.70000"
 
LDBL_MAX is defined in cfloat in this way:
 
#if _MSL_DOUBLE_SIZE == 32
#if _MSL_FLOAT_HEX
 #define DBL_MAX       0x1.fffffeP127
 
#elif _MSL_DOUBLE_SIZE == 64
#if _MSL_FLOAT_HEX
 #define DBL_MAX       0x1.fffffffffffffP1023
 
 
 
0 Kudos

1,830 Views
J2MEJediMaster
Specialist I
Looks like it's time for you to enter a service request for this problem. Click here to do so. You may want to send them an archived version of your project so that they can examine the code in detail.

---Tom

0 Kudos