這裡我們將會看到 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中文網其他相關文章!