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 99: Linha 99:
===As funções <code>log</code> e <code>log10</code>===
===As funções <code>log</code> e <code>log10</code>===


The <code>log</code> 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.
As funções <code>log</code> computam o logaritmo natural do argumento e retornam o resultado. Um "domain error" ocorre se o argumento for negativo. Um "range error" pode ocorrer se o argumento for zero.


The <code>log10</code> 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.
As funçõs <code>log10</code> computam o logaritmo comum (base-10) do argumento e retornam o resultado. Um "domain error" ocorre se o argumento for negativo. Um "range error" ocorre se o argumento for zero.


#include <math.h>
#include <math.h>

Revisão das 20h39min de 10 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

A função acos retorna o arco-cosseno dos seus argumentos em radianos, e a função asin retorna o arco-seno dos seus argumentos em radianos. Todas as funções esperam por argumentos que estejam no intervalo [-1,+1]. O arco-cosseno retorna valores no intervalo [0,π]; o arco-seno retorna valores no intervalo [-π/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

As funções atan retornam o arco-tangente dos arguments em radianos, e a função atan2 retorna o arco-tangente de y/x em radianos. As funções atan retornam o valor no intervalo [-π/2,+π/2] (a razão pelo que ±π/2 está incluido no intervalo é porque os valores decimais pode representar o infinito, e atan(±∞) = ±π/2); as funções atan2 retornam o valor no intervalo [-π,+π]. Para a função atan2, um "domain error" pode ocorrer se os dois argumentos forem 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

As funções cos, sin, e tan retornam o coseno, seno, e tangente do argumento, expresso em radianos.

#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

As funções exp computam a função exponencial de x (ex). Um "range error" ocorre se o valor de x é muito grande.

#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

As funções log computam o logaritmo natural do argumento e retornam o resultado. Um "domain error" ocorre se o argumento for negativo. Um "range error" pode ocorrer se o argumento for zero.

As funçõs log10 computam o logaritmo comum (base-10) do argumento e retornam o resultado. Um "domain error" ocorre se o argumento for negativo. Um "range error" ocorre se o argumento for 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

As funções pow computam x elevado a y e retornam o resultado. Um "domain error" occore se x for negative e y não for um número inteiro. Um "domain error" ocorre se o resultado não puder ser representado quando x é zero e y é menor ou igual a zero. Um "range error" pode ocorrer.

#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

As funções sqrt computam a raiz positiva de x e retornam o resultado. Um "domain error" ocorre se o argumento for negativo.

#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

As funções ceil computam o menor número inteiro que não seja menor que x e retornam o resultado; as funções floor computam o maior número inteiro que não seja maior que x e retornam o resultado.

#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

As funções fabs computam o valor absoluto do número real x e retornam o resultado.

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

As funções fmod

As funções fmod computam o resto de x/y e retornam o valor x - i * y, pra algum número inteiro i onde, se y for um número diferente de zero, o resultado tem o mesmo sinal de x e magnitude menor que a magnitude de y. Se y for zero, dependendo da implementação da função, ocorrerá um "domain error" ou a função fmod retornará zero.

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