TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C++ Math nextafter() Function

C++ Math nextafter() Function with tutorial for beginners and professionals with examples on isgreaterequal(), less(), islessequal(), islessgreater(), isunordered(), exp(), frexp(), ldexp(), log(), log10(), modf(), exp2(), expm1(), log1p(), log2(), logb(), scalbn(), scalbln() etc.

<< Back to CPP

C++ Math nextafter()

The nextafter() function represents the next representable value in a specific direction.

Suppose two numbers are 'from' and 'to'. Therefore, the nextafter() function finds the next value of 'from' in the direction of 'to'.

Syntax

float nextafter( float from, float to);
double nextafter( double from, double to);
long double nextafter( long double from, long double to);
promoted nextafter( arithmetic from, arithmetic to);

Note: If any argument is long double, then the return type is long double. If not, the return type is double.

Parameter

( from, to): These are the floating point values.

Return value

  • If 'from' equals to 'to', it returns the value of 'from'.
  • If no error occurs, the next representable value of 'from' is returned.

Example 1

Let's see a simple example when the value of 'from' and 'to' are equal.

#include 
#include
using namespace std;
int main()
{
     float from=6.7;
     float to=6.7;
     cout<<"Values of from and to are:"<

Output:

Values of from and to are:6.7, 6.7
6.7

In the above example, values of 'from' and 'to' are equal. Therefore, the function returns the value of 'from'.

Example 2

Let's see a simple example when 'from' and 'to' are of same type.

#include 
#include
using namespace std;
int main()
{
      double from=0.0;
      double to=6.0;
      cout<<"Values of from and to are:"<

Output:

Values of from and to are:0, 6
4.94066e-324

In the above example, 'from' and 'to' are of same type but are unequal. The nextafter() function returns the value i.e 4.94066e-324


Next TopicC++ Math Functions




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf