2 Replies - 1820 Views - Last Post: 11 February 2012 - 02:53 AM

#1 Xing   User is offline

  • D.I.C Addict
  • member icon

Reputation: 19
  • View blog
  • Posts: 725
  • Joined: 22-July 06

Finding max & min using numeric_limits

Posted 02 October 2007 - 01:39 AM

Description: Primitive types, max and min values
#include <iostream>
#include <limits>

using namespace std;
int main()
{

    //print maximum of various types

    cout << "Max value for short : " << numeric_limits<short>::max() << endl;
    cout << "Max value for int : " << numeric_limits<int>::max() << endl;
    cout << "Max value for long : " << numeric_limits<long>::max() << endl;
    cout << "Max value for float : " << numeric_limits<float>::max() << endl;
    cout << "Max value for double : " << numeric_limits<double>::max() << endl;

    //print minimum of various types

    cout << "Min value for short : " << numeric_limits<short>::min() << endl;
    cout << "Max value for int : " << numeric_limits<int>::min() << endl;
    cout << "Max value for long : " << numeric_limits<long>::min() << endl;
    cout << "Max value for float : " << numeric_limits<float>::min() << endl;
    cout << "Max value for double : " << numeric_limits<double>::min() << endl;

}



Is This A Good Question/Topic? 0
  • +

Replies To: Finding max & min using numeric_limits

#2 thehaanchen   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 23-September 09

Re: Finding max & min using numeric_limits

Posted 23 September 2009 - 05:18 AM

Sorry I cannot rate this highly.. Type errors - 'Max' printed out output then it should have been 'Min' and Min Double is -numeric_limits::max() NOT numeric_limits::min() which is the smallest value above zero which can be expressed as a double
Was This Post Helpful? 0
  • +
  • -

#3 Karel-Lodewijk   User is offline

  • D.I.C Addict
  • member icon

Reputation: 454
  • View blog
  • Posts: 864
  • Joined: 17-March 11

Re: Finding max & min using numeric_limits

Posted 11 February 2012 - 02:53 AM

I agree with that Max is printed wrong but numeric_limits::min() does print the smallest negative value also for floating point values.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1