当前位置:网站首页>numeric_ Limits the range and related attributes of each data type learned
numeric_ Limits the range and related attributes of each data type learned
2022-07-28 03:53:00 【I washed my feet in Bangong Lake】
c++ There are many data types in , Each data type has a range and related attributes , such as short The type is 16, Range from -32768 To 32767,int The range is from -2147483648 To 2147483647 wait , Because the length of each data type is different , The scope is very different , So I didn't remember their specific scope , and numeric_limits You can view the range size of each data type , It is also convenient to use , Let's look at specific examples :
Member constants
[ static state ] | To identify std::numeric_limits Whether to specialize for this type ( Expose static member constants ) |
[ static state ] | Identify signed types ( Expose static member constants ) |
[ static state ] | Identify integer types ( Expose static member constants ) |
[ static state ] | Identify the type of accurate representation ( Expose static member constants ) |
[ static state ] | Discrimination can represent special values “ Positive infinity ” Floating point type of ( Expose static member constants ) |
[ static state ] | Discrimination can represent special values “ Quiet non number ”( NaN ) Floating point type of ( Expose static member constants ) |
[ static state ] | Discrimination can represent special values “ The number of non letters sent ”( NaN ) Floating point type of ( Expose static member constants ) |
[ static state ] | The informal style used to identify floating-point types ( Expose static member constants ) |
[ static state ] | Identify whether the floating-point type detects an irregular loss of precision , Not inaccurate results ( Expose static member constants ) |
[ static state ] | The rounding pattern used to identify the type ( Expose static member constants ) |
[ static state ] | To identify IEC 559/IEEE 754 Floating point type ( Expose static member constants ) |
[ static state ] | Identify the types that represent finite value sets ( Expose static member constants ) |
[ static state ] | Identify the type of overflow handled by modular arithmetic ( Expose static member constants ) |
[ static state ] | Capable of being represented unchanged radix digit ( Expose static member constants ) |
[ static state ] | The number of decimal digits that can be represented unchanged ( Expose static member constants ) |
[ static state ] (C++11) | The number of decimal digits required to distinguish all values of this type ( Expose static member constants ) |
[ static state ] | The base or integer base used for the representation of a given type ( Expose static member constants ) |
[ static state ] | The power of the base is the smallest negative number plus one of the legal normal floating-point values ( Expose static member constants ) |
[ static state ] | 10 The power of this number is the minimum negative number of the legal normal floating-point value ( Expose static member constants ) |
[ static state ] | The power of the number of times at the bottom is the maximum integer of the legal finite floating-point value plus one ( Expose static member constants ) |
[ static state ] | 10 The power of this number is the largest integer of a legal finite floating-point value ( Expose static member constants ) |
[ static state ] | Identify the types that may cause traps in arithmetic operations ( Expose static member constants ) |
[ static state ] | Identify and detect whether the floating-point type is irregular before rounding ( Expose static member constants ) |
Member functions
[ static state ] | Returns the minimum finite value of a given type ( Expose static member functions ) |
[ static state ] (C++11) | Returns the lowest finite value of a given type ( Expose static member functions ) |
[ static state ] | Returns the maximum finite value of a given type ( Expose static member functions ) |
[ static state ] | return 1.0 The difference from the next representable value of a given type ( Expose static member functions ) |
[ static state ] | Returns the maximum rounding error for a given floating-point type ( Expose static member functions ) |
[ static state ] | Returns a positive infinity value of a given type ( Expose static member functions ) |
[ static state ] | Returns the value of the given floating-point type NaN value ( Expose static member functions ) |
[ static state ] | Returns the sending of a given floating-point type NaN ( Expose static member functions ) |
[ static state ] | Returns the minimum positive non normal value of a given floating-point type ( Expose static member functions ) |
Code example :
#include <iostream>
#include <limits>
using namespace std;
int main()
{
cout << std::boolalpha;
std::cout << "type\t\t│ lowest()\t│ min()\t\t│ max()\n";
std::cout << "bool\t\t│ " << std::numeric_limits<bool>::lowest() << "\t\t│ "
<< std::numeric_limits<bool>::min() << "\t\t│ "
<< std::numeric_limits<bool>::max() << '\n';
std::cout << "char\t\t│ " << std::numeric_limits<char>::lowest() << "\t\t│ "
<< std::numeric_limits<char>::min() << "\t\t│ "
<< std::numeric_limits<char>::max() << '\n';
std::cout << "float\t\t│ " << std::numeric_limits<float>::lowest() << "\t│ "
<< std::numeric_limits<float>::min() << "\t│ "
<< std::numeric_limits<float>::max() << '\n';
std::cout << "double\t\t│ " << std::numeric_limits<double>::lowest() << "\t│ "
<< std::numeric_limits<double>::min() << "\t│ "
<< std::numeric_limits<double>::max() << '\n';
std::cout << "wchar_t\t\t│ " << std::numeric_limits<wchar_t>::lowest() << "\t\t│ "
<< std::numeric_limits<wchar_t>::min() << "\t\t│ "
<< std::numeric_limits<wchar_t>::max() << '\n';
std::cout << "char16_t\t│ " << std::numeric_limits<char16_t>::lowest() << "\t\t│ "
<< std::numeric_limits<char16_t>::min() << "\t\t│ "
<< std::numeric_limits<char16_t>::max() << '\n';
std::cout << "char32_t\t│ " << std::numeric_limits<char32_t>::lowest() << "\t\t│ "
<< std::numeric_limits<char32_t>::min() << "\t\t│ "
<< std::numeric_limits<char32_t>::max() << '\n';
std::cout << "short\t\t│ " << std::numeric_limits<short>::lowest() << "\t│ "
<< std::numeric_limits<short>::min() << "\t│ "
<< std::numeric_limits<short>::max() << '\n';
std::cout << "signed short\t│ " << std::numeric_limits<signed short>::lowest() << "\t│ "
<< std::numeric_limits<signed short>::min() << "\t│ "
<< std::numeric_limits<signed short>::max() << '\n';
std::cout << "unsigned short\t│ " << std::numeric_limits<unsigned short>::lowest() << "\t\t│ "
<< std::numeric_limits<unsigned short>::min() << "\t\t│ "
<< std::numeric_limits<unsigned short>::max() << '\n';
std::cout << "int\t\t│ " << std::numeric_limits<int>::lowest() << "\t│ "
<< std::numeric_limits<int>::min() << "\t│ "
<< std::numeric_limits<int>::max() << '\n';
std::cout << "signed int\t│ " << std::numeric_limits<signed int>::lowest() << "\t│ "
<< std::numeric_limits<signed int>::min() << "\t│ "
<< std::numeric_limits<signed int>::max() << '\n';
std::cout << "unsigned int\t│ " << std::numeric_limits<unsigned int>::lowest() << "\t\t│ "
<< std::numeric_limits<unsigned int>::min() << "\t\t│ "
<< std::numeric_limits<unsigned int>::max() << '\n';
std::cout << "long\t\t│ " << std::numeric_limits<long>::lowest() << "\t│ "
<< std::numeric_limits<long>::min() << "\t│ "
<< std::numeric_limits<long>::max() << '\n';
std::cout << "signed long\t│ " << std::numeric_limits<signed long>::lowest() << "\t│ "
<< std::numeric_limits<signed long>::min() << "\t│ "
<< std::numeric_limits<signed long>::max() << '\n';
std::cout << "unsigned long\t│ " << std::numeric_limits<unsigned long>::lowest() << "\t\t│ "
<< std::numeric_limits<unsigned long>::min() << "\t\t│ "
<< std::numeric_limits<unsigned long>::max() << '\n';
std::cout << "long long\t│ " << std::numeric_limits<long long>::lowest() << "\t\t│ "
<< std::numeric_limits<long long>::min() << "\t\t│ "
<< std::numeric_limits<long long>::max() << '\n';
std::cout << "signed long long│ " << std::numeric_limits<signed long long>::lowest() << "\t\t│ "
<< std::numeric_limits<signed long long>::min() << "\t\t│ "
<< std::numeric_limits<signed long long>::max() << '\n';
std::cout << "unsigned long long│ " << std::numeric_limits<unsigned long long>::lowest() << "\t\t│ "
<< std::numeric_limits<unsigned long long>::min() << "\t\t│ "
<< std::numeric_limits<unsigned long long>::max() << '\n';
cout << "Hello World!" << endl;
return 0;
}
Running results :

Reference resources :
std::numeric_limits - cppreference.com
https://cplusplus.com/reference/limits/numeric_limits/
边栏推荐
- AI chief architect 12 AICA Baidu OCR vertical large-scale landing practice
- Fourier series
- 【P4】解决本地文件修改与库文件间的冲突问题
- leetcode刷题:动态规划09(最后一块石头的重量 II)
- LeetCode 0140. 单词拆分 II
- 【原型与原型链】初识原型与原型链~
- 【OPENVX】对象基本使用之vx_convolution
- 递归和非递归分别实现求第n个斐波那契数
- Lightpicture - exquisite drawing bed system
- Embedded development: tips and techniques -- the best practice of defensive programming with C
猜你喜欢

MySQL是怎么保证高可用的

Prefix-Tuning: Optimizing Continuous Prompts for Generation

【原型与原型链】初识原型与原型链~

What is interface testing and its testing process

Advanced Mathematics (Seventh Edition) Tongji University exercises 3-6 personal solutions

Build an "industrial brain" and improve the park's operation, management and service capabilities with "digitalization"!

Leetcode skimming: dynamic programming 08 (segmentation and subsets)

测试用例管理工具

Monotonic stack - 739. Daily temperature

Summary of static blog building tools
随机推荐
R notes mice
Dynamic programming - 509. Fibonacci number
LeetCode 0141. 环形链表 - 三种方法解决
Collection | 0 basic open source data visualization platform flyfish large screen development guide
Dynamic planning - 1049. Weight of the last stone II
input 上传文件并回显 FileReader并限制选择文件时的类型
AI chief architect 12 AICA Baidu OCR vertical large-scale landing practice
LightPicture – 精致图床系统
Ch340 RTS DTR pin programming drives OLED
conda虚拟环境总结与解读
TypeError: ufunc ‘bitwise_and‘ not supported for the input types, and the inputs could not be safely
[prototype and prototype chain] get to know prototype and prototype chain~
Interview essential skills: SQL query special training!
Super easy to use PC end long screenshot tool
Leetcode brush question: dynamic planning 09 (weight of the last stone II)
Responsive high-end website template source code Gallery material resource download platform source code
Embedded development: tips and techniques -- the best practice of defensive programming with C
Implementation of online rental system based on SSM
LeetCode_ 409_ Longest palindrome string
Recursion and non recursion are used to calculate the nth Fibonacci number respectively