cpg-math

cpg-math — Math function/operators

Synopsis

enum                CpgMathOperatorType;
enum                CpgMathFunctionType;
CpgMathFunctionType cpg_math_function_lookup            (const gchar *name,
                                                         gint *arguments);
gdouble             cpg_math_constant_lookup            (const gchar *name,
                                                         gboolean *found);
CpgMathOperatorType cpg_math_operator_lookup            (CpgMathOperatorType type);
void                cpg_math_function_execute           (CpgMathFunctionType type,
                                                         gint numargs,
                                                         CpgStack *stack);
void                cpg_math_operator_execute           (CpgMathOperatorType type,
                                                         gint numargs,
                                                         CpgStack *stack);
gboolean            cpg_math_function_is_constant       (CpgMathFunctionType type);
gboolean            cpg_math_operator_is_constant       (CpgMathOperatorType type);
gboolean            cpg_math_function_is_variable       (CpgMathFunctionType type);
gboolean            cpg_math_operator_is_variable       (CpgMathOperatorType type);
gboolean            cpg_math_function_is_commutative    (CpgMathFunctionType type);
gboolean            cpg_math_operator_is_commutative    (CpgMathOperatorType type);
const gchar *       cpg_math_function_lookup_by_id      (CpgMathFunctionType type,
                                                         gint *arguments);

Object Hierarchy

  GEnum
   +----CpgMathOperatorType
  GEnum
   +----CpgMathFunctionType

Description

Math expression helper functions.

Details

enum CpgMathOperatorType

typedef enum
{
	CPG_MATH_OPERATOR_TYPE_NONE = 0,
	CPG_MATH_OPERATOR_TYPE_UNARY_MINUS,
	CPG_MATH_OPERATOR_TYPE_MINUS,
	CPG_MATH_OPERATOR_TYPE_PLUS,
	CPG_MATH_OPERATOR_TYPE_MULTIPLY,
	CPG_MATH_OPERATOR_TYPE_DIVIDE,
	CPG_MATH_OPERATOR_TYPE_MODULO,
	CPG_MATH_OPERATOR_TYPE_POWER,
	CPG_MATH_OPERATOR_TYPE_GREATER,
	CPG_MATH_OPERATOR_TYPE_LESS,
	CPG_MATH_OPERATOR_TYPE_GREATER_OR_EQUAL,
	CPG_MATH_OPERATOR_TYPE_LESS_OR_EQUAL,
	CPG_MATH_OPERATOR_TYPE_EQUAL,
	CPG_MATH_OPERATOR_TYPE_OR,
	CPG_MATH_OPERATOR_TYPE_AND,
	CPG_MATH_OPERATOR_TYPE_NEGATE,
	CPG_MATH_OPERATOR_TYPE_TERNARY,
	CPG_MATH_OPERATOR_TYPE_NUM
} CpgMathOperatorType;

Operator types.

CPG_MATH_OPERATOR_TYPE_NONE

none

CPG_MATH_OPERATOR_TYPE_UNARY_MINUS

unary minus

CPG_MATH_OPERATOR_TYPE_MINUS

minus

CPG_MATH_OPERATOR_TYPE_PLUS

plus

CPG_MATH_OPERATOR_TYPE_MULTIPLY

multiply

CPG_MATH_OPERATOR_TYPE_DIVIDE

divide

CPG_MATH_OPERATOR_TYPE_MODULO

modulo

CPG_MATH_OPERATOR_TYPE_POWER

power

CPG_MATH_OPERATOR_TYPE_GREATER

greater

CPG_MATH_OPERATOR_TYPE_LESS

less

CPG_MATH_OPERATOR_TYPE_GREATER_OR_EQUAL

greater or equal

CPG_MATH_OPERATOR_TYPE_LESS_OR_EQUAL

less or equal

CPG_MATH_OPERATOR_TYPE_EQUAL

equal

CPG_MATH_OPERATOR_TYPE_OR

or

CPG_MATH_OPERATOR_TYPE_AND

and

CPG_MATH_OPERATOR_TYPE_NEGATE

negate

CPG_MATH_OPERATOR_TYPE_TERNARY

ternary

CPG_MATH_OPERATOR_TYPE_NUM

number of operators

enum CpgMathFunctionType

typedef enum
{
	CPG_MATH_FUNCTION_TYPE_NONE = 0,
	CPG_MATH_FUNCTION_TYPE_SIN,
	CPG_MATH_FUNCTION_TYPE_COS,
	CPG_MATH_FUNCTION_TYPE_TAN,
	CPG_MATH_FUNCTION_TYPE_ASIN,
	CPG_MATH_FUNCTION_TYPE_ACOS,
	CPG_MATH_FUNCTION_TYPE_ATAN,
	CPG_MATH_FUNCTION_TYPE_ATAN2,
	CPG_MATH_FUNCTION_TYPE_SQRT,
	CPG_MATH_FUNCTION_TYPE_INVSQRT,
	CPG_MATH_FUNCTION_TYPE_MIN,
	CPG_MATH_FUNCTION_TYPE_MAX,
	CPG_MATH_FUNCTION_TYPE_EXP,
	CPG_MATH_FUNCTION_TYPE_FLOOR,
	CPG_MATH_FUNCTION_TYPE_CEIL,
	CPG_MATH_FUNCTION_TYPE_ROUND,
	CPG_MATH_FUNCTION_TYPE_ABS,
	CPG_MATH_FUNCTION_TYPE_POW,
	CPG_MATH_FUNCTION_TYPE_RAND,
	CPG_MATH_FUNCTION_TYPE_LN,
	CPG_MATH_FUNCTION_TYPE_LOG10,
	CPG_MATH_FUNCTION_TYPE_HYPOT,
	CPG_MATH_FUNCTION_TYPE_EXP2,
	CPG_MATH_FUNCTION_TYPE_SINH,
	CPG_MATH_FUNCTION_TYPE_COSH,
	CPG_MATH_FUNCTION_TYPE_TANH,
	CPG_MATH_FUNCTION_TYPE_LERP,
	CPG_MATH_FUNCTION_TYPE_SQSUM,
	CPG_MATH_FUNCTION_TYPE_SIGN,
	CPG_MATH_FUNCTION_TYPE_CSIGN,
	CPG_MATH_FUNCTION_TYPE_CLIP,
	CPG_MATH_FUNCTION_TYPE_CYCLE,
	CPG_MATH_FUNCTION_TYPE_NUM
} CpgMathFunctionType;

Function types.

CPG_MATH_FUNCTION_TYPE_NONE

none

CPG_MATH_FUNCTION_TYPE_SIN

sine

CPG_MATH_FUNCTION_TYPE_COS

cosine

CPG_MATH_FUNCTION_TYPE_TAN

tangent

CPG_MATH_FUNCTION_TYPE_ASIN

arc sine

CPG_MATH_FUNCTION_TYPE_ACOS

arc cosine

CPG_MATH_FUNCTION_TYPE_ATAN

arc tangent

CPG_MATH_FUNCTION_TYPE_ATAN2

arc tangent 2

CPG_MATH_FUNCTION_TYPE_SQRT

square root

CPG_MATH_FUNCTION_TYPE_INVSQRT

inverse sequare root

CPG_MATH_FUNCTION_TYPE_MIN

min

CPG_MATH_FUNCTION_TYPE_MAX

max

CPG_MATH_FUNCTION_TYPE_EXP

exponential

CPG_MATH_FUNCTION_TYPE_FLOOR

floor

CPG_MATH_FUNCTION_TYPE_CEIL

ceil

CPG_MATH_FUNCTION_TYPE_ROUND

round

CPG_MATH_FUNCTION_TYPE_ABS

absolute

CPG_MATH_FUNCTION_TYPE_POW

power

CPG_MATH_FUNCTION_TYPE_RAND

random

CPG_MATH_FUNCTION_TYPE_LN

natural logarithm

CPG_MATH_FUNCTION_TYPE_LOG10

base 10 logarithm

CPG_MATH_FUNCTION_TYPE_HYPOT

euclidean distance

CPG_MATH_FUNCTION_TYPE_EXP2

base-2 exponential

CPG_MATH_FUNCTION_TYPE_SINH

hyperbolic sine

CPG_MATH_FUNCTION_TYPE_COSH

hyperbolic consine

CPG_MATH_FUNCTION_TYPE_TANH

hyperbolic tangent

CPG_MATH_FUNCTION_TYPE_LERP

linear interpolation

CPG_MATH_FUNCTION_TYPE_SQSUM

squared sum

CPG_MATH_FUNCTION_TYPE_SIGN

sign

CPG_MATH_FUNCTION_TYPE_CSIGN

copy sign

CPG_MATH_FUNCTION_TYPE_CLIP

clip

CPG_MATH_FUNCTION_TYPE_CYCLE

cycle

CPG_MATH_FUNCTION_TYPE_NUM

number of function types

cpg_math_function_lookup ()

CpgMathFunctionType cpg_math_function_lookup            (const gchar *name,
                                                         gint *arguments);

Lookup a math function given the name name and number of arguments.

name :

The function name

arguments :

The number of arguments. [out]

Returns :

A CpgMathFunctionType

cpg_math_constant_lookup ()

gdouble             cpg_math_constant_lookup            (const gchar *name,
                                                         gboolean *found);

Get the value of a constant. Valid constants are: pi, PI, e, E, NAN, nan, NaN, Inf, INF, inf.

name :

The name of the constant

found :

Return value whether or not the constant could be found

Returns :

the value of a constant

cpg_math_operator_lookup ()

CpgMathOperatorType cpg_math_operator_lookup            (CpgMathOperatorType type);

Lookup the operator type for a certain operator type.

type :

A CpgMathOperatorType

Returns :

A CpgMathOperatorType

cpg_math_function_execute ()

void                cpg_math_function_execute           (CpgMathFunctionType type,
                                                         gint numargs,
                                                         CpgStack *stack);

Execute a math function on the stack.

type :

A CpgMathFunctionType

stack :

A CpgStack

cpg_math_operator_execute ()

void                cpg_math_operator_execute           (CpgMathOperatorType type,
                                                         gint numargs,
                                                         CpgStack *stack);

Execute an operator on the stack.

type :

A CpgMathOperatorType

stack :

A CpgStack

cpg_math_function_is_constant ()

gboolean            cpg_math_function_is_constant       (CpgMathFunctionType type);

Get whether a math function is constant (i.e. if it is deterministic). An example of a function that is not constant is 'rand'.

type :

A CpgMathFunctionType

Returns :

TRUE if the function is constant, FALSE otherwise

cpg_math_operator_is_constant ()

gboolean            cpg_math_operator_is_constant       (CpgMathOperatorType type);

Get whether an operator is constant (i.e. if it is deterministic).

type :

A CpgMathOperatorType

Returns :

TRUE if the operator is constant, FALSE otherwise

cpg_math_function_is_variable ()

gboolean            cpg_math_function_is_variable       (CpgMathFunctionType type);

Get whether the math function accepts a variable number of arguments.

type :

A CpgMathFunctionType

Returns :

TRUE if the function accepts a variable number of arguments, FALSE otherwise

cpg_math_operator_is_variable ()

gboolean            cpg_math_operator_is_variable       (CpgMathOperatorType type);

Get whether an operator accepts a variable number of arguments.

type :

A CpgMathOperatorType

Returns :

TRUE if the operator accepts a variable number of arguments, FALSE otherwise

cpg_math_function_is_commutative ()

gboolean            cpg_math_function_is_commutative    (CpgMathFunctionType type);

Get whether an function is commutative.

type :

A CpgMathOperatorType

Returns :

TRUE if the function is commutative, FALSE otherwise

cpg_math_operator_is_commutative ()

gboolean            cpg_math_operator_is_commutative    (CpgMathOperatorType type);

Get whether an operator is commutative.

type :

A CpgMathOperatorType

Returns :

TRUE if the operator is commutative, FALSE otherwise

cpg_math_function_lookup_by_id ()

const gchar *       cpg_math_function_lookup_by_id      (CpgMathFunctionType type,
                                                         gint *arguments);

Lookup the name of a function by its id.

type :

A CpgMathFunctionType

arguments :

return value for the number of arguments. [out]

Returns :

the name of the function, or NULL if the function could not be found