CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

problem/limitations with atof()?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
starfire151



Joined: 01 Apr 2007
Posts: 195

View user's profile Send private message

problem/limitations with atof()?
PostPosted: Sat May 26, 2007 1:35 pm     Reply with quote

In trying to convert a latitude/longitude set to floating point, I ran across a curious problem with an 18LF252 and an 18LF2525. In a test case, I formatted a string with 4 characters, a decimal point, and 4 more characters. I tried an atof() on the string and got an invalid answer. In checking other posts related to the subject, I found one that showed the only issue was precision, not validity. I tried decreasing values in the string and repeated the atof() test. It seems three digit characters before the decimal point is the limitation. Is this a real limitation? Is there a work-around or alternative solution?

My test result outputs are as follows:

    string: 4329.6466 float: 34.679296
    string: 329.6466 float: 329.646656
    string: 29.6466 float: 29.646602
    string: 9.6466 float: 9.646600
    string: .6466 float: 0.646600
    string: 6466 float: -2123.934719


Is this documented somewhere?

Thanks.
Sad
Ttelmah
Guest







PostPosted: Sat May 26, 2007 2:51 pm     Reply with quote

atof, is listed in stdlib.h. There is no obvious reason in the listing for a problem. What compiler are you using?. There _is_ a known problem with printf, on the older compilers, if used with '%f', where garbage results are given above a certain size. What is your printf specifier?. Though it is a fault, remember that to display 4.4, requires "%9.4f" (the decimal point is a counted character), and I'd suspect it might be the output that is the problem, rather than atof.

Best Wishes
starfire151



Joined: 01 Apr 2007
Posts: 195

View user's profile Send private message

atof() / printf() prpblem
PostPosted: Mon May 28, 2007 11:09 am     Reply with quote

I'm using version 3.249 of the compiler.

You may be right... this may be a printf() problem. I'm using %.4f format (to display 4 digits after the decimal point but allow the front end to expand to fit the number of digits in the value). Is this part of the problem?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group