Math pow c что это

от admin

Math pow c что это

Стандартная библиотека языка Си предоставляет ряд математических функций, которые определены в разных заголовочных файлах, но в основном определены в файле math.h .

Степерь числа. pow

Функция pow() , определенная в заголовочном файле math.h , возвращает степень числа:

Стоит отметить, что эта функция возвращает число типа double .

Для возведения в степень чисел типа float и long double также определены функции powf() и powl() соответственно.

Округление числа. round

Функция round() округляет число до ближайшего целого. В качестве параметра она принимает число типа double :

Квадратный корень. sqrt

Функция sqrt() возвращает квадратный корень числа типа double :

Для получения квадратного корня числа float также есть функция sqrtf() , а для числа типа long double — функция sqrtl()

pow, powf, powl

If no errors occur, base raised to the power of exponent ( base exponent
) is returned.

If a domain error occurs, an implementation-defined value is returned (NaN where supported).

If a pole error or a range error due to overflow occurs, ±HUGE_VAL , ±HUGE_VALF , or ±HUGE_VALL is returned.

If a range error occurs due to underflow, the correct result (after rounding) is returned.

[edit] Error handling

Errors are reported as specified in math_errhandling.

If base is finite and negative and exponent is finite and non-integer, a domain error occurs and a range error may occur.

If base is zero and exponent is zero, a domain error may occur.

If base is zero and exponent is negative, a domain error or a pole error may occur.

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

  • pow ( + 0 , exponent ) , where exponent is a negative odd integer, returns +∞ and raises FE_DIVBYZERO
  • pow ( — 0 , exponent ) , where exponent is a negative odd integer, returns -∞ and raises FE_DIVBYZERO
  • pow ( ± 0 , exponent ) , where exponent is negative, finite, and is an even integer or a non-integer, returns +∞ and raises FE_DIVBYZERO
  • pow ( ± 0 , — ∞ ) returns +∞ and may raise FE_DIVBYZERO (until C23)
  • pow ( + 0 , exponent ) , where exponent is a positive odd integer, returns +0
  • pow ( — 0 , exponent ) , where exponent is a positive odd integer, returns -0
  • pow ( ± 0 , exponent ) , where exponent is positive non-integer or a positive even integer, returns +0
  • pow ( — 1 , ±∞ ) returns 1
  • pow ( + 1 , exponent ) returns 1 for any exponent , even when exponent is NaN
  • pow ( base, ± 0 ) returns 1 for any base , even when base is NaN
  • pow ( base, exponent ) returns NaN and raises FE_INVALID if base is finite and negative and exponent is finite and non-integer.
  • pow ( base, — ∞ ) returns +∞ for any |base|<1
  • pow ( base, — ∞ ) returns +0 for any |base|>1
  • pow ( base, + ∞ ) returns +0 for any |base|<1
  • pow ( base, + ∞ ) returns +∞ for any |base|>1
  • pow ( — ∞, exponent ) returns -0 if exponent is a negative odd integer
  • pow ( — ∞, exponent ) returns +0 if exponent is a negative non-integer or negative even integer
  • pow ( — ∞, exponent ) returns -∞ if exponent is a positive odd integer
  • pow ( — ∞, exponent ) returns +∞ if exponent is a positive non-integer or positive even integer
  • pow ( + ∞, exponent ) returns +0 for any negative exponent
  • pow ( + ∞, exponent ) returns +∞ for any positive exponent
  • except where specified above, if any argument is NaN, NaN is returned
Читать:
Как в powerpoint сделать появление текста по щелчку

[edit] Notes

Although pow cannot be used to obtain a root of a negative number, cbrt is provided for the common case where exponent is 1/3.

Функция pow

В C++, эта функция перегружена в заголовочных файлах <complex> и <valarray> (смотреть pow комплексных чисел и pow в библиотеке массивов числовых значений).

В Си, определена только версия функции с типами данных её параметров, — double . Другие перегруженные версии этой функции есть только в C++.

Параметры:

  • basis
    Значение с плавающей точкой — основание.
  • exponent
    Значение с плавающей точкой — степень.

Возвращаемое значение

Возведение значения basis в степень exponent .

Если величина результата настолько велика, что она не может быть представлена в объекте возвращаемого типа, возникает ошибка области допустимых значений, и функция возвращает значение HUGE_VAL с соответствующим ему знаком и устанавливает значение макроса ERRNO в ERANGE значение.

Если basis отрицательное и exponent не целое значение, или если basis равна нулю, а exponent — отрицательное, возникает ошибка области допустимых значений, и выполняется установка глобальной переменной ERRNO в значение EDOM .

C library function — pow()

The C library function double pow(double x, double y) returns x raised to the power of y i.e. x y .

Declaration

Following is the declaration for pow() function.

Parameters

x − This is the floating point base value.

y − This is the floating point power value.

Return Value

This function returns the result of raising x to the power y.

Example

The following example shows the usage of pow() function.

Let us compile and run the above program that will produce the following result −

Похожие статьи