Q15 Library

mikroBasic PRO for ARM includes a library for operating and working with Q15 fractional number format.

Library Routines

Q15_Abs

Prototype

sub function Q15_Abs(dim input as integer) as word

Description

Function calculates absolute value of the Q15 fractional format number.

Parameters
  • input: Q15 input number, ranging from -32768 to 32767.
Returns

Function returns Q15 output number.

Q15_Add

Prototype

sub function Q15_Add(dim x as integer, y input2 as integer, dim byref z as integer) as byte

Description

Function sums two Q15 format numbers.

If the result exceeds [-32768, 32767] limits, result will be maximal(minimal) number in Q15 format.

Parameters
  • x: First Q15 number, ranging from -32768 to 32767.
  • y: Second Q15 number, ranging from -32768 to 32767.
  • z: Q15 output number.
Returns
  • 1 - if the result exceeds [-32768, 32767] limits.
  • 0 - otherwise.

Q15_Sub

Prototype

sub function Q15_Sub(dim x as integer, dim y as integer, dim byref z as integer) as byte

Description

Function subtracts two Q15 format numbers.

If the result exceeds [-32768, 32767] limits, result will be maximal(minimal) number in Q15 format.

Parameters
  • in1: First Q15 number, ranging from -32768 to 32767.
  • in2: Second Q15 number, ranging from -32768 to 32767.
  • out: Q15 output number.
Returns
  • 1 - if the result exceeds [-2147483648, 2147483647] limits.
  • 0 - otherwise.

Q15_Itof

Prototype

sub function Q15_Itof(dim x as integer) as real

Description

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

Parameters
  • x: input Q15 number, ranging from -32768 to 32767.
Returns

Function returns resulting floating point number.

Q15_Ftoi

Prototype

sub function Q15_Ftoi(dim f as real) as integer

Description

Function converts number from the floating point number format to Q15 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 0x7FFF (0x8000).

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

Function returns resulting Q15 fractional format number.

Q15_Itoa

Prototype

sub procedure Q15_Itoa(dim x as integer, dim byref s as string)

Description

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

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

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

Parameters
  • x: Q15 format number to be converted.
  • s: resulting ASCII string.
Returns

Nothing.

Q15_Atoi

Prototype

sub function Q15_Atoi(dim byref s as string, dim byref x as integer) as word

Description

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

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

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

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

Q15_Cos

Prototype

sub function Q15_Cos(dim x as integer) as integer

Description

Function returns the cosine of x. The input number is in the Q15 format number and returns value in the Q15 format, ranging from 17748 to 32767.

Parameters
  • x: input number in the Q15 format number, ranging from -32768 to 32767
Returns

Function returns value in the Q15 format, ranging from 17748 to 32767.

Q15_Sin

Prototype

sub function Q15_Sin(dim x as integer) as integer

Description

Function returns the sine of x. The input number is in the Q15 format number and returns value in the Q15 format, ranging from -27580 to 27578.

Parameters
  • x: input number in the Q15 format number, ranging from -32768 to 32767.
Returns

Function returns value in the Q15 format, ranging from -27580 to 27578.

Q15_Tan

Prototype

sub function Q15_Tan(dim x as integer) as integer

Description

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

Parameters
  • x: input number in the Q15 format number, ranging from -25733 to 25738.
Returns

Function returns value in the Q15 format, ranging from -32768 to 32767.

Q15_Asin

Prototype

sub function Q15_Asin(dim x as integer) as integer

Description

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

Parameters
  • x: input number in the Q15 format number, ranging from -27568 to 27578.
Returns

Function returns value in the Q15 format, ranging from -32768 to 32767.

Q15_Atan

Prototype

sub function Q15_Atan(dim x as integer) as integer

Description

Function returns the arc tangent of x. The input number is in the Q15 format number and returns value in the Q15 format, ranging from -25532 to 25509.

Parameters
  • x: input number in the Q15 format number, ranging from -32768 to 32767.
Returns

Function returns value in the Q15 format, ranging from -25532 to 25509.

Q15_Acos

Prototype

sub function Q15_Acos(dim x as integer) as integer

Description

Function returns the arc cosine of x. The input number is in the Q15 format number and returns value in the Q15 format, ranging from 2887 to 32767.

Parameters
  • x: input number in the Q15 format number, ranging from 17705 to 32767.
Returns

Function returns value in the Q15 format, ranging from 2887 to 32767.

Q15_Log

Prototype

sub function Q15_Log(dim x as integer) as integer

Description

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

Parameters
  • x: input number in the Q15 format number, ranging from 3277 to 32767.
Returns

Function returns value in the Q15 format, ranging from -32748 to 0.

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code