当前位置: C语言 -- 标准库 -- <math.h> -- nexttowardf

nexttowardf函数


概要:
#include <math.h>
float nexttowardf(float x, long double y);

描述:

该函数确定沿参数y方向、参数x后的下一个float类型的可表示值。

该函数等价于nextafterf函数,区别在于参数y为long double类型;并且如果参数x等于参数y,函数将返回转换为float类型的y。该函数结果由函数类型决定,第二个参数不会丢失范围或者精度。


参数:
float x

参数为float类型的浮点数。

long double y

参数为long double类型的浮点数。


返回值:

函数返回沿参数y方向、参数x后的下一个float类型的可表示值。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
/*函数nexttowardf范例*/

#include <float.h>
#include <math.h>
#include <stdio.h>

int main(void)
{
    float x = 3.00f;
    long double y = 4.00L;

    printf("%.*f\n", (FLT_DECIMAL_DIG-1), nexttowardf(x,y));

    return 0;
}

输出:

3.00000024


相关内容:
nexttoward 确定double类型的下一个可表示值的函数。
nexttowardl 确定long double类型的下一个可表示值的函数。
nexttowardd32 确定_Decimal32类型的下一个可表示值的函数。
nexttowardd64 确定_Decimal64类型的下一个可表示值的函数。
nexttowardd128 确定_Decimal128类型的下一个可表示值的函数。


主要参考资料:

1、ISO/IEC 9899:2024

2、ISO/IEC 9899:2018