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

FMOD() utilisation - Division a float by a float

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







FMOD() utilisation - Division a float by a float
PostPosted: Mon Apr 02, 2007 2:01 pm     Reply with quote

Hello !!! excuse for my english but I'm a french boy....

I'have got a problem, I want to make a simple division (Float by an another float) but impossible :

Here my script in few lines....Please help me....


//---------------------------------------
#include <16F877A.h>
#use delay(clock=20000000)
//----------------------------------------
#include "math.h"
#include "float.h"
//----------------------------------------

void main (void)
{

float result;
float val1=150.0;
float val2=0.54;

result=fmod(val1,val2); // At this line, the Step mode open the
// source code of "math.h" and stop
// the execution
}

I don't understand because the syntaxe is the same than CCS_manual.pdf



thanks before
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 02, 2007 2:09 pm     Reply with quote

I tested your code with compiler vs. 3.249, and with MPLAB vs. 7.20.
It worked OK. I pressed the F8 key, to "Step over". It goes to the
fmod() routine in math.h, and then it goes to the floor() routine, and
then it exits math.h and goes back to the main() code.

What is your compiler version ? What is your version of MPLAB ?
Are you pressing the F8 key ?
kevcon



Joined: 21 Feb 2007
Posts: 142
Location: Michigan, USA

View user's profile Send private message

PostPosted: Mon Apr 02, 2007 2:09 pm     Reply with quote

What did you get for result?

I got 0.419998169
Joseph
Guest







PostPosted: Mon Apr 02, 2007 2:18 pm     Reply with quote

Ohhhhhhh oki

For me when I am in the code source of math.h its an error..... so the script is ok....thanks

But an another question.....150 / 0.54 = 277.77 and not 0.41 Why ???

I am a newbe.....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 02, 2007 3:33 pm     Reply with quote

Apparently fmod() is not very accurate:

http://support.microsoft.com/kb/57479
kevcon



Joined: 21 Feb 2007
Posts: 142
Location: Michigan, USA

View user's profile Send private message

PostPosted: Tue Apr 03, 2007 7:14 am     Reply with quote

I noticed that too, the result int this case should be 0.42 not 0.419998169
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