这里我们将看到 C 或 C++ 中的 nextafter() 和 nextforward() 函数的效果。这些函数存在于 math.h 或 cmath 库中。
如果函数类似于 nextafter(a, b) 和 nextforward(a, b)。这些函数用于在 b 方向上查找 a 之后的下一个可表示值。 nextforward() 有更精确的第二个参数 b。
#include <stdio.h> #include <math.h> main () { //The nextafter function() printf ("Smallest representable number after 0 towards 1 : %e\n", nextafter(0.0, 1.0)); printf ("Largest representable number before -1 towards 0 :%e\n", nextafter(0.0, -1.0)); printf ("Largest +ve representable number after 0.8 : %e\n", nextafter(0.8, 0.0)); // using nexttoward printf("\n"); printf ("Smallest representable number after 0 towards 1 : %e\n", nexttoward(0.0, 1.0)); printf ("Largest representable number before -1 towards 0 : %e\n", nexttoward(0.0, -1.0)); printf ("Largest +ve representable number after 0.8 : %e\n", nexttoward(0.8, 0.0)); }
Smallest representable number after 0 towards 1 : 4.940656e-324 Largest representable number before -1 towards 0 :-4.940656e-324 Largest +ve representable number after 0.8 : 8.000000e-001 Smallest representable number after 0 towards 1 : 4.940656e-324 Largest representable number before -1 towards 0 : -4.940656e-324 Largest +ve representable number after 0.8 : 8.000000e-001
以上是在C/C++中,nextafter()和nexttoward()的翻译如下:的详细内容。更多信息请关注PHP中文网其他相关文章!