Floating point diveded by 2

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Floating point diveded by 2

Post by Jan Lichtenbelt »

Is it possible to divide a floating point variable A by 2 in the following way?

A>>1

Or must it be done by a floating point division


Kind regards

Jan Lichtenbelt

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Floating point diveded by 2

Post by Benj »

Hi Jan,

I'm not too sure about this one. I have a feeling it won't work but why not give it a go on the hardware and let us know your results. It certainly won't hurt anything.

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: Floating point diveded by 2

Post by Jan Lichtenbelt »

OK, You are right. I could check it myself. Here are the results

A is a floating point variable, in my example 4.321

respectively: A>>1 , A/2 , fdiv(A,2)
Simulation: 2.000000 2.160500 2.160500
PIC-Hardware: 0.000000 0.000000 2.160500

So the only correct way is using the fdiv() function

regards

Jan

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Floating point diveded by 2

Post by Benj »

Hi Jan,

Thanks for letting us know. I had a feeling it wouldn't be that simple but glad you tested it to be sure.

Post Reply