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

Log math function

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



Joined: 23 Aug 2006
Posts: 19

View user's profile Send private message Send e-mail

Log math function
PostPosted: Sat Feb 03, 2007 7:56 pm     Reply with quote

Hi, I have a problem with version 4.023 that doesn't exist in version 3.245. Basically the log function gives the wrong answer. In an otherwise unchanged program these are some results for the two versions:

3.245: log(50) gives 3.92, log(5) gives 1.509, both correct
4.023: log(50) gives 17.41, log(5) gives 0!

It took a loong time to find these as compiler bugs aren't the first I would supect. Would anybody please test this on their machines ? The processor is a PIC18LF258.

Also, has anyone found any problem with automatic casting from ints to floats ? I have an assignment like x = i, where x is a float and i is an unsigned int 16, and it does not work without a cast (float)i. I will try to make a small example demonstrating what I mean.

Best Regards, Thomas Johansson
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Feb 03, 2007 10:11 pm     Reply with quote

I think the problem is that when CCS did the change described in this
thread, that they shot themselves in the foot:
http://www.ccsinfo.com/forum/viewtopic.php?t=29735

Load the math.h file and scroll down to the log function. It starts with this:
Quote:

float log(float x)

There are two lines in it that access a byte within a float variable.
For version 4.023, you need to cast the address of the variable to
a char pointer. Then it will work.

Here are the two lines in the log() function, with the changes shown in bold:
Quote:

*((char *)&y) = 0x7E;

Quote:

n = *((char *)&x) - 0x7E;

Make those changes and recompile. It should now work OK.
thomasj50



Joined: 23 Aug 2006
Posts: 19

View user's profile Send private message Send e-mail

PostPosted: Sun Feb 04, 2007 7:25 pm     Reply with quote

Hi, yes it works after the proposed changes, thanks.

Haven't CCS heard of regression testing - if you change ANYTHING you have to test EVERYTHING ? In this particular case it is even simpler - have they tested the log function at all ? Perhaps the compiler is too cheap :-)

Thanks for the help,
Thomas Johansson
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 04, 2007 8:21 pm     Reply with quote

The lack of regression testing has been a complaint on here before.
How to make them do it ? I don't know.
thomasj50



Joined: 23 Aug 2006
Posts: 19

View user's profile Send private message Send e-mail

PostPosted: Wed Feb 14, 2007 10:47 pm     Reply with quote

I received a new math.h file from CCS that should correct the problem. Only one thing: they added two casts to int8 but it should have been int8*. Didn't they test their own corrections ? I had the two changes, one from this forum and one from CCS, choose CCS and got stuck with the same problem again. It took me several days to consider the change from CCS as the cause of the problem ...
thomasj
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