Trigon Library

The mikroBasic PRO for dsPIC30/33 and PIC24 provides a set of library functions for floating point math handling. See also Predefined Globals and Constants for the list of predefined math constants.

Library Functions

acos

Prototype

sub function acos(dim x as float) as float

Description

Function returns the arc cosine of parameter x; that is, the value whose cosine is x. The input parameter x must be between -1 and 1 (inclusive). The return value is in radians, between 0 and Π (inclusive).

Example
res = acos(0.5)  ' res = 1.047198

asin

Prototype

sub function asin(dim x as float) as float

Description

Function returns the arc sine of parameter x; that is, the value whose sine is x. The input parameter x must be between -1 and 1 (inclusive). The return value is in radians, between -Π/2 and Π/2 (inclusive).

Example
res = asin(0.5)  ' res = 5.235987e-1

atan

Prototype

sub function atan(dim arg as float) as float

Description

Function computes the arc tangent of parameter f; that is, the value whose tangent is f. The return value is in radians, between -Π/2 and Π/2 (inclusive).

Example
res = atan(1.0)  ' res = 7.853982e-1

atan2

Prototype

sub function atan2(dim y as float, dim x as float) as float

Description

This is the two-argument arc tangent function. It is similar to computing the arc tangent of y/x, except that the signs of both arguments are used to determine the quadrant of the result and x is permitted to be zero. The return value is in radians, between -Π and Π (inclusive).

Example
res = atan2(2., 1.)  ' res = 4.636475e-1

ceil

Prototype

sub function ceil(dim x as float) as float

Description

Function returns value of parameter x rounded up to the next whole number.

Example
res = ceil(0.5)  ' res = 1.000000

cos

Prototype

sub function cos(dim arg as float) as float

Description

Function returns the cosine of f in radians. The return value is from -1 to 1.

Example
res = cos(PI/3.)  ' res = 0.500008

cosh

Prototype

sub function cosh(dim x as float) as float

Description

Function returns the hyperbolic cosine of x, defined mathematically as (ex+e-x)/2. If the value of x is too large (if overflow occurs), the function fails.

Example
res = cosh(PI/3.)  ' res = 1.600286

eval_poly

Prototype

sub function eval_poly(dim x as float, dim byref d as array[10] of float, dim n as integer) as float

Description

Function Calculates polynom for number x, with coefficients stored in d[], for degree n.

exp

Prototype

sub function exp(dim x as float) as float

Description

Function returns the value of e — the base of natural logarithms — raised to the power x (i.e. ex).

Example
res = exp(0.5)   ' res = 1.648721

fabs

Prototype

sub function fabs(dim d as float) as float

Description

Function returns the absolute (i.e. positive) value of d.

Example
res = fabs(-1.3)  ' res = 1.3

floor

Prototype

sub function floor(dim x as float) as float

Description

Function returns the value of parameter x rounded down to the nearest integer.

Example
res = floor(15.258)  ' res = 15.000000

frexp

Prototype

sub function frexp(dim value as float, dim byref eptr as integer) as float

Description

The function splits a floating-point value value into a normalized fraction and an integral power of 2. The return value is a normalized fraction and the integer exponent is stored in the object pointed to by eptr.

ldexp

Prototype

sub function ldexp(dim value as float, dim newexp as integer) as float

Description

Function returns the result of multiplying the floating-point number num by 2 raised to the power n (i.e. returns x * 2n).

Example
res = ldexp(2.5, 2)  ' res = 10

log

Prototype

sub function log(dim x as float) as float

Description

Function returns the natural logarithm of x (i.e. loge(x)).

Example
res = log(10)  ' res = 2.302585E

log10

Prototype

sub function log10(dim x as float) as float

Description

Function returns the base-10 logarithm of x (i.e. log10(x)).

Example
res = log10(100.)  ' res = 2.000000

modf

Prototype

sub function modf(dim val as float, dim byref iptr as float) as float

Description

Returns argument val split to the fractional part (function return val) and integer part (in number iptr).

Example
res = modf(6.25, iptr)  ' res = 0.25, iptr = 6.00 

pow

Prototype

sub function pow(dim x as float, dim y as float) as float

Description

Function returns the value of x raised to the power y (i.e. xy).

Example
res = pow(10.,5.)  ' res = 9.999984e+4

sin

Prototype

sub function sin(dim arg as float) as float

Description

Function returns the sine of f in radians. The return value is from -1 to 1.

Example
res = sin(PI/2.)  ' res = 1.000000

sinh

Prototype

sub function sinh(dim x as float) as float

Description

Function returns the hyperbolic sine of x, defined mathematically as (ex-e-x)/2. If the value of x is too large (if overflow occurs), the function fails.

Example
res = sinh(PI/2.)  ' res = 2.301296

sqrt

Prototype

sub function sqrt(dim x as float) as float

Description

Function returns the non negative square root of x.

Example
res = sqrt(10000.)   ' res = 100.0000

tan

Prototype

sub function tan(dim x as float) as float

Description

Function returns the tangent of x in radians. The return value spans the allowed range of floating point in the mikroBasic PRO for dsPIC30/33 and PIC24.

Example
res = tan(PI/4.)  ' res = 0.999998

tanh

Prototype

sub function tanh(dim x as float) as float)

Description

Function returns the hyperbolic tangent of x, defined mathematically as sinh(x)/cosh(x).

Example
res = tanh(-PI/4.)   ' res = -0.655793
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