LibCapy - ratio

Rational number class.

Macros:

Format for print instructions

Enumerations:

None.

Typedefs:

Type for the base of a CapyRatio

Type for the fractional parts of a CapyRatio

Struct CapyRatio :

Struct CapyRatio's properties:

Components of the ratio

Struct CapyRatio's methods:

None.

Functions:

Create a CapyRatio equal to base+num/den

Input argument(s):

base: the base
num: the numerator
den: the denominator

Output and side effect(s):

Return a CapyRatio

Allocate memory for a new CapyRatio and create it

Input argument(s):

base: the base
num: the numerator
den: the denominator

Output and side effect(s):

Return a CapyRatio

Exception(s):

May raise CapyExc_MallocFailed.

Free the memory used by a CapyRatio

Input argument(s):

that: the CapyRatio to free

Free the memory used by a CapyRatio* and reset '*that' to NULL

Input argument(s):

that: a pointer to the CapyRatio to free

Check if a rational is equal to NaN

Input argument(s):

r: the CapyRatio to check

Output and side effect(s):

Return true if the rational is equal to NaN (denominator equals to 0)

Create a CapyRatio from a double

Input argument(s):

a: the double

Output and side effect(s):

Return a new CapyRatio representing the nearest possible value to the input double.

Convert a CapyRatio to a double

Input argument(s):

that: the CapyRatio to convert

Output and side effect(s):

Return a double representing approximating the CapyRatio.

Reduce a CapyRatio

Input argument(s):

that: the CapyRatio to reduce

Output and side effect(s):

Return a new CapyRatio equals to the reduced CapyRatio

Exception(s):

May raise CapyExc_NumericalOverflow

Input argument(s):

x: the first CapyRatio (must be in reduced form)
y: the second CapyRatio (must be in reduced form)

Output and side effect(s):

Return a new CapyRatio (in reduced form) equal to x+y

Exception(s):

May raise CapyExc_NumericalOverflow

Get the negative of a CapyRatio

Input argument(s):

x: the CapyRatio (must be in reduced form)

Output and side effect(s):

Return a new CapyRatio (in reduced form) equal to -x

Exception(s):

May raise CapyExc_NumericalOverflow

Substract two CapyRatios

Input argument(s):

x: the first CapyRatio (must be in reduced form)
y: the second CapyRatio (must be in reduced form)

Output and side effect(s):

Return a new CapyRatio (in reduced form) equal to x-y

Exception(s):

May raise CapyExc_NumericalOverflow

Compare two CapyRatios

Input argument(s):

x: the first CapyRatio (must be in reduced form)
y: the second CapyRatio (must be in reduced form)

Output and side effect(s):

Return -1 if xy

Multiply two CapyRatios

Input argument(s):

x: the first CapyRatio (must be in reduced form)
y: the second CapyRatio (must be in reduced form)

Output and side effect(s):

Return a new CapyRatio (in reduced form) equal to x*y

Exception(s):

May raise CapyExc_NumericalOverflow

Get the inverse of a CapyRatio

Input argument(s):

x: the CapyRatio (must be in reduced form)

Output and side effect(s):

Return a new CapyRatio (in reduced form) equal to 1/that

Exception(s):

May raise CapyExc_NumericalOverflow

Divide two CapyRatios

Input argument(s):

x: the first CapyRatio (must be in reduced form)
y: the second CapyRatio (must be in reduced form)

Output and side effect(s):

Return a new CapyRatio (in reduced form) equal to x/y

Exception(s):

May raise CapyExc_NumericalOverflow

Get the absolute value of a CapyRatio

Input argument(s):

x: the CapyRatio (must be in reduced form)

Output and side effect(s):

Return a new CapyRatio (in reduced form) equal to abs(x)

Exception(s):

May raise CapyExc_NumericalOverflow

Raise a CapyRatio to an integer power

Input argument(s):

x: the CapyRatio
n: the power

Output and side effect(s):

Return a new CapyRatio (in reduced form) equal to x^n

Exception(s):

May raise CapyExc_NumericalOverflow

Get the square root of a CapyRatio

Input argument(s):

x: the CapyRatio (must be in reduced form)

Output and side effect(s):

Return a new CapyRatio (in reduced form) equal to sqrt(x)

Exception(s):

May raise CapyExc_NumericalOverflow

2022-01-24
in LibCapy,
44 views