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 8722503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:26:11+00:00 2026-06-13T07:26:11+00:00

doubles seem not to work. can I only use int? I heard that I

  • 0

doubles seem not to work. can I only use int?
I heard that I can use C++ function templates to change this to double. I’m not sure how to go about that though.

 #include <iostream>                                                     // Necessary 
using namespace std;
#define mMaxOf2(max, min) ((max) > (min) ? (max) : (min))
#define mMaxOf3(Min, Mid, Max)\
{\
     mMaxOf2(mMaxOf2((Min), (Mid)),(Max))\
}
inline long double fMaxOf2(long double min, long double max)
{
    return max > min ? max : min;
}

inline long double fMaxOf3(long double Min, long double Mid, long double Max)
{
      return fMaxOf2(Min, fMaxOf2( Mid, Max));
    //fMaxOf2(Min, fMaxOf2( Mid, Max));     caused nan   problem      
}

int main()
{
    double primary;
    double secondary;
    double tertiary;

    cout << "Please enter three numbers: ";
    cin >> primary >> secondary >> tertiary;
    cout << "The maximum of " << primary << " " << secondary << " " << tertiary;

    long double maximum = mMaxOf3(primary, secondary, tertiary);
    cout << " using mMaxOf3 is " << maximum;

    cout << "\nThe maximum of " << primary << " " << secondary << " " << tertiary;
    long double maxim = fMaxOf3(primary, secondary, tertiary);
    cout << " using fMaxOf3 is " << maxim;

    return 0;
}

So the problem was

    inline long double fMaxOf2(long double min, long double max)
    {
        return max > min ? max : min;
    }

    inline long double fMaxOf3(long double Min, long double Mid, long double Max)
    {
        fMaxOf2(Min, fMaxOf2( Mid, Max));    // This was wrong
        // It was fMaxOf2 (fMaxOf2(Min, Mid, Max);
    }

Anyway now I get a new error… says maxim is nan…
Solved it. Thanks Everyone!

  • 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-13T07:26:13+00:00Added an answer on June 13, 2026 at 7:26 am

    Using templates:

    template<class T>
    inline T fMaxOf2(T min, T max)
    {
        return max > min ? max : min;
    }
    
    template<class T>
    inline T fMaxOf3(T Min, T Mid, T Max)
    {
        fMaxOf2(Min, fMaxOf2(Mid, Max));
    }
    

    To use the functions:

    double max = fMaxOf3<double>(0.231, 123.21312, 904.4);
    

    Now you may ask, why is that? Templates accepts, well, template arguments. T in template<class T> is the argument for the two functions. T now can be used in your functions as a “normal” type or class.

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

Sidebar

Related Questions

This may seem like a realy basic question but... How do you use double
I can't seem to get this toString() method to work? The deepToString method works
This may seem like an absurd question, however thought I best double check beforehand.
Given doubles can't be used in volatile fields, is this a safe alternative? Or
This is the code i using, but i not sure why it can be
I am very frustrated with how MD and IB seem to not work well
This has been driving be crazy, but I can't seem to find an answer.
I wrote a function to convert 64-bit Double to ByteString (architecture/type safety is not
I have a some doubles that I want to port into NSDecimalNumber, because I'm
Processing time doubles as Y goes to the right. Can anybody tell me why?

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.