Home > Backend Development > C++ > In C/C++, nextafter() and nexttoward() are translated as follows:

In C/C++, nextafter() and nexttoward() are translated as follows:

王林
Release: 2023-09-05 23:17:06
forward
1510 people have browsed it

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.

Example

#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));
}
Copy after login

Output

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
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template