View previous topic :: View next topic |
Author |
Message |
thomasj50
Joined: 23 Aug 2006 Posts: 19
|
Log math function |
Posted: Sat Feb 03, 2007 7:56 pm |
|
|
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
|
|
Posted: Sat Feb 03, 2007 10:11 pm |
|
|
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
|
|
Posted: Sun Feb 04, 2007 7:25 pm |
|
|
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
|
|
Posted: Sun Feb 04, 2007 8:21 pm |
|
|
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
|
|
Posted: Wed Feb 14, 2007 10:47 pm |
|
|
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 |
|
|
|