Μαθηματικές Συναρτήσεις και Σταθερές <math.h>


Η Μαθηματική βιβλιοθήκη είναι εύκολη στη χρήση. Πρέπει να γράψετε #include <math.h> και να καλέστε το μεταγλωττιστή ως εξής:

   cc mathprog.c -o mathprog -lm

Μαθηματικές Συναρτήσεις

Παρακάτω υπάρχει μια λίστα κοινών μαθηματικών συνατήσεων, ενώ υπάρχουν και αρκετές άλλες. Δεν απιτούνται πολλές εξηγήσεις:

double acos(double x) -- Compute arc cosine of x.
double asin(double x) -- Compute arc sine of x.
double atan(double x) -- Compute arc tangent of x.
double atan2(double y, double x) -- Compute arc tangent of y/x.
double ceil(double x) -- Get smallest integral value that exceeds x.
double cos(double x) -- Compute cosine of angle in radians.
double cosh(double x) -- Compute the hyperbolic cosine of x.
div_t div(int number, int denom) -- Divide one integer by another.
double exp(double x -- Compute exponential of x
double fabs (double x ) -- Compute absolute value of x.
double floor(double x) -- Get largest integral value less than x.
double fmod(double x, double y) -- Divide x by y with integral quotient and return remainder.
double frexp(double x, int *expptr) -- Breaks down x into mantissa and exponent of no.
labs(long n) -- Find absolute value of long integer n.
double ldexp(double x, int exp) -- Reconstructs x out of mantissa and exponent of two.
ldiv_t ldiv(long number, long denom) -- Divide one long integer by another.
double log(double x) -- Compute log(x).
double log10 (double x ) -- Compute log to the base 10 of x.
double modf(double x, double *intptr) -- Breaks x into fractional and integer parts.
double pow (double x, double y) -- Compute x raised to the power y.
double sin(double x) -- Compute sine of angle in radians.
double sinh(double x) - Compute the hyperbolic sine of x.
double sqrt(double x) -- Compute the square root of x.
void srand(unsigned seed) -- Set a new seed for the random number generator (rand).
double tan(double x) -- Compute tangent of angle in radians.
double tanh(double x) -- Compute the hyperbolic tangent of x.

Μαθηματικές Σταθερές

Η βιβλιοθήκη math.h ορίζει πολλές σταθερές (που συχνά αγνοούνται). Καλό είναι να ελέγχουμε αυτούς τους ορισμούς πριν τη χρήση:

HUGE -- The maximum value of a single-precision floating-point number.
M_E -- The base of natural logarithms (e).
M_LOG2E -- The base-2 logarithm of e.
M_LOG10E - The base-10 logarithm of e.
M_LN2 -- The natural logarithm of 2.
M_LN10 -- The natural logarithm of 10.
M_PI -- $\pi$.
M_PI_2 -- $\pi$/2.
M_PI_4 -- $\pi$/4.
M_1_PI -- 1/$\pi$.
M_2_PI -- 2/$\pi$.
M_2_SQRTPI -- 2/$\sqrt{\pi}$.
M_SQRT2 -- The positive square root of 2.
M_SQRT1_2 -- The positive square root of 1/2.
MAXFLOAT -- The maximum value of a non-infinite single-precision floating point number.
HUGE_VAL -- positive infinity.

Επίσης υπάρχει ένας αριθμός σταθερών που εξαρτώνται από το σύστημα και βρίσκονται στη βιβλιοθήκη value.h.


Dave Marshall
1/5/1999
μετάφραση και προσαρμογή στα Ελληνικά Κ.Γ. Μαργαρίτης
3/3/2008