Dave Bryner

Fractional Arithmetic

Discussion created by Dave Bryner on Feb 20, 2008
Latest reply on Feb 26, 2008 by Pascal Irrle
I'm having the hardest time wraping my brain around Fractional data types.

I need to convert integers, such as the values returned from the ADC,
and floats, such as 0.3835545, to Fract16 values.

In the application note an1772.pdf I found these to be almost useful...
#define _CI(X) *(INT )&(X) /* Convert to int */
#define _CPI(X) (INT *)(X) /* Convert to pointer to int */
#define _CLI(X) *(long int *)&(X) /* Convert to long */
#define _CF(X) *(_fract *)&(X) /* Convert to fractional */
#define _CPF(X) (_fract *)(X) /* Convert to pointer to fract. */
#define _CLF(X) *(long _fract *)&(X) /* Convert to long fract.

except there is no definition of _fract.

Does anyone have working macros to do this?

Thanks for any help

Outcomes