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

v4 _fixed(x) math

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



Joined: 02 Mar 2006
Posts: 9

View user's profile Send private message

v4 _fixed(x) math
PostPosted: Mon Aug 27, 2007 11:18 am     Reply with quote

trying to port some old code that used some float math to 4.051, I was planning on using only fixed vars now.

first, when I declare the var (I know this is probably a stupid question):
Code:
signed _fixed(2) int16 stuff;

when I hover over stuff later on the popup says "variable VOID:FP2 stuff" the "void" has me nervous. is this declaring what I think it is; a number between -327.68 and 327.68?

When I assign int values to fixed vars, it should be transparent, right?
Code:

signed int16 int_stuff = 123;
signed _fixed(2) int16 fixed_stuff;

fixed_stuff = int_stuff;      // fixed_stuff should = 123.00 now
fixed_stuff *= 0.54;         // fixed_stuff should = 66.42
int_stuff = fixed_stuff;     // int_stuff should = 66


one more question: when I multiply or add different fixed numbers, when does truncation happen?
Code:

signed int16 _fixed(1) fix1 = 1.2;
signed int16 _fixed(2) fix2 = 1.23;
signed int16 _fixed(2) answer;

answer = fix1 * fix2;

what is answer now?


Thanks[/code]
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