Q31 Library

mikroPascal PRO for ARM includes a library for operating and working with Q31 fractional number format.

Library Routines

Q31_Abs

Prototype

function Q31_Abs(input : longint) : longint;

Description

Function calculates absolute value of the Q31 fractional format number.

Parameters
  • input: Q31 input number.
Returns

Function returns Q31 output number.

Q31_Add

Prototype

function Q31_Add(x : longint; y : longint; var z : longint) : byte;

Description

Function sums two Q31 format numbers.

If the result exceeds [-2147483648, 2147483647] limits, result will be maximal(minimal) number in Q31 format.

Parameters
  • x: First Q31 number.
  • y: Second Q31 number.
  • z: Q31 output number.
Returns
  • 1 - if the result exceeds [-2147483648, 2147483647] limits.
  • 0 - otherwise.

Q31_Sub

Prototype

function Q31_Sub(x : longint; y : longint; var x : longint) : byte;

Description

Function subtracts two Q31 format numbers.

If the result exceeds [-2147483648, 2147483647] limits, result will be maximal(minimal) number in Q31 format.

Parameters
  • x: First Q31 number.
  • y: Second Q31 number.
  • z: Q31 output number.
Returns
  • 1 - if the result exceeds [-2147483648, 2147483647] limits.
  • 0 - otherwise.

Q31_Itof

Prototype

function Q31_Itof(x : longint) : real;

Description

Function converts number from the Q31 fractional number format to floating point number format.

Parameters
  • x: input Q31 number, ranging from -2147483648 to 2147483647.
Returns

Function returns resulting floating point number.

Q31_Ftoi

Prototype

function Q31_Ftoi(f : real) : longint;

Description

Function converts number from the floating point number format to Q31 fractional number format.

Input number scope should be in the range of [-1.00000, 0.99996].

If the floating point number is not in this range, the resulting number will be 0x7FFFFFFF (0x80000000).

Parameters
  • f: floating format number to be converted.
Returns

Function returns resulting Q31 fractional format number.

Q31_Itoa

Prototype

procedure Q31_Itoa(x : longint; var s : string);

Description

Function converts number from the Q31 fractional format to ASCII string.

Output ASCII string is in the following format : sn.ddddddddddddddddddddddddddddddd

  • s - sign; '-' negative, space - positive.
  • n - integer part; 0 or 1.
  • d - decimal part; 0..9 (ending zeros are not displayed).

Parameters
  • x: Q31 format number to be converted.
  • s: output ASCII string.
Returns

Nothing.

Q31_Atoi

Prototype

function Q31_Atoi(var s : string; var x : longint) : word;

Description

Function converts the input ASCII string s into a number in Q31 fractional point format.

Input ASCII string should be in the following format: sn.ddddddddddddddddddddddddddddddd

  • s - sign; '-' negative, space - positive.
  • n - integer part; 0 or 1.
  • d - decimal part; 0..9 (ending zeros are not displayed).

Parameters
  • s: input ASCII string.
  • x: resulting number in Q31 format.
Returns
  • 2 - If input string is in not in the appropriate format.
  • 1 - If overflow has been detected.
  • 0 - If no errors occured.

Q31_Cos

Prototype

function Q31_Cos(x : longint) : longint;

Description

Function returns the cosine of x. The input number is in the Q31 format number and returns value in the Q31 format, ranging from 1160290361 to 2147483647.

Parameters
  • x: input number in the Q31 format number, ranging from -2147483648 to 2147483647
Returns

Function returns value in the Q31 format, ranging from 1160290361 to 2147483647.

Q31_Sin

Prototype

function Q31_Sin(x : longint) : longint;

Description

Function returns the sine of x. The input number is in the Q31 format number and returns value in the Q31 format, ranging from -1807039907 to 1807039904.

Parameters
  • x: input number in the Q31 format number, ranging from -2147483648 to 2147483647.
Returns

Function returns value in the Q31 format, ranging from -1807039907 to 1807039904.

Q31_Tan

Prototype

function Q31_Tan(x : longint) : longint;

Description

Function returns the tangent of x. The input number is in the Q31 format number and returns value in the Q31 format, ranging from -2147483648 to 2147483648.

Parameters
  • x: input number in the Q31 format number, ranging from -1686629760 to 1686629760.
Returns

Function returns value in the Q31 format, ranging from -2147483648 to 2147483647.

Q31_Asin

Prototype

function Q31_Asin(x : longint) : longint;

Description

Function returns the arc sine of x. The input number is in the Q31 format number and returns value in the Q31 format, ranging from -2147483648 to 2147483648.

Parameters
  • x: input number in the Q31 format number, ranging from -1807076313 to 1807076320.
Returns

Function returns value in the Q31 format, ranging from -2147483648 to 2147483647.

Q31_Atan

Prototype

function Q31_Atan(x : longint) : longint;

Description

Function returns the arc tangent of x. The input number is in the Q31 format number and returns value in the Q31 format, ranging from -1673210000 do 1673209982.

Parameters
  • x: input number in the Q31 format number, ranging from -2147483648 to 2147483647.
Returns

Function returns value in the Q31 format, ranging from -1673210000 do 1673209982.

Q31_Acos

Prototype

function Q31_Acos(x : longint) : longint;

Description

Function returns the arc cosine of x. The input number is in the Q31 format number and returns value in the Q31 format, ranging from 189407136 do 2147458881.

Parameters
  • x: input number in the Q31 format number, ranging from 1160311168 do 2147483647.
Returns

Function returns value in the Q31 format, ranging from 189407136 do 2147458881.

Q31_Log

Prototype

function Q31_Log(x : longint) : longint;

Description

Function returns the logarithm of x. The input number is in the Q31 format number and returns value in the Q31 format, ranging from -2144585218 to 0.

Parameters
  • x: input number in the Q31 format number, ranging from 214748368 do 2147483647.
Returns

Function returns value in the Q31 format, ranging from -2144585218 to 0.