• Aucun résultat trouvé

atot - atol

Dans le document Language Reference (Page 118-127)

bdos

Purpose:

Makes a DOS system call.

Format:

#include <dos.h>

int bdo~(dosfn, dosdx, dosa/) int dosfn; 1* Function number *1

unsigned int dosdx; /* OX register value *1 unsigned int dosa/; /* AL register value *1 Comments:

The b~o~ function makes the DOS system call specified by dosfn after placil1g the value specified by dosdx in theDxregister and the value specified by dosa/ in the AL register. The bdos function performs an

tNT 21H instruction that makes the system call. .When control returns from DOS, bdos returns the contents of the' AX register:

Use th~ bdos function to make DOS system calls that either take no

arg~ments or only take arguments stored in the ox (DH,DL) and/or AL

regist~rs.

The bdos function returns the value of theAx register only after DOS completes the system call.

This example makes DOS function call 9 (display string) display a prompt. Because this call does not need the AL register value, code a 0 instead. This example works correctly only in small anq medium model programs.

#include <dos.h>

char *buffer = "Enter file name:$";

/* AL is not needed, so 0 is used */

bdos(9,(unsigned)buffer,8);

bdos

Related Topics:

intdos, intdosx Notes:

1. Do not use this call to make system calls that indicate errors by setting the carry flag. Because C programs do not have access to this flag, they cannot tell the status of the return value. Use the intdos function in these cases.

2. The bdos function is not available under OS/2. For information on calling OS/2 functions from a C program, see "Application

Program Interface" in the IBM Operating Systeml2 Technical Ref-erence manual.

bessel

Purpose:

Returns bessel functions.

Format:

#include <math.h>

double jO(x) double j1 (x) double jn(n,x) double yO(x) double y1 (x) double yn(n,x)

double x; /* Floating-point value */

int n; /* Integer order */

Comments:

Bessel functions are power-series expansions that are solutions of certain special differential equations. These equations occur in prob-lems in physics, particularly those probprob-lems that concern oscillations.

The jO, j1, and jn routines are bessel functions of the first kind for orders 0, 1, and

n,

respectively.

The yO, y1, and yn routines are bessel functions of the second kind for orders 0, 1, and n, respectively. The argument x must be positive.

These functions return the result of a bessel function of

x.

For jO, j1, yO, or y1, if x is too large, the function sets errno to ERANGE,

writes a TLOSS error message to the stderr data stream, and returns O.

For yO, y1, or yn, if x is negative, the function sets errno to EDOM,

writes a DOMAIN error message to the stderr data stream, and returns the value HUGE_VAL.

For more information about EDOM and DOMAIN, see "Math Errors" in Appendix A, "Error Messages" in this book.

bessel

You can change the way that the bessel function handles errors by using the matherr routine.

Example:

#include <rnath.h>

#define j2(x) (2./(x)) * jl(x) - jO(x) /* The Bessel functions of the first kind obey the recurrence relation:

J(n+l,x) =.(2n/x)*J(n,x) - J(n-l,x) */

This implies that the particular function jn(2,x) may be expressed in terms of jO and j1 by the identity given above in the #define

statement. This example tests whether the library function jn(2,x) computes values identical to those of the macro j2, using selected double values of x.

double g[3J={ 6.E-2, 6.25E-2, 6.5E-2 };

rnai nO {

i nt i;

doub 1 ed, e, f;

printf(" x j2(x)

"jn(2,x) cornpare?\n");

for(i=O; i<3; i++) {

d=g[iJ;

e=j2(d);

f=jn(2,d) ;

printf("%7.4f %16.13e"

"%16.13e ",d,e,f);

printf«e==f)?" equal\n"

:"unequal\n");

Related Topics:

matherr

bsearch

Purpose:

Performs a binary search of a sorted array.

Format:

/* Use either search.h or stdlib.h */

#include <stdlib.h>

void *bsearch(key, base, num, width, compare) const void *key; /* Search key * /

/* Pointer to base of search data */

const void *base;

/* Number and width of elements */

size _ t num, width;

/* Pointer to compare function */

int (*compare)( const void *element1 ,const void *element2) ; Comments:

The bsearch function performs a binary search of a sorted array of num elements, each of width bytes in size. The base is a pointer to the base of the array to search, and the key is the value being sought.

Compare is a pointer to a routine, which you must supply, that com-pares two array elements and returns a value specifying their relationship. The bsearch function calls this routine one or more times during the search, passing pointers to two array elements on each call. The routine must compare the elements, then return one of the following values.

Value Less than 0

o

Greater than 0

Meaning

element1 less than element2 element1 identical to element2 element1 greater than element2

bsearch

The bsearch function returns a pointer to the first occurrence of the key in the array to which the base points. If bsearch cannot find the key, it returns NULL.

Example:

This program reads the command-line parameters and uses qsort to sort them. It then displays the sorted arguments. Next, it uses bsearch to locate the first parameter starting with "TEMP".

#include <stdlib.h>

result=(char **)bsearch«char *)&key, (char *)argv, argc,

sizeof(char *), bcompare);

if (result)

printf("%s found\n" , *result);

else

printf("TEMP not foundl\n");

bsearch

int qcompare(argl,arg2) char **argl, **arg2;

{

/* Compare all of both strings. */

return(strcmp(*argl,*arg2));

int bcompare(argl,arg2) char **argl, **arg2;

{

/* Compare to length of key. */

return(strncmp(*argl,*arg2, strlen(*argl)));

Related Topics:

qsort

Purpose:

Calculates the absolute value of a complex number.

Format:

#include <mat~.h>

double cabs(z)

/* Contains real and imaginary parts */

struct complex z;

Comments:

cabs

The cabs function calculates the absolute value of a complex number.

The complex number must be a structure with type complex, defined in math.h:

struct complex {double x,y;};

A call to cabs is equivalent to sqrt{z.x * z.x

+

z.y * z.y)

The cabs function returns the absolute value as described above. If an overflow results, the function calls the matherr routine, sets errno to ERANGE and returns the value HUGE_VAL.

cabs

Example:

The following example computes d to be the the absolute value of the complex number (3.0, 4.0).

#include <math.h>

#include <stdio.h>

mai n () {

struct complex value;

double d;

value.x = 3.0;

value.y = 4.0;

d = cabs(value);

printf("Absolute value is %f\n",d);

Dans le document Language Reference (Page 118-127)