Integer Math


Functions

long random (int max)
void srand (int seed)
int imin (int first_value, int second_value)
int imax (int first_value,int second_value)


Compounds

     struct   bitsetWorks with a set of bits using simple bit operations


Detailed Description

Here you can find some mathematical functions, imin() and imax() among them. If you need to find the minimal or maximal of two numbers, look at these efficient functions.


Function Documentation

int imax ( int first_value,
int second_value )
 

Returns the maximum of the two values.

Parameters:
first_value   first value to be compared.
second_value   second value to be compared.
Returns:
The maximum of the two values
        #include <cywin.h>
        ...
        struct rect_t object_1;
        struct rect_t object_2;
        struct rect_t rect_and;
        ...
        //  Obtains intersection of two rectangles.
        rect_and.x = imax( object_1.x, object_2.x );
        rect_and.y = imax( object_1.y, object_2.y );
        rect_and.w = imin( object_1.x + object_1.w,
                           object_2.x + object_2.w) - rect_and.x;
        rect_and.h = imin( object_1.y + object_1.h,
                           object_2.y + object_2.h) - rect_and.y;
        ...
See also:
imin.

int imin ( int first_value,
int second_value )
 

Returns the minimum of the two values.

Parameters:
first_value   first value to be compared.
second_value   second value to be compared.
Returns:
The minimum of the two values.
        #include <cywin.h>
        ...
        struct rect_t object_1;
        struct rect_t object_2;
        struct rect_t rect_and;
        ...
        //  Obtains intersection of two rectangles.
        rect_and.x = imax( object_1.x, object_2.x );
        rect_and.y = imax( object_1.y, object_2.y );
        rect_and.w = imin( object_1.x + object_1.w,
                           object_2.x + object_2.w ) - rect_and.x;
        rect_and.h = imin( object_1.y + object_1.h,
                           object_2.y + object_2.h ) - rect_and.y;
        ...
See also:
imax.

long random ( int max )
 

Returns a pseudo-random value from 0 to max - 1.

Parameters:
max   the value what determines the range of return values. This range is [0, max-1].
Returns:
A pseudo-random value from 0 to max-1.
       #include <cybiko.h>
       ...
       int nRandVal;
       ...
       //  Returns pseudo-random value from 0 to 99.
       nRandVal = random( 100 );

void srand ( int seed )
 

Initializes a pseudo-random number generator.

Parameters:
seed   Seed for pseudo-random number generation
Returns:
None.
       #include <cybiko.h>
       ...
       int nValue;
       ...
       srand( clock() );
       ...
       nValue = random( 100 );
       ...