Limits header file usage example

Source: Internet
Author: User

 

////////////////////////////////////////////////////////////////////// // // Compile options needed: /GX// // <filename> :  Numeric.cpp// // Variables and Functions:// //    has_denorm//    has_denorm_loss//    has_infinity//    has_quiet_NaN//    has_signaling_NaN//    is_bounded//    is_exact//    is_iec559//    is_integer//    is_modulo//    is_signed//    is_specialized//    tinyness_before//    traps//    round_style//    digits//    digits10//    max_exponent//    max_exponent10//    min_exponent//    min_exponent10//    radix;//    denorm_min()//    epsilon()//    infinity()//    max()//    min()//    quiet_ NaN()//    round_error()//    signaling_NaN()// // Written by Linda Koontz// of Microsoft Product Support Services,// Copyright (c) 1996 Microsoft Corporation. All rights reserved.////////////////////////////////////////////////////////////////////// /* Compile options needed: /GX*/ #include <iostream>#include <limits>#if _MSC_VER > 1020   // if VC++ version is > 4.2   using namespace std;  // std c++ libs implemented in std   #endifvoid main() {    cout << " 1 The minimum value for char is " <<        (int)numeric_limits<char>::min() << endl;    cout << " 2 The minimum value for int is " <<         numeric_limits<int>::min() << endl;    cout << " 3 The maximum value for char is " <<        (int)numeric_limits<char>::max() << endl;    cout << " 4 The maximum value for int is " <<        numeric_limits<int>::max() << endl;    cout << " 5 The number of bits to represent a char is " <<        numeric_limits<char>::digits << endl;    cout << " 6 The number of bits to represent an int is " <<        numeric_limits<int>::digits << endl;    cout <<" 7 The number of digits representable in base 10 for float is"         << numeric_limits<float>::digits10 << endl;    cout << " 8 Is a char signed?              " <<        numeric_limits<char>::is_signed << endl;    cout << " 9 Is an unsigned integer signed? " <<        numeric_limits<unsigned int>::is_signed << endl;    cout << "10 Is a integer an integer? " <<        numeric_limits<int>::is_integer << endl;    cout << "11 Is a float an integer?   " <<        numeric_limits<float>::is_integer << endl;    cout << "12 Is a integer exact? " <<        numeric_limits<int>::is_exact << endl;    cout << "13 Is a float  exact?  " <<        numeric_limits<float>::is_exact << endl;    cout << "14 The radix for float is            "  <<        numeric_limits<float>::radix << endl;    cout << "15 The epsilon for float is          " <<        numeric_limits<float>::epsilon() << endl;    cout << "16 The round error for float is      " <<        numeric_limits<float>::round_error() << endl;    cout << "17 The minimum exponent for float is " <<        numeric_limits<float>::min_exponent << endl;    cout << "18 The minimum exponent in base 10   " <<        numeric_limits<float>::min_exponent10 << endl;    cout << "19 The maximum exponent is           " <<        numeric_limits<float>::max_exponent << endl;    cout << "20 The maximum exponent in base 10   " <<        numeric_limits<float>::max_exponent10 << endl;    cout << "21 Can float represent positive infinity?  " <<        numeric_limits<float>::has_infinity << endl;    cout << "22 Can double represent positive infinity? " <<        numeric_limits<double>::has_infinity << endl;    cout << "23 Can int represent positive infinity? " <<        numeric_limits<int>::has_infinity << endl;    cout << "24 Can float represent a NaN?           " <<        numeric_limits<float>::has_quiet_NaN << endl;    cout << "25 Can float represent a signaling NaN? " <<        numeric_limits<float>::has_signaling_NaN << endl;    cout << "26 Does float allow denormalized values?   " <<        numeric_limits<float>::has_denorm << endl;    cout << "27 Does float detect denormalization loss? " <<        numeric_limits<float>::has_denorm_loss << endl;    cout << "28 Representation of positive infinity for float " <<        numeric_limits<float>::infinity() << endl;    cout << "29 Representation of quiet NaN for float         " <<        numeric_limits<float>::quiet_NaN() << endl;    cout << "30 Minimum denormalized number for float         " <<        numeric_limits<float>::denorm_min() << endl;    cout << "31 Minimum positive denormalized value for float " <<        numeric_limits<float>::denorm_min() << endl;    cout << "32 Does float adhere to IEC 559 standard?  " <<        numeric_limits<float>::is_iec559 << endl;    cout << "33 Is float bounded? " <<        numeric_limits<float>::is_bounded << endl;    cout << "34 Is float modulo?  " <<        numeric_limits<float>::is_modulo << endl;    cout << "35 Is int modulo?    " <<        numeric_limits<float>::is_modulo << endl;    cout << "36 Is trapping implemented for float?    " <<        numeric_limits<float>::traps << endl;    cout << "37 Is tinyness detected before rounding? " <<        numeric_limits<float>::tinyness_before << endl;    cout << "38 What is the rounding style for float? " <<        (int)numeric_limits<float>::round_style << endl;    cout << "39 What is the rounding style for int? " <<        (int)numeric_limits<int>::round_style << endl;    cout << "40 How does a float represent a signaling NaN? " <<        numeric_limits<float>::signaling_NaN() << endl;    cout << "41 Is int specialized? " <<        numeric_limits<float>::is_specialized << endl;}

Output: 1 The minimum value for char is -128 2 The minimum value for int is  -2147483648 3 The maximum value for char is 127 4 The maximum value for int is  2147483647 5 The number of bits to represent a char is 7 6 The number of bits to represent an int is 31 7 The number of digits representable in base 10 for float is 6 8 Is a char signed?              1 9 Is an unsigned integer signed? 010 Is an integer an integer? 111 Is a float an integer?   012 Is an integer exact? 113 Is a float exact?  014 The radix for float is            215 The epsilon for float is          1.19209e-00716 The round error for float is      0.517 The minimum exponent for float is -12518 The minimum exponent in base 10   -3719 The maximum exponent is           12820 The maximum exponent in base 10   3821 Can float represent positive infinity?  122 Can double represent positive infinity? 123 Can int represent positive infinity? 024 Can float represent a NaN?           125 Can float represent a signaling NaN? 126 Does float allow denormalized values?   127 Does float detect denormalization loss? 128 Representation of positive infinity for float 1.#INF29 Representation of quiet NaN for float         -1.#IND30 Minimum denormalized number for float         1.4013e-04531 Minimum positive denormalized value for float 1.4013e-04532 Does float adhere to IEC 559 standard?  133 Is float bounded? 134 Is float modulo?  035 Is int modulo?    036 Is trapping implemented for float?    137 Is tinyness detected before rounding? 138 What is the rounding style for float? 139 What is the rounding style for int? 040 How does a float represent a signaling NaN? -1.#INF41 Is int specialized? 1

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.