Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7794607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:49:27+00:00 2026-06-01T22:49:27+00:00

The title is quite self-explanatory, input is given double value, and I want to

  • 0

The title is quite self-explanatory, input is given double value, and I want to add/substract the smallest amount possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:49:28+00:00Added an answer on June 1, 2026 at 10:49 pm

    You can use nextafter, which is available if your compiler implements C99’s math functions (i.e., C++11 and above). This function (and its various overloads) can be described as:

    double nextafter(double value, double target);
    

    It will move from value in the direction of target by the smallest possible amount (typically by tweaking the bit representation of the float). If value is already at target, this does nothing.

    If target is greater than value this will increment value by the smallest possible amount. If target is less than value this will decrement value by the smallest possible amount.

    Common usage is to pass either DBL_MAX or INFINITY as the target to increase the minimal amount (or, the negation of them to decrease the minimal amount).

    The choice between DBL_MAX and INFINITY depends on what you want to do at the boundary – nextafter(DBL_MAX, DBL_MAX) == DBL_MAX, but nextafter(DBL_MAX, INFINITY) == INFINITY.

    And yes, it’s poorly named. See also nextafter and nexttoward: why this particular interface?.


    #include <cfloat> // DBL_MAX
    #include <cmath> // std::nextafter
    
    double x = 0.1;
    
    // Next representable number **after** x in the direction of DBL_MAX.
    // (i.e., this is larger than x, and there is no double between it and x)
    double xPlusSmallest = std::nextafter(x, DBL_MAX); 
    
    // Next representable number **before** x in the direction of -DBL_MAX.
    // (i.e., this is smaller than x, and there is no double between it and x)
    double xMinusSmallest = std::nextafter(x, -DBL_MAX); 
    

    Even if your compiler doesn’t support it, it probably has an instrinsic for it. (MSVC has had _nextafter since 2005, for example. GCC probably implements it as standard.)

    If your compiler doesn’t support it but Boost is available to you, you can do this:

    #include <boost/math/special_functions/next.hpp>
    #include <cfloat> 
    
    double x = 0.1;
    
    double xPlusSmallest = boost::math::nextafter(x, DBL_MAX); 
    double xMinusSmallest = boost::math::nextafter(x, -DBL_MAX); 
    

    And if none of those work for you, you’ll just have to crack open the Boost header and copy it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well the title is quite self explanatory. I want to build two panels one
Well, the title is quite self-explanatory... Is it possible to set default port number
Title is quite self explanatory, but I have some animation being done in a
Title says it mostly. I want to add a simple extension method to the
The title of this question should be pretty self explanatory. I am making an
Sorry for the long and self explanatory title, but UIScrollView has raised so many
Not sure if the title is quite right for the question but I can't
I'm sorry if the title is quite confusing but I am wondering if it's
I have quite a lot of music files but their title attributes have the
Apologies for the vague title, but this is quite a difficult problem to explain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.