'fmod func'에 해당되는 글 1건

  1. 2021.06.25 Watcom C Library : fmod, fopen, FP_OFF, EP_SEG

 

 

Watcom C Library Reference : fmod, fopen, FP_OFF, FP_SEG

 

 

 

 

fmod

 

Synopsis : #include <math.h> 

              double fmod ( double x, double y );

 


Description : The fmod function computes the floating-point remainder of x/y, even if the quotient not representable.

 

 

Returns : The fmod function returns the value x - (i * y), for some integer i such that, if y is non the result has the same sign as x and magnitude less than the magnitude of y. If the value of y is zero, then the value returned is zero.

 

See Also : ceil, fabs, floor

 


Example :

#include <stdio.h> 

#include <math.h>


void main( )

{
    printf( "%f\n", fmod (  4.5,  2.0 ) );

    printf( "%f\n", fmod ( -4.5,  2.0 ) ) ;

    printf( "%f\n", fmod(   4.5, -2.0 ) );

    printf( "%f\n", fmod ( -4.5, -2.0 ) );
}

 


produces the following :
0.500000 

-0.500000 

0.500000 

-0.500000

 

Classification : ANSI
Systems : All

 

 

 

 

 

fopen

 

Synopsis : #include <stdio.h> 

              FILE *fopen( const char *filename, const char *mode );

 


Description : The fopen function opens the file whose name is the string pointed to by filename, and associates a stream with it. The argument mode points to a string beginning with on following sequences:

 Mode  Meaning
 "r"  open file for reading; use default file translation
 "w"  create file for writing, or truncate to zero length; use default file translation
 "a"  append: open text file or create for writing at end-of-file; use default file translation
 "rb"  open binary file for reading
 "rt"  open text file for reading
 "wb"  create binary file for writing, or truncate to zero length
 "wt"  create text file for writing, or truncate to zero length
 "ab"  append; open binary file or create for writing at end-of-file
 "at"  append; open text file or create for writing at end-of-file
 "r+"  open file for update (reading and/or writing); use default file translation
 "w+"  create file for update, or truncate to zero length; use default file translation
 "a+"  append; open file or create for update, writing at end-of-file; use default file translation
 "r+b", "rb+"  open binary file for update (reading and/or writing)
 "r+t", "rt+"  open text file for update (reading and/or writing)
 "w+b", "wb+"  create binary file for update, or truncate to zero length
 "w+t", "wt+"  create text file for update, or truncate to zero length
 "a+b", "ab+"  append; open binary file or create for update, writing at end-of-file
 "a+t", "at+"  append; open text file or create for update, writing at end-of-file

 

When default file translation is specified, the value of the global variable _fmode establishes whether the file is to treated as a binary or a text file. Unless this value is changed by the program, the default will be text mode.

 

Opening a file with read mode ('r' as the first character in the mode argument) fails if the file does not exist or it cannot be read. Opening a file with append mode ('a' as the first character in the mode argument) causes all  subsequent writes to the file to be forced to the current end-of-file, regardless of previous calls to the fseek function. When a file is opened with update mode ('t' as the second or third character of the mode argument), both input and output may be performed on the associated stream.


When a stream is opened in update mode, both reading and writing may be performed. However, writing may  not be followed by reading without an intervening call to the fflush function or to a file positioning function ( fseek, fsetpos, rewind). Similarly, reading may not be followed by writing without an intervening call to a file positioning function, unless the read resulted in end-of-file.

 

 


Returns : The fopen function returns a pointer to the object controlling the stream. This pointer must be passed as a parameter to subsequent functions for performing operations on the file. If the open operation fails, fopen returns NULL. When an error has occurred, errno contains a value indicating the type of error that has been detected.

 

 

See Also : fclose, fcloseali, fdopen, freopen, _fsopen

 


Example :

#include <stdio.h>


void main( )

{
    FILE     *fp;
   

    fp = fopen( "report.dat", "r" );

    if( fp != NULL ) {
        /* rest of code goes here */

        fclose( fp );

    }

}

 

Classification : ANSI, ('t' is a WATCOM extension)
Systems : All

 

 

 

 

 

FP_OFF

 

Synopsis : #include <i86.h> 

              unsigned FP_OFF( void __far *far_ptr );

 


Description : The FP_OFF macro can be used to obtain the offset portion of the far pointer value given in
far_ptr.

 

 

Returns : The macro returns an unsigned integer value which is the offset portion of the pointer value.

 

 

See Also : FP_SEG, MK_FP, segread

 


Example :

#include <stdio.h> 

#include <i86.h>


char ColourTable[256] [3];


void main( )

{
    union  REGPACK r;

    int     i;


    /* read block of colour registers */

    r.h.ah = 0x10;
    r.h.al = 0x17;

#if defined (__386__)
    r.x.ebx = 0;

    r.x.ecx = 256;

    r.x.edx = FP_OFF ( ColourTable );
    r.w.ds = r.w.fs = r.w.gs = FP_SEG ( &r );

#else
    r.w.bx = 0;

    r.w.cx = 256;
    r.w.dx = FP_OFF ( ColourTable );

#endif
    r.w.es = FP_SEG ( ColourTable ); 

    intr( 0x10, &r );

 

    for( i = 0; i < 256; i++ ) {

        printf( "Colour index = %d"  "{ Red=%d, Green=%d, Blue=%d }\n",

                i,

                ColourTable[i][0],

                ColourTable[i][1],

                ColourTable[i][2] );

    }

}

 

Classification : Intel
Systems : MACRO

 

 

 

 

 

FP_SEG

 

Synopsis : #include <i86.h> 

              unsigned FP_SEG ( void __far *far-ptr );

 


Description : The FP_SEG macro can be used to obtain the segment portion of the far pointer value given in far_ptr.

 

 

Returns : The macro returns an unsigned integer value which is the segment portion of the pointer value.

 

 

See Also : FP_OFF, MK_FP, segread

 


Example :

#include <stdio.h> 

#include <i86.h>


char ColourTable[256][3];


void main( )

{
    union  REGPACK r;

    int     i;

 

    /* read block of colour registers */

    r.h.ah = 0x10;
    r.h.al = 0x17;

#if defined ( __386__)
    r.x.ebx = 0;

    r.x.ecx = 256;

    r.x.edx = FP_OFF ( ColourTable );
    r.w.ds = r.w.fs = r.w.gs = FP_SEG ( &r );

#else
    r.w.bx = 0;

    r.w.cx = 256;
    r.w.dx = FP_OFF ( ColourTable );

#endif
    r.w.es = FP_SEG ( ColourTable );

    intr( 0x10, &r );


    for ( i = 0; i < 256; i++ ) {

        printf( "Colour index = %d "  " { Red=%d, Green=%d, Blue=%d } \n",
                i,
                ColourTable[i][0],

                ColourTable[i][1],

                ColourTable[i][2] );

    }

}

 

Classification : Intel
Systems : MACRO

 

 

 

 

 

 

 

 

This manual describes the WATCOM C library for DOS, Windows, and OS/2, It includes the Standard C Library (as defined in the ANSI C Standard).

 

WATCOM C Language Reference manual describes the ANSI C Programming language and extensions to it which are supported by WATCOM C/C++ (32bit)

 

 

 

728x90
반응형
Posted by 전화카드
,