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 CCS Technical Support

Bug with math?

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



Joined: 01 Nov 2011
Posts: 3

View user's profile Send private message

Bug with math?
PostPosted: Tue Nov 01, 2011 5:30 am     Reply with quote

Hi,
I downloaded the evaluation version of the compiler because at the university I would compare it with C18.
I made this simply test program:

Code:

#include <18f46k22.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP

#device ANSI
#device PASS_STRINGS=IN_RAM

#use delay(clock=64000000, internal)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include "math.h"

void printResult(const char* text, float number){
   number=log10(number);
   printf("%s: %10.7f\r\n",text,number);
}

void main()
{
   printResult("Result",10);

   while(1);
   
}


I simulated it in MPSIM but the result of log10(10) is different than 1! The result is 0.00232....
Where I'm wrong?
Thank you
F
Battery David



Joined: 01 Feb 2010
Posts: 25

View user's profile Send private message

PostPosted: Tue Nov 01, 2011 8:02 am     Reply with quote

I tried this with your function but couldn't get it to work.

I popped the log10(xx) into a program I was working on and it gave me the correct result. I tried making xx an unsigned int8 and it still worked.

I'm using 4.125, what version are you using?

David
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Tue Nov 01, 2011 8:20 am     Reply with quote

Are you looking at what is actually printed out of the serial, or a 'watch'?.
Prints 'Result: 1.0000000' for me.
Has the sound of something like a watch window set to the wrong type. Remember a float uses the MCHP float format, not IEEE formats.
What is the actual version number of the demo compiler?.

Best Wishes
frank0204



Joined: 01 Nov 2011
Posts: 3

View user's profile Send private message

PostPosted: Tue Nov 01, 2011 12:07 pm     Reply with quote

Hi,
I'm using the evaluation version downloaded from the site.
From the "PIC version" window I see that the version is 4.122d "Limited evaluation".
I found what is the problem and it is related to the #device ANSI directive.
If delete this row and adjust the code the result of log10 is right.
Please use my code below to check the problem:

Code:

#include <18f46k22.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP

//Comment or Comment-out this define to see the problem.
//When _USE_ANSI_ defined the result of log10 is wrong
#define _USE_ANSI_

#ifdef _USE_ANSI_
   #device ANSI
#endif
#device PASS_STRINGS=IN_RAM

#use delay(clock=64000000, internal)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#include "math.h"

#ifdef _USE_ANSI_
   void printResult(const char* text, float number){
#else
   void printResult(char* text, float number){
#endif
   number=log10(number);
   printf("%s: %10.7f\r\n",text,number);
}

void main()
{
   printResult("Result",10);

   while(1);
   
}


the #device ANSI directive cannot be used with math functions?

Note: I tested the code both on MPLab Sim and on a real pic18f46k22: same behaviour.

Thanks
F
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 01, 2011 4:40 pm     Reply with quote

I got a similar failure in vs. 4.125. It appears that the math.h library has
not been tested in ANSI mode. Or at least the log10() function hasn't been
tested in that mode. However, most of us do not use ANSI mode so it's
not too much of an issue for us.
frank0204



Joined: 01 Nov 2011
Posts: 3

View user's profile Send private message

PostPosted: Tue Nov 01, 2011 5:11 pm     Reply with quote

Yes,
Same problems with ln, exp and pow.
The math library does not work with ANSI mode or is bugged.
So a porting from C18 can be very annoying...
Hope in the future the ANSI mode will be supported.
Thank you
F
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