Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

regarding Float calculations in Keil C

Status
Not open for further replies.

yviswanathbe

Full Member level 4
Joined
Jun 14, 2007
Messages
221
Helped
10
Reputation
20
Reaction score
6
Trophy points
1,298
Activity points
3,066
Hi Friends,

I am facing problem with Float variable in my program.

Code:
void DAC_SET(void)	 
{
    float crange, scale;
    crange=(65535/40); //the result should be 1638.375 but i am getting 1638 integer part only.
    scale=temprecord.current; //user desired value stored in a structure
    DAC_Count=crange*scale;
}

I am using keil microvision 3. I have included MATH.H
C51FPS.LIB is exists in the LIB folder.
Whats wrong i am doing here.

somebody please help me?

Thanks and Regards,
Viswanath.
 

Hi Friend

Code:
void DAC_SET(void)	 
{
    float crange, scale;
    crange=(65535/40); //the result should be 1638.375 but i am getting 1638 integer part only.
    scale=temprecord.current; //user desired value stored in a structure
    DAC_Count=crange*scale;
}


In your Code , Both value 65535 and 40 are Integer.
For this reason it create integer result

Try this line

crange=(65535/40.0);
or
crange=(65535.0/40);
or
crange=(float)(65535/40);

it is casting problem.

Shyam
INDIA
 
Any change in settings of the compiler?

---------- Post added at 09:25 ---------- Previous post was at 09:24 ----------

crange=(float)(65535/40);
is desirable.
Regards,
Jerin.
 
Hi Shyam and Jerin,

Its working now.

Thanks for your help.

Regards,
Viswanath
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top