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

nexttoward

函数  <cmath> <ctgmath>

C99 double nexttoward (double x , double y);
float nexttowardf (float x , float y);
long double nexttowardl (long double x, long double y);
C++11 double nexttoward (double x , double y);
float nexttoward (float x , float y);
long double nexttoward (long double x, long double y);
double nexttoward (Type1 x , Type2 y);       // additional overloads

下一个可表示的趋向精确值
返回参数x在参数y方向上可以表示的最接近的数值 该函数的行为与nextafter类似,但可能使用更精确的y。

C99 头文件<tgmath.h> 提供了该函数的类型泛型宏版本。
C++11 这个头文件(<cmath>) 为整型提供了额外的重载:这些重载有效地在计算之前将x转换为double (在T是任何整型时定义)

☲  参数


x
基础值
y
返回值接近的趋向值.
如果两个参数相等,函数返回y(转换为返回类型)。

☉  返回值



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

☣  示例



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

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

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

🍄  另请参阅



nextafter 下一个可表示值(function )

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