clutter-fixed

clutter-fixed — Fixed point API

Synopsis




typedef     ClutterFixed;
#define     CFX_Q
#define     CFX_ONE
#define     CFX_MAX
#define     CFX_MIN
typedef     ClutterAngle;
#define     CFX_PI
#define     CFX_2PI
#define     CFX_PI_2
#define     CFX_PI_4
#define     CFX_120
#define     CFX_180
#define     CFX_240
#define     CFX_360
#define     CFX_60
#define     CFX_255
#define     CFX_DIV
#define     CFX_INT
#define     CFX_MUL
#define     CLUTTER_FIXED_TO_FLOAT          (x)
#define     CLUTTER_FIXED_TO_DOUBLE         (x)
#define     CLUTTER_FLOAT_TO_FIXED          (x)
#define     CLUTTER_INT_TO_FIXED            (x)
#define     CLUTTER_FIXED_INT               (x)
#define     CLUTTER_FIXED_FRACTION          (x)
#define     CLUTTER_FIXED_FLOOR             (x)
#define     CLUTTER_FIXED_CEIL              (x)
#define     CLUTTER_FIXED_MUL               (x,y)
#define     CLUTTER_FIXED_DIV               (x,y)
#define     clutter_cosi                    (angle)
#define     clutter_cosx                    (angle)
ClutterFixed clutter_sini                   (ClutterAngle angle);
ClutterFixed clutter_sinx                   (ClutterFixed angle);
gint        clutter_sqrti                   (gint x);
ClutterFixed clutter_sqrtx                  (ClutterFixed x);

Description

Clutter has a fixed point API targeted at platforms without a floating point unit, such as embedded devices. This API should be preferred to the floating point one as it does not trigger the slow path of software emulation, relying on integer math for fixed-to-floating and floating-to-fixed conversion.

Basic Rules of Fixed Point Arithmetic

  • Two fixed point numbers can be directly added and subtracted.

  • To add other numerical type to a fixed point number it has to be first converted to fixed point.

  • A fixed point number can be directly multiplied or divided by an integer.

  • Two fixed point numbers can only be multiplied and divided by the provided CLUTTER_FIXED_MUL (aka CFX_MUL) and CLUTTER_FIXED_DIV (aka CFX_DIV) macros.

Details

ClutterFixed

typedef gint32 ClutterFixed;

Fixed point number (16.16)


CFX_Q

#define CFX_Q      16		/* Decimal part size in bits */

Number of bits used to store fractional part of ClutterFixed.


CFX_ONE

#define CFX_ONE    (1 << CFX_Q)	/* 1 */

ClutterFixed representation of 1.


CFX_MAX

#define CFX_MAX    0x7fffffff

Maximum number representable by ClutterFixed.


CFX_MIN

#define CFX_MIN    0x80000000

Minumum number representable by ClutterFixed.


ClutterAngle

typedef gint32 ClutterAngle;    /* angle such that 1024 == 2*PI */

Integer representation of an angle such that 1024 corresponds to full circle (i.e., 2*Pi).


CFX_PI

#define CFX_PI     0x0003243f

Fixed point representation of Pi


CFX_2PI

#define CFX_2PI    0x0006487f

Fixed point representation of Pi*2


CFX_PI_2

#define CFX_PI_2   0x00019220   /* pi/2 */


CFX_PI_4

#define CFX_PI_4   0x0000c910   /* pi/4 */


CFX_120

#define CFX_120 CLUTTER_INT_TO_FIXED (120)

Fixed point representation of the number 120


CFX_180

#define CFX_180 CLUTTER_INT_TO_FIXED (180)

Fixed point representation of the number 180


CFX_240

#define CFX_240 CLUTTER_INT_TO_FIXED (240)

Fixed point representation of the number 240


CFX_360

#define CFX_360 CLUTTER_INT_TO_FIXED (360)

Fixed point representation of the number 360


CFX_60

#define CFX_60  CLUTTER_INT_TO_FIXED (60)

Fixed point representation of the number 60


CFX_255

#define CFX_255 CLUTTER_INT_TO_FIXED (255)

Fixed point representation of the number 255


CFX_DIV

#define CFX_DIV CLUTTER_FIXED_DIV

Alias for CLUTTER_FIXED_DIV.


CFX_INT

#define CFX_INT CLUTTER_FIXED_INT

Alias for CLUTTER_FIXED_INT.


CFX_MUL

#define CFX_MUL CLUTTER_FIXED_MUL

Alias for CLUTTER_FIXED_MUL.


CLUTTER_FIXED_TO_FLOAT()

#define CLUTTER_FIXED_TO_FLOAT(x)       ((float) ((int)(x) / 65536.0))

Macro for converting ClutterFixed to single precission floating point.


CLUTTER_FIXED_TO_DOUBLE()

#define CLUTTER_FIXED_TO_DOUBLE(x)      ((double) ((int)(x) / 65536.0))

Macro for converting ClutterFixed to double precission floating point.


CLUTTER_FLOAT_TO_FIXED()

#define CLUTTER_FLOAT_TO_FIXED(x) _clutter_double_to_fixed((x))

Macro for converting floating point numbers to ClutterFixed.

x : double or float

CLUTTER_INT_TO_FIXED()

#define CLUTTER_INT_TO_FIXED(x) ((x) << CFX_Q)

Macro for converting integers to ClutterFixed.

x : int

CLUTTER_FIXED_INT()

#define CLUTTER_FIXED_INT(x)            ((x) >> CFX_Q)

Macro to obtain integer part of ClutterFixed.


CLUTTER_FIXED_FRACTION()

#define CLUTTER_FIXED_FRACTION(x)       ((x) & ((1 << CFX_Q) - 1))

Macro to obtain the fraction of ClutterFixed.


CLUTTER_FIXED_FLOOR()

#define     CLUTTER_FIXED_FLOOR(x)

Macro to obtain greatest integer smaller than given ClutterFixed.


CLUTTER_FIXED_CEIL()

#define CLUTTER_FIXED_CEIL(x) CLUTTER_FIXED_FLOOR(x + 0xffff) 

Macro to obtain smallest integer greater than given ClutterFixed.


CLUTTER_FIXED_MUL()

#define CLUTTER_FIXED_MUL(x,y) ((x) >> 8) * ((y) >> 8)

Macro for multiplication of two ClutterFixed numbers.


CLUTTER_FIXED_DIV()

#define CLUTTER_FIXED_DIV(x,y) ((((x) << 8)/(y)) << 8)

Macro for difvision of two ClutterFixed numbers.


clutter_cosi()

#define clutter_cosi(angle) clutter_sini((angle) - 256)

Very fast fixed point implementation of cosine function.

ClutterAngle is an integer such that 1024 represents full circle.

angle : a ClutterAngle angle

Since 0.2


clutter_cosx()

#define clutter_cosx(angle) clutter_fixed_sin((angle) - CFX_PI_2)

Fixed point cosine function

angle : a ClutterFixed angle in radians

Since 0.2


clutter_sini ()

ClutterFixed clutter_sini                   (ClutterAngle angle);

Very fast fixed point implementation of sine function.

ClutterAngle is an integer such that 1024 represents full circle.

angle : a ClutterAngle
Returns : ClutterFixed sine value.

Since 0.2


clutter_sinx ()

ClutterFixed clutter_sinx                   (ClutterFixed angle);

Fixed point implementation of sine function

angle : a ClutterFixed angle in radians
Returns : ClutterFixed sine value.

Since 0.2


clutter_sqrti ()

gint        clutter_sqrti                   (gint x);

Very fast fixed point implementation of square root for integers.

This function is about 10x faster than clib sqrt() on x86, and (this is not a typo!) more than 800x faster on ARM without FPU. It's error is < 5% for arguments < 132 and < 10% for arguments < 5591.

x : integer value
Returns : integer square root.

Since 0.2


clutter_sqrtx ()

ClutterFixed clutter_sqrtx                  (ClutterFixed x);

A fixed point implementation of squre root

x : a ClutterFixed
Returns : ClutterFixed square root.

Since 0.2