Как извлечь корень в c
Стандартная библиотека языка Си предоставляет ряд математических функций, которые определены в разных заголовочных файлах, но в основном определены в файле math.h .
Степерь числа. pow
Функция pow() , определенная в заголовочном файле math.h , возвращает степень числа:
Стоит отметить, что эта функция возвращает число типа double .
Для возведения в степень чисел типа float и long double также определены функции powf() и powl() соответственно.
Округление числа. round
Функция round() округляет число до ближайшего целого. В качестве параметра она принимает число типа double :
Квадратный корень. sqrt
Функция sqrt() возвращает квадратный корень числа типа double :
Для получения квадратного корня числа float также есть функция sqrtf() , а для числа типа long double — функция sqrtl()
sqrt, sqrtf, sqrtl
If no errors occur, square root of arg ( \( <\small \sqrt
If a domain error occurs, an implementation-defined value is returned (NaN where supported).
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.
Domain error occurs if arg is less than zero.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
- If the argument is less than -0, FE_INVALID is raised and NaN is returned.
- If the argument is +∞ or ±0, it is returned, unmodified.
- If the argument is NaN, NaN is returned
[edit] Notes
sqrt is required by the IEEE standard to be correctly rounded from the infinitely precise result. In particular, the exact result is produced if it can be represented in the floating-point type. The only other operations which require this are the arithmetic operators and the function fma . Other functions, including pow , are not so constrained.