[Algorithm I ~ IV (C ++ implementation)] exercise 3.1: Find the maximum and minimum values that int float double can represent.

Source: Internet
Author: User

Contains the header file limits. h

Numeric_limits <type >:: max (): calculates the maximum value (min () of a data type to the minimum value)

The minimum value of a floating point number is the smallest positive value that can be expressed.

cout.setf( ios::showbase|ios::uppercase );        cout << "int min = " << numeric_limits<int>::min() << "---" << hex << numeric_limits<int>::min() << endl;        cout.unsetf( ios::hex );        cout << "int max = " << numeric_limits<int>::max() << "---" << hex << numeric_limits<int>::max() << endl;        cout << endl;        cout.unsetf( ios::hex );        cout << "lont int min = " << numeric_limits< long int>::min() << "---" << hex << numeric_limits<long int>::min() << endl;        cout.unsetf( ios::hex );        cout << "long int max = " << numeric_limits<long int>::max() << "---" << hex << numeric_limits<long int>::max() << endl;        cout << endl;        cout.unsetf( ios::hex );        cout << "short int min = " << numeric_limits<short int>::min() << "---" << hex                 << numeric_limits<short int>::min() << endl;        cout.unsetf( ios::hex );        cout << "short int max = " << numeric_limits<short int>::max() << "---" << hex                 << numeric_limits<short int>::max() << endl;        cout << endl;        cout.unsetf( ios::hex );        cout << "float min = " << numeric_limits<float>::min() << "---" << hex << numeric_limits<float>::min() << endl;        cout << "float max = " << numeric_limits<float>::max() << "---" << hex << numeric_limits<float>::max() << endl;        cout << endl;        cout << "double min = " << numeric_limits<double>::min() << "---" << hex << numeric_limits<double>::min() << endl;        cout << "double max = " << numeric_limits<double>::max() << "---" << hex << numeric_limits<double>::max() << endl;        cout << endl;

Result:

int min = -2147483648---0X80000000int max = 2147483647---0X7FFFFFFFlont int min = -2147483648---0X80000000long int max = 2147483647---0X7FFFFFFFshort int min = -32768---0X8000short int max = 32767---0X7FFFfloat min = 1.17549E-38---1.17549E-38float max = 3.40282E+38---3.40282E+38double min = 2.22507E-308---2.22507E-308double max = 1.79769E+308---1.79769E+308

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.