Results 1 to 5 of 5

Thread: [RESOLVED] Numeric Limits

  1. #1

    Thread Starter
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Resolved [RESOLVED] Numeric Limits

    Does c# have anything like std::numeric_limits in c++?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Numeric Limits

    You should perhaps explain what std::numeric_limits is or does, for those of us who know C# but not C++ (or at least haven't touched C++ for years ).
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: Numeric Limits

    It defines the max and min numbers for the machine.

    Code:
    const int     MaxInt    = (std::numeric_limits<int>::max)();
    const double  MaxDouble = (std::numeric_limits<double>::max)();
    const double  MinDouble = (std::numeric_limits<double>::min)();
    const float   MaxFloat  = (std::numeric_limits<float>::max)();
    const float   MinFloat  = (std::numeric_limits<float>::min)();

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Numeric Limits

    All the standard numeric types have static MinValue and MaxValue fields that return their minimum and maximum values:
    Code:
    const int     MaxInt    = int.MaxValue;
    const double  MaxDouble = double.MaxValue;
    const double  MinDouble = double.MinValue;
    const float   MaxFloat  = float.MaxValue;
    const float   MinFloat  = float.MinValue;
    etc. There's no point declaring your own constants though. Just use those fields as and when required.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: Numeric Limits

    Thanks! I knew it would be something easy, but I couldn't find it in my beginning c# book.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width