Fixed is a 32b data type that presents a number in the fixed point
representation. Upper half (in big endian) holds its integer part,
while the lower one holds the fractional part and therefore there is
a scale of s=65536=2^16. This scale is used when converting a number
to its Fixed representation and during several operations such as
multiplication or division. That's why there's MulDiv because it is
more effective because scales cancel.
Whether the data type is signed or unsigned depends barely on YOU and
you should just use different arithmetic operations at the assembly
level (compiler does that for you). That is a reason why there are
some UnsignedFixed functions as these different arithmetic operations
has to be used.
If you want to get a number to its Fixed representation, you JUST
multiply it by the scale (s) and suppose it does not overflow you
obtain its fixed point representation after rounding to the nearest
that is often solved as adding 1/2 ulp.
Based on the previous statement, Float64ToUnsignedFixed macro first
multiplies a number with the scale s that gets it to a double
representation of a fixed data type and then adds a 1/2 ulp [unit in
the last place] to get the number rounded to its nearest Fixed
representation. Once that is done, the number gets cast to
UnsignedFixed. If you cast it to a Fixed instead, it will work the
same way.
The second macro, FractionOfUnsignedFixed simply omits the high
(integer) portion of an UnsignedFixed so the only fractional portion
of the UnsignedFixed remains and you obtain an absolute value of the
fractional part. That is absolutely OK because the entire number is
an absolute value anyway. Then the macro casts fractional part as a
double to get it into the floating point set and divides it by the
scale to get its unscaled value. I would probably use 65536.0 instead
of 65536 to tell the compiler that this number is a floating point
number but it should be able to find out automatically.
Concluding, I recommend to put there 65536.0 to be absolutely sure
what kind of division happens but otherwise the macro is OK.
It might be interesting to write FractionOfFixed because it would not
work to just mask off the high portion because we lose the sign.
Which way do you think is better?
Tomas
--
# Ing. Tomas Zahradnicky, Jr.
# The Czech Technical University
# Dept of Computer Science, FEE-CTU Prague
_______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-API mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-api/email@hidden