Home >Backend Development >C++ >In C/C++, nextafter() and nexttoward() are translated as follows:
Here we will see the effect of nextafter() and nextforward() functions in C or C. These functions exist in the math.h or cmath libraries.
If the function is similar to nextafter(a, b) and nextforward(a, b). These functions find the next representable value after a in the b direction. nextforward() has a more precise second parameter 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
The above is the detailed content of In C/C++, nextafter() and nexttoward() are translated as follows:. For more information, please follow other related articles on the PHP Chinese website!