How would you solve below problems in C/C++?
- What is the smallest representable positive floating point number in C/C++?
- What is the largest representable negative floating point number in C/C++?
- Given a positive floating point number x, find the largest representable floating point value smaller than x?
nextafter(x, y) and nexttoward(x.y)
In C and C++, both nextafter(x, y) and nexttoward(x.y) are similar functions defined in math.h or cmath header files. They both return next representable value after x in the direction of y. nexttoward() has more precise second parameter y.
The following program demonstrates the concept :
nextafter first value greater than zero: 4.940656e-324 nextafter first value less than zero: -4.940656e-324 nexttoward first value greater than zero: 4.940656e-324 nexttoward first valnextafter first value greater than zero: 4.940656e-324 nextafter first value less than zero: -4.940656e-324 nexttoward first value greater than zero: 4.940656e-324 nexttoward first value less than zero: -4.940656e-324 ue less than zero: -4.940656e-324
This article is contributed by Aditya Chatterjee. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- nearbyint() function in C++
- Print system time in C++ (3 different ways)
- pthread_cancel() in C with example
- User Defined Literals in C++
- Placement new operator in C++
- std::regex_match, std::regex_replace() | Regex (Regular Expression) In C++
- unordered_multiset and its uses
- std::fill() and fill_n() in C++ STL
- Database Connectivity using C/C++
- unorderd_set in C++ STL
- Extra brackets with function names in C/C++
- Print 2D matrix in different lines and without curly braces in C/C++?
- Concept of setjump and longjump in C
- Local Labels in C
- How to print "GeeksforGeeks" with empty main() in C, C++ and Java?