Fixed Point Support

Fixed Point Support — Fixed Point API

Synopsis

typedef             ClutterFixed;
#define             CFX_ONE
#define             CFX_HALF
#define             CFX_MAX
#define             CFX_MIN
#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             CLUTTER_FIXED_TO_INT                (x)
#define             CLUTTER_FIXED_TO_FLOAT              (x)
#define             CLUTTER_FIXED_TO_DOUBLE             (x)
#define             CLUTTER_FLOAT_TO_FIXED              (x)
#define             CLUTTER_FLOAT_TO_INT                (x)
#define             CLUTTER_FLOAT_TO_UINT               (x)
#define             CLUTTER_INT_TO_FIXED                (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)
typedef             ClutterAngle;
#define             CLUTTER_ANGLE_FROM_DEG              (x)
#define             CLUTTER_ANGLE_FROM_DEGX             (x)
#define             CLUTTER_ANGLE_TO_DEG                (x)
#define             CLUTTER_ANGLE_TO_DEGX               (x)
#define             CLUTTER_ANGLE_MAX_DEG
#define             CFX_RADIANS_TO_DEGREES
#define             clutter_cosx                        (a)
#define             clutter_sinx                        (a)
#define             clutter_tanx                        (a)
#define             clutter_atanx                       (a)
#define             clutter_atan2x                      (x,y)
#define             clutter_qmulx                       (x,y)
#define             clutter_qdivx                       (x,y)

#define             CLUTTER_MAXFIXED
#define             CLUTTER_MINFIXED
                    ClutterParamSpecFixed;
GParamSpec*         clutter_param_spec_fixed            (const gchar *name,
                                                         const gchar *nick,
                                                         const gchar *blurb,
                                                         ClutterFixed minimum,
                                                         ClutterFixed maximum,
                                                         ClutterFixed default_value,
                                                         GParamFlags flags);
#define             CLUTTER_VALUE_HOLDS_FIXED           (x)
void                clutter_value_set_fixed             (GValue *value,
                                                         ClutterFixed fixed_);
ClutterFixed        clutter_value_get_fixed             (const GValue *value);

Description

Clutter has a fixed point API targeted at platforms without a floating point unit, such as embedded devices. On such platforms 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.

It is no recommened for use on platforms with a floating point unit (eg desktop systems) nor for use in bindings.

Basic rules of Fixed Point arithmethic:

  • Two fixed point numbers can be directly added, subtracted and have their modulus taken.

  • 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 and CLUTTER_FIXED_DIV macros.

Details

ClutterFixed

typedef float ClutterFixed;

Fixed point number (16.16)


CFX_ONE

#define CFX_ONE         1.0

1.0 represented as a fixed point value.


CFX_HALF

#define CFX_HALF        0.5

0.5 represented as a fixed point value.


CFX_MAX

#define CFX_MAX         G_MAXFLOAT

Maximum fixed point value.


CFX_MIN

#define CFX_MIN         (-G_MAXFLOAT)

Minimum fixed point value.


CFX_PI

#define CFX_PI          G_PI

Fixed point representation of Pi


CFX_2PI

#define CFX_2PI         (G_PI * 2)

Fixed point representation of Pi*2


CFX_PI_2

#define CFX_PI_2        (G_PI / 2)

Fixed point representation of Pi/2


CFX_PI_4

#define CFX_PI_4        (G_PI / 4)

Fixed point representation of Pi/4


CFX_120

#define CFX_120         120.0

Fixed point representation of the number 120


CFX_180

#define CFX_180         180.0

Fixed point representation of the number 180


CFX_240

#define CFX_240         240.0

Fixed point representation of the number 240


CFX_360

#define CFX_360         360.0

Fixed point representation of the number 360


CFX_60

#define CFX_60          60.0

Fixed point representation of the number 60


CFX_255

#define CFX_255         255.0

Fixed point representation of the number 255


CLUTTER_FIXED_TO_INT()

#define CLUTTER_FIXED_TO_INT(x)         ((int)(x))

Converts a fixed point value to integer (removing the decimal part).

x :

a fixed point value

Since 0.6


CLUTTER_FIXED_TO_FLOAT()

#define CLUTTER_FIXED_TO_FLOAT(x)       (x)

Convert a fixed point value to float.

x :

a fixed point value

CLUTTER_FIXED_TO_DOUBLE()

#define CLUTTER_FIXED_TO_DOUBLE(x)      ((double)(x))

Convert a fixed point value to double.

x :

a fixed point value

CLUTTER_FLOAT_TO_FIXED()

#define CLUTTER_FLOAT_TO_FIXED(x)       ((x))

Convert a float value to fixed.

x :

a floating point value

CLUTTER_FLOAT_TO_INT()

#define CLUTTER_FLOAT_TO_INT(x)         ((int)(x))

Convert a float value to int.

x :

a floating point value

CLUTTER_FLOAT_TO_UINT()

#define CLUTTER_FLOAT_TO_UINT(x)        ((unsigned int)(x))

Convert a float value to unsigned int.

x :

a floating point value

CLUTTER_INT_TO_FIXED()

#define CLUTTER_INT_TO_FIXED(x)         ((float)(x))

Convert an integer value to fixed point.

x :

an integer value

CLUTTER_FIXED_FRACTION()

#define CLUTTER_FIXED_FRACTION(x)       ((x)-floorf (x))

Retrieves the fractionary part of a fixed point value

x :

a fixed point value

CLUTTER_FIXED_FLOOR()

#define CLUTTER_FIXED_FLOOR(x)          (floorf (x))

Round down a fixed point value to an integer.

x :

a fixed point value

CLUTTER_FIXED_CEIL()

#define CLUTTER_FIXED_CEIL(x)           (ceilf (x))

Round up a fixed point value to an integer.

x :

a fixed point value

CLUTTER_FIXED_MUL()

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

Multiply two fixed point values

x :

a fixed point value

y :

a fixed point value

CLUTTER_FIXED_DIV()

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

Divide two fixed point values

x :

a fixed point value

y :

a fixed point value

ClutterAngle

typedef float ClutterAngle;

An abstract representation of an angle.


CLUTTER_ANGLE_FROM_DEG()

#define CLUTTER_ANGLE_FROM_DEG(x)  ((float)(x))

x :


CLUTTER_ANGLE_FROM_DEGX()

#define CLUTTER_ANGLE_FROM_DEGX(x) (CLUTTER_FIXED_TO_FLOAT (x))

x :


CLUTTER_ANGLE_TO_DEG()

#define CLUTTER_ANGLE_TO_DEG(x)    ((float)(x))

x :


CLUTTER_ANGLE_TO_DEGX()

#define CLUTTER_ANGLE_TO_DEGX(x)   (CLUTTER_FLOAT_TO_FIXED (x))

x :


CLUTTER_ANGLE_MAX_DEG

#define CLUTTER_ANGLE_MAX_DEG 1509949439.6


CFX_RADIANS_TO_DEGREES

#define CFX_RADIANS_TO_DEGREES  (180.0 / G_PI)

Fixed point representation of the number 180 / pi


clutter_cosx()

#define clutter_cosx(a)                 cosf (a * (G_PI/180.0))

a :


clutter_sinx()

#define clutter_sinx(a)                 sinf (a * (G_PI/180.0))

a :

Returns :


clutter_tanx()

#define clutter_tanx(a)                 tanf (a * (G_PI/180.0))

a :


clutter_atanx()

#define clutter_atanx(a)                atanf (a * (G_PI/180.0))

a :


clutter_atan2x()

#define clutter_atan2x(x,y)             atan2f (x, y)

x :

y :


clutter_qmulx()

#define clutter_qmulx(x,y)              ((x) * (y))

x :

y :

Returns :


clutter_qdivx()

#define clutter_qdivx(x,y)              ((x) / (y))

x :

y :

Returns :


CLUTTER_MAXFIXED

#define CLUTTER_MAXFIXED        G_MAXFLOAT

Higher boundary for ClutterFixed

Since 0.8


CLUTTER_MINFIXED

#define CLUTTER_MINFIXED        (-G_MAXFLOAT)

Lower boundary for ClutterFixed

Since 0.8


ClutterParamSpecFixed

typedef struct {
  ClutterFixed  minimum;
  ClutterFixed  maximum;
  ClutterFixed  default_value;
} ClutterParamSpecFixed;

GParamSpec subclass for fixed point based properties

ClutterFixed minimum;

lower boundary

ClutterFixed maximum;

higher boundary

ClutterFixed default_value;

default value

Since 0.8


clutter_param_spec_fixed ()

GParamSpec*         clutter_param_spec_fixed            (const gchar *name,
                                                         const gchar *nick,
                                                         const gchar *blurb,
                                                         ClutterFixed minimum,
                                                         ClutterFixed maximum,
                                                         ClutterFixed default_value,
                                                         GParamFlags flags);

Creates a GParamSpec for properties using ClutterFixed values

name :

name of the property

nick :

short name

blurb :

description (can be translatable)

minimum :

lower boundary

maximum :

higher boundary

default_value :

default value

flags :

flags for the param spec

Returns :

the newly created GParamSpec

Since 0.8


CLUTTER_VALUE_HOLDS_FIXED()

#define CLUTTER_VALUE_HOLDS_FIXED(x)    (G_VALUE_HOLDS ((x), CLUTTER_TYPE_FIXED))

Evaluates to TRUE if x holds a ClutterFixed.

x :

a GValue

Since 0.8


clutter_value_set_fixed ()

void                clutter_value_set_fixed             (GValue *value,
                                                         ClutterFixed fixed_);

Sets value to fixed_.

value :

a GValue initialized to CLUTTER_TYPE_FIXED

fixed_ :

the fixed point value to set

Since 0.8


clutter_value_get_fixed ()

ClutterFixed        clutter_value_get_fixed             (const GValue *value);

Gets the fixed point value stored inside value.

value :

a GValue initialized to CLUTTER_TYPE_FIXED

Returns :

the value inside the passed GValue

Since 0.8