problem of conversion

Post your requests and ideas on the future development of mikroPascal PRO for PIC32.
Post Reply
Author
Message
brianho
Posts: 21
Joined: 10 Jul 2013 02:53

problem of conversion

#1 Post by brianho » 19 Dec 2013 04:57

Hi,

Below is a part of my program:

int f, location1, location2;
float ans;
float heartrate;

f = abs (location1 - location2);
heartrate = ((f*5)/1000);
ans = 1/heartrate;

There is a problem getting a correct float value of heartrate because f is an integer.
How can i get the correct float number?

tpetar
Posts: 593
Joined: 27 Apr 2012 18:44
Location: Pancevo, Serbia

Re: problem of conversion

#2 Post by tpetar » 19 Dec 2013 05:09

Hi,

Is this MikroPascal Pro or MikroC Pro ? :)

Do not use "f" use something other for example "fff".


Best regards,
Peter

brianho
Posts: 21
Joined: 10 Jul 2013 02:53

Re: problem of conversion

#3 Post by brianho » 19 Dec 2013 06:40

Hi,

it is mikcroC. it will be able to solve the problem by changing f to fff?

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: problem of conversion

#4 Post by filip » 23 Dec 2013 12:14

Hi,

The f should behave the same as fff, I have tried both variants and they worked OK.

Regards,
Filip.

tpetar
Posts: 593
Joined: 27 Apr 2012 18:44
Location: Pancevo, Serbia

Re: problem of conversion

#5 Post by tpetar » 23 Dec 2013 14:20

Hi,

I tried code in MikroC Pro.

With 'f' I get "'f' Identifier redefined", if 'f' is changed to 'ff' or 'fff' or something else code is compiled.

Best regards,
Peter

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: problem of conversion

#6 Post by dejan.odabasic » 24 Dec 2013 19:00

Hello,

@tpetar
mikroC PRO for PIC will give your "...Identifier redefined", but mikroC PRO for PIC32 will not.

@brianho
Try changing your calculation like this:

Code: Select all

int f, location1, location2;
float ans;
float heartrate;

f = abs (location1 - location2);
heartrate = ((f*5.0)/1000.0); // It will tell compiler to calculate with float numbers
// if your expression contains only integers calculation will be done on integers.
ans = 1/heartrate;
Best regards.

tpetar
Posts: 593
Joined: 27 Apr 2012 18:44
Location: Pancevo, Serbia

Re: problem of conversion

#7 Post by tpetar » 26 Dec 2013 18:30

Thank You Dejan & Filip,


Best regards,
Peter

Post Reply

Return to “mikroPascal PRO for PIC32 Wish List”