Programar em C/Operações matemáticas (Avançado): diferenças entre revisões

Origem: Wikilivros, livros abertos por um mundo aberto.
[edição não verificada][edição não verificada]
Conteúdo apagado Conteúdo adicionado
Thiagol (discussão | contribs)
Nova página: {{emtraducao2}} The <code><math.h></code> header contains prototypes for several functions that deal with mathematics. In the 1990 version of the ISO standard, only the <code>double</c...
 
Thiagol (discussão | contribs)
Sem resumo de edição
Linha 1: Linha 1:
{{TopNav|prev=Indice|next=Controle de fluxo}}
{{emtraducao2}}
{{emtraducao2}}
The <code><math.h></code> header contains prototypes for several functions that deal with mathematics. In the 1990 version of the ISO standard, only the <code>double</code> versions of the functions were specified; the 1999 version added the <code>float</code> and <code>long double</code> versions.
The <code><math.h></code> header contains prototypes for several functions that deal with mathematics. In the 1990 version of the ISO standard, only the <code>double</code> versions of the functions were specified; the 1999 version added the <code>float</code> and <code>long double</code> versions.

Revisão das 15h33min de 2 de março de 2007


Predefinição:Emtraducao2 The <math.h> header contains prototypes for several functions that deal with mathematics. In the 1990 version of the ISO standard, only the double versions of the functions were specified; the 1999 version added the float and long double versions.

The functions can be grouped into the following categories:


Trigonometric functions

The acos and asin functions

The acos functions return the arccosine of their arguments in radians, and the asin functions return the arcsine of their arguments in radians. All functions expect the argument in the range [-1,+1]. The arccosine returns a value in the range [0,π]; the arcsine returns a value in the range [-π/2,+π/2].

#include <math.h>
float asinf(float x); /* C99 */
float acosf(float x); /* C99 */
double asin(double x);
double acos(double x);
long double asinl(long double x); /* C99 */
long double acosl(long double x); /* C99 */


The atan and atan2 functions

The atan functions return the arctangent of their arguments in radians, and the atan2 function return the arctangent of y/x in radians. The atan functions return a value in the range [-π/2,+π/2] (the reason why ±π/2 are included in the range is because the floating-point value may represent infinity, and atan(±∞) = ±π/2); the atan2 functions return a value in the range [-π,+π]. For atan2, a domain error may occur if both arguments are zero.

#include <math.h>
float atanf(float x); /* C99 */
float atan2f(float y, float x); /* C99 */
double atan(double x);
double atan2(double y, double x);
long double atanl(long double x); /* C99 */
long double atan2l(long double y, long double x); /* C99 */


The cos, sin, and tan functions

The cos, sin, and tan functions return the cosine, sine, and tangent of the argument, expressed in radians.

#include <math.h>
float cosf(float x); /* C99 */
float sinf(float x); /* C99 */
float tanf(float x); /* C99 */
double cos(double x);
double sin(double x);
double tan(double x);
long double cosl(long double x); /* C99 */
long double sinl(long double x); /* C99 */
long double tanl(long double x); /* C99 */


Hyperbolic functions

The cosh, sinh and tanh functions compute the hyperbolic cosine, the hyperbolic sine, and the hyperbolic tangent of the argument respectively. For the hyperbolic sine and cosine functions, a range error occurs if the magnitude of the argument is too large.

#include <math.h>
float coshf(float x); /* C99 */
float sinhf(float x); /* C99 */
float tanhf(float x); /* C99 */
double cosh(double x); 
double sinh(double x);
double tanh(double x);
long double coshl(long double x); /* C99 */
long double sinhl(long double x); /* C99 */
long double tanhl(long double x); /* C99 */


Exponential and logarithmic functions

The exp functions

The exp functions compute the exponential function of x (ex). A range error occurs if the magnitude of x is too large.

#include <math.h>
float expf(float x); /* C99 */
double exp(double x);
long double expl(long double x); /* C99 */


The frexp, ldexp, and modf functions

The frexp functions break a floating-point number into a normalized fraction and an integer power of 2. It stores the integer in the object pointed to by ex.

The frexp functions return the value x such that x has a magnitude of either [1/2, 1) or zero, and value equals x times 2 to the power *ex. If value is zero, both parts of the result are zero.

The ldexp functions multiply a floating-point number by a integral power of 2 and return the result. A range error may occur.

The modf function breaks the argument value into integer and fraction parts, each of which has the same sign as the argument. They store the integer part in the object pointed to by *iptr and return the fraction part.

#include <math.h>
float frexpf(float value, int *ex); /* C99 */
double frexp(double value, int *ex);
long double frexpl(long double value, int *ex); /* C99 */
float ldexpf(float x, int ex); /* C99 */
double ldexp(double x, int ex);
long double ldexpl(long double x, int ex); /* C99 */
float modff(float value, float *iptr); /* C99 */
double modf(double value, double *iptr); 
long double modfl(long double value, long double *iptr); /* C99 */


The log and log10 functions

The log functions compute the natural (not common) logarithm of the argument and return the result. A domain error occurs if the argument is negative. A range error may occur if the argument is zero.

The log10 functions compute the common (base-10) logarithm of the argument and return the result. A domain error occurs if the argument is negative. A range error may occur if the argument is zero.

#include <math.h>
float logf(float x); /* C99 */
double log(double x);
long double logl(long double x); /* C99 */
float log10f(float x); /* C99 */
double log10(double x);
long double log10l(long double x); /* C99 */

Power functions

The pow functions

The pow functions compute x raised to the power y and return the result. A domain error occurs if x is negative and y is not an integral value. A domain error occurs if the result cannot be represented when x is zero and y is less than or equal to zero. A range error may occur.

#include <math.h>
float powf(float x, float y); /* C99 */
double pow(double x, double y);
long double powl(long double x, long double y); /* C99 */


The sqrt functions

The sqrt functions compute the nonnegative square root of x and return the result. A domain error occurs if the argument is negative.

#include <math.h>
float sqrtf(float x); /* C99 */
double sqrt(double x);
long double sqrtl(long double x); /* C99 */


Nearest integer, absolute value, and remainder functions

The ceil and floor functions

The ceil functions compute the smallest integral value not less than x and return the result; the floor functions compute the largest integral value not greater than x and return the result.

#include <math.h>
float ceilf(float x); /* C99 */
double ceil(double x);
long double ceill(long double x); /* C99 */
float floorf(float x); /* C99 */
double floor(double x);
long double floorl(long double x); /* C99 */


The fabs functions

The fabs functions compute the absolute value of a floating-point number x and return the result.

#include <math.h>
float fabsf(float x); /* C99 */
double fabs(double x); 
long double fabsl(long double x); /* C99 */


The fmod functions

The fmod functions compute the floating-point remainder of x/y and return the value x - i * y, for some integer i such that, if y is nonzero, the result has the same sign as x and magnitude less than the magnitude of y. If y is zero, whether a domain error occurs or the fmod functions return zero is implementation-defined.

#include <math.h>
float fmodf(float x, float y); /* C99 */
double fmod(double x, double y);
long double fmodl(long double x, long double y); /* C99 */