Using "numeric_limits<double>::min()" in MFC application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jalal

    Using "numeric_limits<double>::min()" in MFC application

    I am trying to use numeric_limits< double>::min() in an MFC application
    in Microsoft Visual C++.NET 2003. I am having some difficulties here.
    The following are the parts of a simple program I wrote and
    corresponding error massages. I am confused here. Similar codes work
    fine in Win32 Console Project. Can you please help me to resolve
    this? Thank you for your helps.

    Best Regards,

    Jalal



    Code
    -------------------------------
    // Created by Microsoft Visual C++.NET
    #include "stdafx.h"
    #include "test.h"
    #include "testDlg.h"
    #include ".\testdlg. h"

    // I have added to use numeric_limits
    #include <limits>
    using namespace std;


    void CtestDlg::OnBnC lickedSubmit()
    {
    double y;

    // TODO: Add your control notification handler code here
    UpdateData(TRUE );

    y = numeric_limits< double>::min();

    // Writing y in dialog box
    x.Format("%.10f ", double(y));

    UpdateData(FALS E);
    }


    Error massage:
    -----------------------
    warning C4003: not enough actual parameters for macro 'min'
    error C2589: '(' : illegal token on right side of '::'
    error C2059: syntax error : '::'
  • Pete Becker

    #2
    Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

    Jalal wrote:[color=blue]
    >
    > warning C4003: not enough actual parameters for macro 'min'
    > error C2589: '(' : illegal token on right side of '::'
    > error C2059: syntax error : '::'[/color]

    The windows headers do you the favor of providing macros named 'min' and
    'max' that can screw up your code. To get rid of 'em, add

    #define NOMINMAX

    to your stdafx.h file, before any #include directives.

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)

    Comment

    • Alf P. Steinbach

      #3
      Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

      * m.jalal@worldne t.att.net (Jalal) schriebt:[color=blue]
      > I am trying to use numeric_limits< double>::min()[/color]

      Yes?

      [color=blue]
      > in an MFC application in Microsoft Visual C++.NET 2003.[/color]

      That's off-topic here, but you'll get answers to such questions in
      e.g. [comp.os.ms-windows.program mer.win32] (I might even answer it
      there myself ;-) ), or in a Microsoft newsgroup.


      [color=blue]
      > I am having some difficulties here.
      > The following are the parts of a simple program I wrote and
      > corresponding error massages. I am confused here. Similar codes work
      > fine in Win32 Console Project. Can you please help me to resolve
      > this? Thank you for your helps.[/color]

      To top it off you have not included the _relevant_ parts of your program.
      Please do that when reposting your question in e.g. the group mentioned
      above. Might also be a good idea to state that the question was earlier
      posted in [comp.lang.c++] but off-topic there.

      --
      A: Because it messes up the order in which people normally read text.
      Q: Why is top-posting such a bad thing?
      A: Top-posting.
      Q: What is the most annoying thing on usenet and in e-mail?

      Comment

      • Rolf Magnus

        #4
        Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

        Alf P. Steinbach wrote:
        [color=blue]
        > * m.jalal@worldne t.att.net (Jalal) schriebt:[color=green]
        >> I am trying to use numeric_limits< double>::min()[/color]
        >
        > Yes?[/color]

        What makes you doubt that?
        [color=blue][color=green]
        >> in an MFC application in Microsoft Visual C++.NET 2003.[/color]
        >
        > That's off-topic here, but you'll get answers to such questions in
        > e.g. [comp.os.ms-windows.program mer.win32] (I might even answer it
        > there myself ;-) ), or in a Microsoft newsgroup.[/color]

        The question isn't actually about MFC, though the problem itself seems
        to be related to the windows platform. However, the OP probably didn't
        know that. He just got an error message about
        numeric_limits< double>::max(), so he wanted to know what he's doing
        wrong.
        [color=blue][color=green]
        >> I am having some difficulties here.
        >> The following are the parts of a simple program I wrote and
        >> corresponding error massages. I am confused here. Similar codes
        >> work
        >> fine in Win32 Console Project. Can you please help me to resolve
        >> this? Thank you for your helps.[/color]
        >
        > To top it off you have not included the _relevant_ parts of your
        > program.[/color]

        He hasn't? What would be missing?
        [color=blue]
        > Please do that when reposting your question in e.g. the group
        > mentioned above. Might also be a good idea to state that the question
        > was earlier posted in [comp.lang.c++] but off-topic there.[/color]

        The question wasn't, even if the answer might be.

        Comment

        • Alf P. Steinbach

          #5
          Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

          * Rolf Magnus <ramagnus@t-online.de> schriebt:[color=blue]
          > Alf P. Steinbach wrote:
          >[color=green]
          > > * m.jalal@worldne t.att.net (Jalal) schriebt:[color=darkred]
          > >> I am trying to use numeric_limits< double>::min()[/color]
          > >
          > > Yes?[/color]
          >
          > What makes you doubt that?[/color]

          Why do you think I doubt what?

          [color=blue][color=green][color=darkred]
          > >> in an MFC application in Microsoft Visual C++.NET 2003.[/color]
          > >
          > > That's off-topic here, but you'll get answers to such questions in
          > > e.g. [comp.os.ms-windows.program mer.win32] (I might even answer it
          > > there myself ;-) ), or in a Microsoft newsgroup.[/color]
          >
          > The question isn't actually about MFC, though the problem itself seems
          > to be related to the windows platform.[/color]

          It is about one particular vendor's header files for the Windows platform.

          [color=blue]
          > However, the OP probably didn't
          > know that. He just got an error message about
          > numeric_limits< double>::max(), so he wanted to know what he's doing
          > wrong.[/color]

          One thing he or she did wrong was to not try it out in standard C++ before
          asking in a standard C++ Usenet group.

          [color=blue][color=green][color=darkred]
          > >> I am having some difficulties here.
          > >> The following are the parts of a simple program I wrote and
          > >> corresponding error massages. I am confused here. Similar codes
          > >> work
          > >> fine in Win32 Console Project. Can you please help me to resolve
          > >> this? Thank you for your helps.[/color]
          > >
          > > To top it off you have not included the _relevant_ parts of your
          > > program.[/color]
          >
          > He hasn't? What would be missing?[/color]

          What was missing was the include file where the vendor-specific header
          files were erronously included for C++, namely [stdafx.h].

          [color=blue][color=green]
          > > Please do that when reposting your question in e.g. the group
          > > mentioned above. Might also be a good idea to state that the question
          > > was earlier posted in [comp.lang.c++] but off-topic there.[/color]
          >
          > The question wasn't, even if the answer might be.[/color]

          Both the question and the answer were off-topic. The question because it
          concerned use of one particular vendor's header files on one particular
          platform, as could easily be ascertained by trying standard C++. The answer
          for the same reason, but then it's toss-of-the-coin whether to give a very
          short "satisfying " answer (short-term) or point to a more appropriate group.

          --
          A: Because it messes up the order in which people normally read text.
          Q: Why is top-posting such a bad thing?
          A: Top-posting.
          Q: What is the most annoying thing on usenet and in e-mail?

          Comment

          • P.J. Plauger

            #6
            Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

            "Alf P. Steinbach" <alfps@start.no > wrote in message
            news:409a0ddb.1 910671296@news. individual.net. ..
            [color=blue]
            > Both the question and the answer were off-topic. The question because it
            > concerned use of one particular vendor's header files on one particular
            > platform, as could easily be ascertained by trying standard C++. The[/color]
            answer[color=blue]
            > for the same reason, but then it's toss-of-the-coin whether to give a very
            > short "satisfying " answer (short-term) or point to a more appropriate[/color]
            group.

            Gosh. And I just tried compiling a simple program with gcc.
            The headers look reasonably conforming, and yet I get
            this diagnostic from the linker that sqrt is undefined.
            Had I known that I failed to write the -lm flag on the
            compiler command line, I would have known *not* to ask
            for help from this newsgroup (where many contributors
            happen to know the answer), but to go to a gcc specific
            newsgroup instead. Where's prescience when you really
            need it?

            The C++ Standard is a worthless document without real
            live implementations of the language it describes.
            Sadly, there are no standards for the kind of gotchas
            different implementations inflict on us. If only there
            were a newsgroup that understood this, or at least had
            less zealous Topic Police.

            P.J. Plauger
            Dinkumware, Ltd.



            Comment

            • Alf P. Steinbach

              #7
              Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

              * "P.J. Plauger" <pjp@dinkumware .com> schriebt:[color=blue]
              > "Alf P. Steinbach" <alfps@start.no > wrote in message
              > news:409a0ddb.1 910671296@news. individual.net. ..
              >[color=green]
              > > Both the question and the answer were off-topic. The question because it
              > > concerned use of one particular vendor's header files on one particular
              > > platform, as could easily be ascertained by trying standard C++. The[/color]
              > answer[color=green]
              > > for the same reason, but then it's toss-of-the-coin whether to give a very
              > > short "satisfying " answer (short-term) or point to a more appropriate[/color]
              > group.
              >
              > Gosh. And I just tried compiling a simple program with gcc.
              > The headers look reasonably conforming, and yet I get
              > this diagnostic from the linker that sqrt is undefined.
              > Had I known that I failed to write the -lm flag on the
              > compiler command line, I would have known *not* to ask
              > for help from this newsgroup (where many contributors
              > happen to know the answer), but to go to a gcc specific
              > newsgroup instead.[/color]

              Well you're so experienced by now, having written all these libraries and
              whatnot, that you know that a linker issue is pure tool usage and is
              off-topic in this group. The same goes for how to include <windows.h>
              properly for C++, or how to use MS Visual Studio. This is in the FAQ.

              I don't understand why the heck you're jumping in here, because you sure
              as h... do know all this, and would never be confused by a linker issue.

              [color=blue]
              >Where's prescience when you really need it?[/color]

              Indeed, one cannot know in advance the details of why an error occurs.

              But one can know that it is to do with linking (pure tool usage).

              Or that is to do with #include of Microsoft's <windows.h> (pure MS issue).



              [color=blue]
              > The C++ Standard is a worthless document without real
              > live implementations of the language it describes.
              > Sadly, there are no standards for the kind of gotchas
              > different implementations inflict on us. If only there
              > were a newsgroup that understood this, or at least had
              > less zealous Topic Police.[/color]

              I agree with that. Such groups exist. E.g., [no.it.programme ring.c++],
              which is a Norwegian group where English threads are supported -- sometimes
              frequented by Bjarne, and perhaps in the future also you?

              Also, perhaps what's regarded as on-topic here should be loosened up a bit.

              I've argued for that before, and will probably also in the future...

              --
              A: Because it messes up the order in which people normally read text.
              Q: Why is top-posting such a bad thing?
              A: Top-posting.
              Q: What is the most annoying thing on usenet and in e-mail?

              Comment

              • Julie

                #8
                Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

                "Alf P. Steinbach" wrote:
                [snip][color=blue]
                > Also, perhaps what's regarded as on-topic here should be loosened up a bit.[/color]

                Funny thing is that since this newsgroup doesn't have a charter, there really
                isn't a notion of on or off topic here...

                The FAQ ain't it, either.

                First things first, let's get a charter for the newsgroup.

                Comment

                • E. Robert Tisdale

                  #9
                  Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

                  Julie wrote:
                  [color=blue]
                  > Alf P. Steinbach wrote:
                  > [snip]
                  >[color=green]
                  >>Also, perhaps what's regarded as on-topic here should be loosened up a bit.[/color]
                  >
                  > Funny thing is that since this newsgroup doesn't have a charter,
                  > there really isn't a notion of on or off topic here...[/color]

                  There certainly *is* strong opinion
                  about what is on and off topic in the comp.lang.c++ newsgroup.
                  Whether there is consensus or not is independent
                  of whether there is a charter or not.
                  [color=blue]
                  >
                  > The FAQ ain't it, either.
                  >
                  > First things first, let's get a charter for the newsgroup.[/color]

                  A charter won't help build consensus.
                  A charter won't help enforce rules.
                  A charter probably won't even help end discussion
                  about what is on or off topic in this newsgroup.

                  What helps is if you ignore off-topic articles.
                  If a subject is off-topic in the comp.lang.c++ newsgroup,
                  it is usually sufficient to simply mention that fact
                  to alert unwary subscribers who might otherwise respond.

                  Almost all off-topic articles are posted by regular subscribers
                  as an off-topic digression from a legitimate thread.
                  Only a tiny fraction are posted by new subscribers.

                  The comp.lang.c++ has a higher signal-to-noise ratio
                  than newsgroups that have a charter.
                  Let's not screw that up.

                  Comment

                  • Alf P. Steinbach

                    #10
                    Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

                    * Julie <julie@nospam.c om> schriebt:[color=blue]
                    > "Alf P. Steinbach" wrote:
                    > [snip][color=green]
                    > > Also, perhaps what's regarded as on-topic here should be loosened up a bit.[/color]
                    >
                    > Funny thing is that since this newsgroup doesn't have a charter, there really
                    > isn't a notion of on or off topic here...
                    >
                    > The FAQ ain't it, either.
                    >
                    > First things first, let's get a charter for the newsgroup.[/color]

                    Well, I'm not sure of the technicalities of retrofitting a charter, but in
                    principle I agree with you -- the infamous "someone" should do this!

                    The FAQ as well as the monthly posting should of course include the charter,
                    when and if it gets written and passes voting (caveat: procedure for that?).

                    A good place to start might be the [comp.lang.c++.m oderated] charter, e.g. at
                    <url:
                    ftp://ftp.isc.org/usenet/news.announce.n ewgroups/comp/comp.lang.c++.m oderated>:

                    <CLC++M CHARTER>
                    comp.lang.c++.m oderated is a moderated news group for discussion of common
                    C++ programming issues. Welcomed topics of discussion will include any topic
                    directly related to the C++ programming language. The moderators will decide
                    which posts are of general interest to the worldwide C++ community. The
                    moderators are free to reject any post which is deemed to be system-specific,
                    covered by the comp.lang.c++ FAQ(s), and/or more appropriate to another
                    Usenet discussion group. The following is a short list of posts which
                    will be considered off-topic by the moderators.

                    - System-specific problems which are better addressed in existing
                    system-specific newsgroups may be considered off-topic. (Here we
                    are using the term "system-specific" in reference to a particular
                    computer system configuration.)
                    - Questions answered in the comp.lang.c++ FAQ(s) will be considered
                    off-topic.
                    - Obvious homework problems and trivial questions that can be answered by
                    quick inspection of any C++ text may be considered off-topic.
                    - Very broad questions which could equally apply to any computer programming
                    language may be considered off-topic.
                    - Advocacy and "flame wars" about C++ will be considered off-topic.
                    - Advertising shall be considered off-topic.
                    - C++ product announcements shall be at the discretion of the
                    moderators.

                    Overall, the moderators shall lean towards accepting posts and the free
                    exchange of ideas and general discussion of C++ issues.
                    </CLC++M CHARTER>

                    What's a bit lacking here, in my opinion, is topicality of library-specific
                    problems. A library may be system independent (such as Boost), or very widely
                    used. But there is a difference discussing the use of e.g. boost::shared_p tr
                    for pimpl idiom, and on the other hand "how do I implement Tiny Basic using
                    Boost Spirit?" -- which I'd regard as off-topic no matter Boost or not. In
                    short there must be some general C++ relevance, not just a C++ association.
                    The charter says any topic directly related to the C++ language is welcomed,
                    but it doesn't say any topic only vaguely associated to C++ is unwelcome.

                    Also, there is the question of actually using C++ for those tasks the language
                    is intended for.

                    For example, currently the use of C++ to provide bindings for other languages,
                    such as Java JNI, is off-topic in just about any group except
                    [comp.programmin g], but I think such actual practice should be on-topic here.

                    --
                    A: Because it messes up the order in which people normally read text.
                    Q: Why is top-posting such a bad thing?
                    A: Top-posting.
                    Q: What is the most annoying thing on usenet and in e-mail?

                    Comment

                    • Julie

                      #11
                      Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

                      "E. Robert Tisdale" wrote:[color=blue]
                      >
                      > Julie wrote:
                      >[color=green]
                      > > Alf P. Steinbach wrote:
                      > > [snip]
                      > >[color=darkred]
                      > >>Also, perhaps what's regarded as on-topic here should be loosened up a bit.[/color]
                      > >
                      > > Funny thing is that since this newsgroup doesn't have a charter,
                      > > there really isn't a notion of on or off topic here...[/color]
                      >
                      > There certainly *is* strong opinion
                      > about what is on and off topic in the comp.lang.c++ newsgroup.
                      > Whether there is consensus or not is independent
                      > of whether there is a charter or not.
                      >[color=green]
                      > >
                      > > The FAQ ain't it, either.
                      > >
                      > > First things first, let's get a charter for the newsgroup.[/color]
                      >
                      > A charter won't help build consensus.
                      > A charter won't help enforce rules.
                      > A charter probably won't even help end discussion
                      > about what is on or off topic in this newsgroup.[/color]

                      All true, however it doesn't change the fact that a charter should be the first
                      order of business if better defining newsgroup topicality is needed.
                      [color=blue]
                      > The comp.lang.c++ has a higher signal-to-noise ratio
                      > than newsgroups that have a charter.
                      > Let's not screw that up.[/color]

                      Are you concluding that necessarily having a charter decreases signal to noise?

                      Comment

                      • Ioannis Vranos

                        #12
                        Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

                        "Julie" <julie@nospam.c om> wrote in message
                        news:409AC357.2 D3FAC6E@nospam. com...[color=blue]
                        > "Alf P. Steinbach" wrote:
                        > [snip][color=green]
                        > > Also, perhaps what's regarded as on-topic here should be loosened up a[/color][/color]
                        bit.[color=blue]
                        >
                        > Funny thing is that since this newsgroup doesn't have a charter, there[/color]
                        really[color=blue]
                        > isn't a notion of on or off topic here...
                        >
                        > The FAQ ain't it, either.
                        >
                        > First things first, let's get a charter for the newsgroup.[/color]



                        But Usenet is still governed by the old days spirit of freedom. That means
                        that when you think something does not fit to be discussed here, you notify
                        the user to find a more appropriate newsgroup.






                        Regards,

                        Ioannis Vranos

                        Comment

                        • Ioannis Vranos

                          #13
                          Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

                          "Julie" <julie@nospam.c om> wrote in message
                          news:409AD464.8 10BF02B@nospam. com...[color=blue]
                          >
                          > All true, however it doesn't change the fact that a charter should be the[/color]
                          first[color=blue]
                          > order of business if better defining newsgroup topicality is needed.[/color]


                          The topicality is well known. ISO C++.






                          Regards,

                          Ioannis Vranos

                          Comment

                          • Jalal

                            #14
                            Re: Using &quot;numeric_l imits&lt;double &gt;::min()&quo t; in MFC application

                            Dear Pete:

                            I have implemented what you have suggested. My program is now
                            working. Thank you for your helps.

                            Best Regards,

                            Jalal


                            Pete Becker <petebecker@acm .org> wrote in message news:<40999CC3. ACCF49AF@acm.or g>...[color=blue]
                            > Jalal wrote:[color=green]
                            > >
                            > > warning C4003: not enough actual parameters for macro 'min'
                            > > error C2589: '(' : illegal token on right side of '::'
                            > > error C2059: syntax error : '::'[/color]
                            >
                            > The windows headers do you the favor of providing macros named 'min' and
                            > 'max' that can screw up your code. To get rid of 'em, add
                            >
                            > #define NOMINMAX
                            >
                            > to your stdafx.h file, before any #include directives.[/color]

                            Comment

                            Working...