|
|
View previous topic :: View next topic |
Author |
Message |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
floating point |
Posted: Tue Mar 08, 2011 1:53 pm |
|
|
Hi There,
Why would this:
Code: |
fprintf(DEBUG,"%f * %f = %f\r\n",(float)scldpotval1,(float)scaler,(float)scldpotval1*(float)scaler);
|
Give me something like
33776.00 * 1.48 = 50000.00
scldpotval1 and scaler, both are of type float
I don't understand
compiler 4.119, 18f87k22 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 08, 2011 2:14 pm |
|
|
With no test program, it's tough to know exactly what you're doing.
But if I compile the following program with vs. 4.119 and run it in
MPLAB simulator, I get this:
Quote: | 33776.00 * 1.48 = 49988.48
|
Code: |
#include <18F87K22.h>
#fuses XT, NOWDT, PUT, BROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600, UART1, errors, stream=DEBUG)
//========================================
void main()
{
float scldpotval1 = 33776.00;
float scaler = 1.48;
fprintf(DEBUG,"%f * %f = %f\r\n",(float)scldpotval1,(float)scaler,(float)scldpotval1*(float)scaler);
while(1);
} |
Always post a test program so we can duplicate your test environment.
Otherwise we're just guessing, and it may be a waste of time. |
|
|
|
|
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
|