MLib Alpha 1 API Reference

MLib Alpha 1 API Reference

Fixed Point

the M_Fix16 type is used to model a fixed-point number with 16 bits of fractional bits. This section presents macros, types and functions used to manage these numbers.


M_Fix16


  typedef M_Int32   M_Fix16;

this type is used to store and operate on 16.16 fixed float numbers.



M_FIX16_MAX


#define  M_FIX16_MAX    ((M_Fix16)0x7FFFFFF)

the biggest M_Fix16 number



M_FIX16_MIN


#define  M_FIX16_MIN    ((M_Fix16)0x8000001)

the smallest M_Fix16 number



m_fix16_add


#define  m_fix16_add(x,y)    ((x)+(y))

returns the sum of two fix16 numbers


note

this macro doesn't check overflows


m_fix16_sub


#define  m_fix16_sub(x,y)    ((x)-(y))

returns the difference of two fix16 numbers


note

this macro doesn't check underflows


m_fix16_mul


  MLIB_API(M_Fix16)   m_fix16_mul( M_Fix16   a,
                                   M_Fix16   b );

returns the product of two M_Fix16 number.


input
a

first number

b

second number

result

the product of "a" and "b".

note

this really computes 'a*b/0x10000' with 64 bits of accuracy.

this function returns M_FIX16_MAX or M_FIX16_MIN in case of overflow..


m_fix16_div


  MLIB_API(M_Fix16)   m_fix16_div( M_Fix16   a,
                                   M_Fix16   b );

returns the division of two M_Fix16 number.


input
a

first number

b

second number

result

the value of "a" divided by "b" in 16.16 format

note

this really computes 'a*0x10000/b' with 64 bits of accuracy

this function returns M_FIX16_MAX or M_FIX16_MIN in case of overflow (e.g. divide by 0)


m_fix16_muldiv


  MLIB_API(M_Fix16)   m_fix16_muldiv( M_Fix16    a,
                                      M_Fix16    b,
                                      M_Fix16    c );

returns the value of "a*b/c", computed with maximal accuracy


input
a

first number

b

second number

c

third number

result

the value of "a*b/c" in 16.16 format

note

this really computes 'a*b/c" with 64 bits of accuracy

this function returns M_FIX16_MAX or M_FIX16_MIN in case of overflow (e.g. divide by 0)


m_fix16_sqrt


  MLIB_API(M_Fix16)   m_fix16_sqrt( M_Fix16  a );

returns the square root of a M_Fix16 number


input
a

number

result

square root. 0 if "a" was <= 0


m_fix16_qmul


  MLIB_API(M_Fix16)   m_fix16_qmul( M_Fix16    a,
                                    M_Fix16    b );

a variant of m_fix16_mul that can be used when all arguments are positive. it DOESN'T CHECK OVERFLOWS !!


input
a

first number

b

second number

result

the product of "a" and "b".


m_fix16_qdiv


  MLIB_API(M_Fix16)   m_fix16_qdiv( M_Fix16    a,
                                    M_Fix16    b );

a variant of m_fix16_div that can be used when all arguments are positive. it DOESN'T CHECK OVERFLOWS !!


input
a

first number

b

second number

result

the division of "a" by "b"


m_fix16_qmuldiv


  MLIB_API(M_Fix16)   m_fix16_qmuldiv( M_Fix16   a,
                                       M_Fix16   b,
                                       M_Fix16   c );

a variant of m_fix16_muldiv that can be used when all arguments are positive. it DOESN'T CHECK OVERFLOWS !!


input
a

first number

b

second number

c

third number

result

the result of "a*b/c"


generated on Tue Oct 09 23:59:46 2001