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)
Thiagol (discussão | contribs)
Linha 137: Linha 137:




==Funções de Arredondamento para Números Inteiros, Valores Absolutos e Resto da Divisão==
==Nearest integer, absolute value, and remainder functions==


===As funções <code>ceil</code> e <code>floor</code>===
===As funções <code>ceil</code> e <code>floor</code>===

Revisão das 21h59min de 2 de março de 2007


Predefinição:Emtraducao2 O cabeçalho <math.h> contém protótipos de algumas funções na área de matemática. Na versão de 1990 do padrão ISO, somente a versão double das funções foram específicadas; na versão de 1999 foram adicionadas as versões float e long double.

As funções podem ser agrupadas nas seguintes categorias:

Funções Trigonométricas

As funções acos e asin

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 */


As funções atan e atan2

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 */


As funções cos, sin e tan

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 */


Funções Hiperbólicas

As funções cosh, sinh and tanh computam o coseno hiperbólico, o seno hiperbólico e a tangente hiperbólica respectivamente. Para as funções de seno e coseno hiperbólico, um erro de ...


#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 */


Funções Exponencial e Logaritmo

A função exp

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 */


As funções frexp, ldexp e modf

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 */


As funções log e log10

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 */


Funções de Arredondamento para Números Inteiros, Valores Absolutos e Resto da Divisão

As funções ceil e floor

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 */

As funções fabs

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 */

As funções fmod

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 */