Home C&C++函数库 c++ 语法 程序源码 Linux C库

nextafter

函数  <cmath> <ctgmath>

C99 double nextafter (double x , double y);
float nextafterf (float x , float y);
long double nextafterl (long double x, long double y);
C++11 double nextafter (double x , double y);
float nextafter (float x , float y);
long double nextafter (long double x, long double y);
double nextafter (Type1 x , Type2 y);       // additional overloads

下一个可表示的值
返回参数x在参数y方向上可以表示的最接近的数值 类似的函数nexttoward也有相同的行为,但它需要一个长double作为第二个参数。

C99 头文件<tgmath.h> 提供了该函数的类型泛型宏版本。
C++11 这个头文件(<cmath>) 为其他算术类型组合(Type1和Type2)提供了额外的重载: 这些重载在计算前将其实参转换为double,除非至少有一个实参是 long double类型(在这种情况下,两个实参都被转换为long double类型)。

☲  参数


x
基础值
y
返回值接近的趋向值.
如果两个参数相等,函数返回y。

☉  返回值



在y方向x之后的下一个可表示值。
如果x是该类型中可表示的最大有限值,而结果是无限的或不可表示的,则会发生溢出范围错误。
如果发生溢出范围错误: -并且math_errhandling设置了MATH_ERRNO:全局变量errno设置为ERANGE。 -并且math_errhandling设置了MATH_ERREXCEPT:引发FE_OVERFLOW

☣  示例



/* nextafter example */
#include <stdio.h>      /* printf */
#include <math.h>       /* nextafter */

int main ()
{
  printf ("first representable value greater than zero: %e\n", nextafter(0.0,1.0));
  printf ("first representable value less than zero: %e\n", nextafter(0.0,-1.0));
  return 0;
}

输出:
first representable value greater than zero: 4.940656e-324
first representable value less than zero: -4.940656e-324

🍄  另请参阅



nexttoward 下一个可表示趋向精确值(function )

联系我们 免责声明 关于CandCplus 网站地图