My Project
Rational Utility Functions

Functions

MMAL_RATIONAL_T mmal_rational_add (MMAL_RATIONAL_T a, MMAL_RATIONAL_T b)
 
MMAL_RATIONAL_T mmal_rational_subtract (MMAL_RATIONAL_T a, MMAL_RATIONAL_T b)
 
MMAL_RATIONAL_T mmal_rational_multiply (MMAL_RATIONAL_T a, MMAL_RATIONAL_T b)
 
MMAL_RATIONAL_T mmal_rational_divide (MMAL_RATIONAL_T a, MMAL_RATIONAL_T b)
 
int32_t mmal_rational_to_fixed_16_16 (MMAL_RATIONAL_T rational)
 
MMAL_RATIONAL_T mmal_rational_from_fixed_16_16 (int32_t fixed)
 
void mmal_rational_simplify (MMAL_RATIONAL_T *rational)
 
MMAL_BOOL_T mmal_rational_equal (MMAL_RATIONAL_T a, MMAL_RATIONAL_T b)
 

Detailed Description

The rational utility functions allow easy manipulation of rational numbers.

Function Documentation

◆ mmal_rational_add()

MMAL_RATIONAL_T mmal_rational_add ( MMAL_RATIONAL_T  a,
MMAL_RATIONAL_T  b 
)

Add 2 rational numbers. It is assumed that both input rational numbers are in their simplest form.

Parameters
aFirst operand
bSecond operand
Returns
a + b

◆ mmal_rational_divide()

MMAL_RATIONAL_T mmal_rational_divide ( MMAL_RATIONAL_T  a,
MMAL_RATIONAL_T  b 
)

Divide 2 rational numbers. It is assumed that both input rational numbers are in their simplest form.

Parameters
aFirst operand
bSecond operand
Returns
a / b

◆ mmal_rational_equal()

MMAL_BOOL_T mmal_rational_equal ( MMAL_RATIONAL_T  a,
MMAL_RATIONAL_T  b 
)

Test 2 rational numbers for equality.

Parameters
aFirst operand
bSecond operand
Returns
true if equal

◆ mmal_rational_from_fixed_16_16()

MMAL_RATIONAL_T mmal_rational_from_fixed_16_16 ( int32_t  fixed)

Convert a signed 32-bit Q16 number to a rational number.

Parameters
fixedSigned 32-bit Q16 number to convert
Returns
Rational number

◆ mmal_rational_multiply()

MMAL_RATIONAL_T mmal_rational_multiply ( MMAL_RATIONAL_T  a,
MMAL_RATIONAL_T  b 
)

Multiply 2 rational numbers. It is assumed that both input rational numbers are in their simplest form.

Parameters
aFirst operand
bSecond operand
Returns
a * b

◆ mmal_rational_simplify()

void mmal_rational_simplify ( MMAL_RATIONAL_T rational)

Reduce a rational number to it's simplest form.

Parameters
rationalRational number to simplify

◆ mmal_rational_subtract()

MMAL_RATIONAL_T mmal_rational_subtract ( MMAL_RATIONAL_T  a,
MMAL_RATIONAL_T  b 
)

Subtract 2 rational numbers. It is assumed that both input rational numbers are in their simplest form.

Parameters
aFirst operand
bSecond operand
Returns
a - b

◆ mmal_rational_to_fixed_16_16()

int32_t mmal_rational_to_fixed_16_16 ( MMAL_RATIONAL_T  rational)

Convert a rational number to a 32-bit signed Q16 number. Saturation will occur for rational numbers with an absolute value greater than 32768.

Parameters
rationalRational number to convert
Returns
32-bit signed Q16 number