mikroSDK Reference Manual
ANSI C Stdlib Library

ANSI C Stdlib Library. More...

Functions list

int abs (int num)
 Returns absolute value of given argument. More...
 
float atof (char *str)
 Converts string to float. More...
 
int atoi (char *str)
 Converts string to integer. More...
 
long atol (char *str)
 Converts string to number of type long. More...
 
div_t div (int number, int denom)
 Divides number (numerator) by denom (denominator). More...
 
ldiv_t ldiv (long number, long denom)
 Divides number (numerator) by denom (denominator). More...
 
uldiv_t uldiv (unsigned long number, unsigned long denom)
 Divides number (numerator) by denom (denominator). More...
 
long labs (long num)
 Returns the absolute value of num. More...
 
long max (long num1, long num2)
 Returns maximum value of num1 and num2. More...
 
long min (long num1, long num2)
 Returns minimum value of num1 and num2. More...
 
int rand ()
 Pseudo-random number generator. More...
 
void srand (unsigned seed)
 Seeds the random number generator used by the function rand. More...
 
int xtoi (char *str)
 Extracts hex value from a given string. More...
 

Detailed Description

ANSI C Stdlib Library provides a set of standard ANSI C library functions of general utility.

Function Documentation

◆ abs()

int abs ( int  num)

The abs function computes the absolute value of an integer num. If the result cannot be represented, the behavior is undefined.

Returns absolute value of given argument.

The abs function computes the absolute value of an integer num. If the result cannot be represented, the behavior is undefined.

Parameters
[in]numNumber the absolute value is set for.
Returns
The abs function returns the absolute value.

◆ atof()

float atof ( char *  str)

The atof function converts the initial portion of the string pointed to by str to double representation. Except for the behavior on error, it is equivalent to strtod.

Converts string to float.

The atof function converts the initial portion of the string pointed to by str to double representation. Except for the behavior on error, it is equivalent to strtod.

Parameters
[in]strString to be converted.
Returns
The atof function returns the converted value.

◆ atoi()

int atoi ( char *  str)

The atoi function converts the initial portion of the string pointed to by str to int representation. Except for the behavior on error, it is equivalent to strtol.

Converts string to integer.

The atoi function converts the initial portion of the string pointed to by str to int representation. Except for the behavior on error, it is equivalent to strtol.

Parameters
[in]strString to be converted.
Returns
The atoi function returns the converted value.

◆ atol()

long atol ( char *  str)

The atol function converts the initial portion of the string pointed to by str to long int representation. Except for the behavior on error, it is equivalent to strtol.

Converts string to number of type long.

The atol function converts the initial portion of the string pointed to by str to long int representation. Except for the behavior on error, it is equivalent to strtol.

Parameters
[in]strString to be converted.
Returns
The atol function returns the converted value.

◆ div()

div_t div ( int  number,
int  denom 
)

The div function computes the quotient and remainder of the division of the numerator number by the denominator denom. If the division is inexact, the resulting quotient is the integer of lesser magnitude that is the nearest to the algebraic quotient. If the result cannot be represented, the behavior is undefined. Otherwise, quotient * denom + remainder shall equal number.

Divides number (numerator) by denom (denominator).

The div function computes the quotient and remainder of the division of the numerator number by the denominator denom. If the division is inexact, the resulting quotient is the integer of lesser magnitude that is the nearest to the algebraic quotient. If the result cannot be represented, the behavior is undefined. Otherwise, quotient * denom + remainder shall equal number.

Parameters
[in]numberNumber to be divided.
[in]denomNumber to be divided by.
Returns
The div function returns a structure of type div-t, comprising of both the quotient and the remainder. The structure shall contain the lollouing members, in either order: – int quot / quotient / – int rem / remainder /

◆ ldiv()

ldiv_t ldiv ( long  number,
long  denom 
)

The ldiv function is similar to the div function, except that the arguments and the members of the returned structure (which has type ldiv-t) all have type long int.

Divides number (numerator) by denom (denominator).

The ldiv function is similar to the div function, except that the arguments and the members of the returned structure (which has type ldiv-t) all have type long int.

Parameters
[in]numberNumber to be divided.
[in]denomNumber to be divided by.
Returns
The ldiv function returns a structure of type ldiv-t, comprising of both the quotient and the remainder. The structure shall contain the lollouing members, in either order: – long quot / quotient / – long rem / remainder /

◆ uldiv()

uldiv_t uldiv ( unsigned long  number,
unsigned long  denom 
)

The uldiv function is similar to the div function, except that the arguments and the members of the returned structure (which has type uldiv-t) all have type unsigned long int.

Divides number (numerator) by denom (denominator).

The uldiv function is similar to the div function, except that the arguments and the members of the returned structure (which has type uldiv-t) all have type unsigned long int.

Parameters
[in]numberNumber to be divided.
[in]denomNumber to be divided by.
Returns
The ldiv function returns a structure of type uldiv-t, comprising of both the quotient and the remainder. The structure shall contain the lollouing members, in either order: – unsigned long quot / quotient / – unsigned long rem / remainder /

◆ labs()

long labs ( long  num)

The labs function is similar to the abs function, except that the argument and the returned value each have type long int.

Returns the absolute value of num.

The labs function is similar to the abs function, except that the argument and the returned value each have type long int.

Parameters
[in]numNumber the absolute value is set for.
Returns
The abs function returns the absolute value of type long int.

◆ max()

long max ( long  num1,
long  num2 
)

Returns maximum value of num1 and num2.

Parameters
[in]num1Number 1 to be checked.
[in]num2Number 2 to be checked.
Returns
The max function returns the greater value between num1 and num2.

◆ min()

long min ( long  num1,
long  num2 
)

Returns minimum value of num1 and num2.

Parameters
[in]num1Number 1 to be checked.
[in]num2Number 2 to be checked.
Returns
The min function returns the lesser value between num1 and num2.

◆ rand()

int rand ( )

The rand function computes a sequence of pseudo-random integers in the range 0 to RAND_MAX.

Pseudo-random number generator.

The rand function computes a sequence of pseudo-random integers in the range 0 to RAND_MAX.

Returns
Function rand returns random integer value.
Note
The value of the RAND-MAX is 32767.

◆ srand()

void srand ( unsigned  seed)

The srand function uses the argument as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand. If srand is then called with the same seed value, the sequence of pseudo-random numbers shall be repeated. If rand is called before any calls to srand have been made, the same sequence shall be generated as when srand is first called with a seed value of 1.

Seeds the random number generator used by the function rand.

The srand function uses the argument as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand. If srand is then called with the same seed value, the sequence of pseudo-random numbers shall be repeated. If rand is called before any calls to srand have been made, the same sequence shall be generated as when srand is first called with a seed value of 1.

Parameters
[in]seedNumber to be used as new seed.
Returns
The srand function returns no value.

◆ xtoi()

int xtoi ( char *  str)

Extracts hex value from a given string.

Parameters
[in]strString the value is extracted from.
Returns
The xtoi funtion returns a hex value.