Joules
Joined: 02 Mar 2006 Posts: 9
|
v4 _fixed(x) math |
Posted: Mon Aug 27, 2007 11:18 am |
|
|
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] |
|