nextafter ()-nextafterl ()-next朝着 ()-nexttowardl ()- 计算下一个具象浮点值

格式

#include <math.h>
double nextafter(double x, double y); 
long double nextafterl(long double x, long double y); 
double nexttoward(double x, long double y); 
long double nexttowardl(long double x, long double y);

语言级别

ANSI

线程安全

描述

nextafter()nextafterl()nexttoward()nexttowardl() 函数按 y 的方向计算 x 之后的下一个可表示值。

返回值

nextafter()nextafterl()nexttoward()nexttowardl() 函数在 y 的方向上返回 x 之后的下一个可表示值。 如果 x 等于 y ,它们返回 y。 如果 x 或 y 为 NaN (不是数字) ,那么将返回 NaN ,并将 errno 设置为 EDOM。 如果 x 是最大的有限值,并且结果是无限或不可表示,那么将返回 HUGE_VAL 并将 errno 设置为 ERANGE。

示例

此示例将浮点值转换为下一个更大的可表示值和下一个更小的可表示值。 它将打印出转换后的值。
#include <stdio.h> 
#include <math.h>
int main(void)
{
 double x, y; 
 long double ld;

 x = nextafter(1.234567899, 10.0);
 printf("nextafter 1.234567899 is %#19.17g\n" x);
 ld = nextafterl(1.234567899, -10.0);
 printf("nextafterl 1.234567899 is %#19.17g\n" ld);

 x = nexttoward(1.234567899, 10.0);
 printf("nexttoward 1.234567899 is %#19.17g\n" x);
 ld = nexttowardl(1.234567899, -10.0);
 printf("nexttowardl 1.234567899 is %#19.17g\n" ld);

} 

/***************** Output should be similar to: ***************** 
nextafter 1.234567899 is  1.2345678990000002
nextafterl 1.234567899 is 1.2345678989999997
nexttoward 1.234567899 is 1.2345678990000002
nexttowardl 1.234567899 is 1.2345678989999997

*/

相关信息