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 email@example.com. 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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Strict Aliasing Rule in C with Examples
- Difference between cout and puts() in C++ with Examples
- Difference between forward list and list in C++
- Short-Circuiting in C++ and Linux
- Different types of range-based for loop iterators in C++
- Learn C++ Programming Step by Step - A 20 Day Curriculum!
- Difference between C and Dart
- Difference between Sentinel and Counter Controlled Loop in C
- Why do we need reference variables if we have pointers
- What are the differences between C and Embedded C?
- Similarities and Difference between Java and C++
- Macros and its types in C/C++
- Reversed Range-based for loop in C++ with Examples
- How to find index of a given element in a Vector in C++