C++ Reference: Standard C++ Library reference: C Library: cmath: logb

发布于:2022-12-06 ⋅ 阅读:(565) ⋅ 点赞:(0)

C++官网参考链接:https://cplusplus.com/reference/cmath/logb/

函数 
<cmath> <ctgmath>
logb
C99
double logb(double x);      
float logbf(float x);
long double logbl(long double x);
C++11
double logb(double x);      
float logb(float x);
long double logb(long double x);     
double logb(T x);   // additional overloads for integral types

计算以浮点数为底数的对数
返回|x|的对数,使用FLT_RADIX作为对数的底数。
在大多数平台上,FLT_RADIX为2,因此该函数等价于正值的log2
C99
头文件<tgmath.h>提供了该函数的泛型类型的宏版本。
C++11
在此头文件(<cmath>)中为整型(integral types)提供了额外的重载:这些重载在计算之前有效地将x转换为double类型(定义T为任何整型(integral types))。

形参

计算其对数的值。

返回值
FLT_RADIX为底数的x的对数。
如果x为0,则可能导致定义域错误或极点错误(或者没有错误,取决于库实现)。
如果发生定义域错误: 
math_errhandling具有MATH_ERRNO集合:全局变量errno设置为EDOM
math_errhandling具有MATH_ERREXCEPT集合:将引发FE_INVALID
如果发生极点错误: 
math_errhandling具有MATH_ERRNO集合:全局变量errno设置为ERANGE
math_errhandling具有MATH_ERREXCEPT集合:引发FE_DIVBYZERO

用例
/* logb example */
#include <stdio.h>      /* printf */
#include <math.h>       /* logb */

int main ()
{
  double param, result;
  param = 1024.0;
  result = logb (param);
  printf ("logb (%f) = %f.\n", param, result );
  return 0;
}
输出:

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到