Kelas numeric_limits
Templat kelas menjelaskan properti aritmatika dari jenis numerik bawaan.
Sintaks
template <class Type>
class numeric_limits
Parameter
Jenis
Jenis data elemen dasar yang propertinya sedang diuji atau dikueri atau diatur. Jenis juga dapat dideklarasikan const
, , volatile
atau const volatile
.
Keterangan
Header menentukan spesialisasi eksplisit untuk jenis wchar_t
, , , bool
, signed char
char
, unsigned short
short
unsigned char
, int
, long
unsigned long
unsigned int
float
, , double
, , long double
, , long long
, , unsigned long long
, , char16_t
dan .char32_t
Untuk spesialisasi eksplisit ini, anggota numeric_limits::is_specialized adalah true
, dan semua anggota yang relevan memiliki nilai yang bermakna. Program ini dapat menyediakan spesialisasi eksplisit tambahan. Sebagian besar fungsi anggota kelas menjelaskan atau menguji kemungkinan implementasi .float
Untuk spesialisasi arbitrer, tidak ada anggota yang memiliki nilai yang bermakna. Objek anggota yang tidak memiliki nilai yang bermakna menyimpan nol (atau false
) dan fungsi anggota yang tidak mengembalikan nilai yang bermakna mengembalikan Type(0)
.
Fungsi dan Konstanta Statis
Nama | Deskripsi |
---|---|
denorm_min | Mengembalikan nilai denormalisasi nonzero terkecil. |
Digit | Mengembalikan jumlah digit radiks yang dapat diwakili tipe tanpa kehilangan presisi. |
digits10 | Mengembalikan jumlah digit desimal yang dapat diwakili tipe tanpa kehilangan presisi. |
Epsilon | Mengembalikan selisih antara 1 dan nilai terkecil yang lebih besar dari 1 yang dapat diwakili oleh tipe data. |
has_denorm | Menguji apakah jenis memungkinkan nilai denormalisasi. |
has_denorm_loss | Menguji apakah hilangnya akurasi terdeteksi sebagai kehilangan denormalisasi alih-alih sebagai hasil yang tidak pasti. |
has_infinity | Menguji apakah jenis memiliki representasi untuk infinitas positif. |
has_quiet_NaN | Menguji apakah jenis memiliki representasi untuk senyap bukan angka (NAN), yang bukan sinyal. |
has_signaling_NaN | Menguji apakah jenis memiliki representasi untuk memberi sinyal bukan angka (NAN). |
Infinity | Representasi untuk tak terbatas positif untuk jenis, jika tersedia. |
is_bounded | Menguji apakah kumpulan nilai yang mungkin diwakili jenis terbatas. |
is_exact | Pengujian jika perhitungan yang dilakukan pada jenis bebas dari kesalahan pembulatan. |
is_iec559 | Menguji apakah jenis sesuai dengan standar IEC 559. |
is_integer | Menguji apakah jenis memiliki representasi bilangan bulat. |
is_modulo | Menguji apakah jenis memiliki representasi modulo. |
is_signed | Menguji apakah jenis memiliki representasi yang ditandatangani. |
is_specialized | Menguji apakah jenis memiliki spesialisasi eksplisit yang ditentukan dalam templat numeric_limits kelas . |
Terendah | Mengembalikan nilai terbatas yang paling negatif. |
max | Mengembalikan nilai batas maksimum untuk suatu jenis. |
max_digits10 | Mengembalikan jumlah digit desimal yang diperlukan untuk memastikan bahwa dua nilai yang berbeda dari jenis memiliki representasi desimal yang berbeda. |
max_exponent | Mengembalikan eksponen integral positif maksimum yang dapat diwakili oleh jenis floating-point sebagai nilai terbatas saat basis radix dinaikkan ke daya tersebut. |
max_exponent10 | Mengembalikan eksponen integral positif maksimum yang dapat diwakili oleh jenis floating-point sebagai nilai terbatas saat basis sepuluh dinaikkan ke daya tersebut. |
min | Mengembalikan nilai minimum yang dinormalisasi untuk suatu jenis. |
min_exponent | Mengembalikan eksponen integral negatif maksimum yang dapat diwakili oleh jenis floating-point sebagai nilai terbatas saat basis radix dinaikkan ke daya tersebut. |
min_exponent10 | Mengembalikan eksponen integral negatif maksimum yang dapat diwakili oleh jenis floating-point sebagai nilai terbatas saat basis sepuluh dinaikkan ke daya tersebut. |
quiet_NaN | Mengembalikan representasi dari sepi bukan angka (NAN) untuk jenis tersebut. |
Radix | Mengembalikan basis integral, yang disebut sebagai radix, yang digunakan untuk representasi jenis. |
round_error | Mengembalikan kesalahan pembulatan maksimum untuk jenis tersebut. |
round_style | Mengembalikan nilai yang menjelaskan berbagai metode yang dapat dipilih implementasi untuk membulatkan nilai floating-point ke nilai bilangan bulat. |
signaling_NaN | Mengembalikan representasi sinyal bukan angka (NAN) untuk jenis tersebut. |
tinyness_before | Menguji apakah jenis dapat menentukan bahwa nilai terlalu kecil untuk diwakili sebagai nilai yang dinormalisasi sebelum membulatkannya. |
Perangkap | Menguji apakah trapping yang melaporkan pengecualian aritmatika diimplementasikan untuk jenis. |
denorm_min
Mengembalikan nilai denormalisasi nonzero terkecil.
static constexpr Type denorm_min() throw();
Tampilkan Nilai
Nilai denormalisasi nonzero terkecil.
Keterangan
long double
sama seperti double
untuk pengkompilasi C++.
Fungsi mengembalikan nilai minimum untuk jenis , yang sama dengan min jika has_denorm tidak sama dengan denorm_present
.
Contoh
// numeric_limits_denorm_min.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "The smallest nonzero denormalized value" << endl
<< "for float objects is: "
<< numeric_limits<float>::denorm_min( ) << endl;
cout << "The smallest nonzero denormalized value" << endl
<< "for double objects is: "
<< numeric_limits<double>::denorm_min( ) << endl;
cout << "The smallest nonzero denormalized value" << endl
<< "for long double objects is: "
<< numeric_limits<long double>::denorm_min( ) << endl;
// A smaller value will round to zero
cout << numeric_limits<float>::denorm_min( )/2 <<endl;
cout << numeric_limits<double>::denorm_min( )/2 <<endl;
cout << numeric_limits<long double>::denorm_min( )/2 <<endl;
}
The smallest nonzero denormalized value
for float objects is: 1.4013e-045
The smallest nonzero denormalized value
for double objects is: 4.94066e-324
The smallest nonzero denormalized value
for long double objects is: 4.94066e-324
0
0
0
Digit
Mengembalikan jumlah digit radiks yang dapat diwakili tipe tanpa kehilangan presisi.
static constexpr int digits = 0;
Tampilkan Nilai
Jumlah digit radiks yang dapat diwakili oleh jenis tanpa kehilangan presisi.
Keterangan
Anggota menyimpan jumlah digit radix yang dapat diwakili jenis tanpa perubahan, yang merupakan jumlah bit selain bit tanda apa pun untuk jenis bilangan bulat yang telah ditentukan sebelumnya, atau jumlah digit mantissa untuk jenis titik mengambang yang telah ditentukan sebelumnya.
Contoh
// numeric_limits_digits_min.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<float>::digits <<endl;
cout << numeric_limits<double>::digits <<endl;
cout << numeric_limits<long double>::digits <<endl;
cout << numeric_limits<int>::digits <<endl;
cout << numeric_limits<__int64>::digits <<endl;
}
24
53
53
31
63
digits10
Mengembalikan jumlah digit desimal yang dapat diwakili tipe tanpa kehilangan presisi.
static constexpr int digits10 = 0;
Tampilkan Nilai
Jumlah digit desimal yang dapat diwakili oleh jenis tanpa kehilangan presisi.
Contoh
// numeric_limits_digits10.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<float>::digits10 <<endl;
cout << numeric_limits<double>::digits10 <<endl;
cout << numeric_limits<long double>::digits10 <<endl;
cout << numeric_limits<int>::digits10 <<endl;
cout << numeric_limits<__int64>::digits10 <<endl;
float f = (float)99999999;
cout.precision ( 10 );
cout << "The float is; " << f << endl;
}
6
15
15
9
18
The float is; 100000000
Epsilon
Fungsi mengembalikan selisih antara 1 dan nilai terkecil yang lebih besar dari 1 yang dapat diwakili untuk jenis data.
static constexpr Type epsilon() throw();
Tampilkan Nilai
Perbedaan antara 1 dan nilai terkecil yang lebih besar dari 1 yang dapat diwakili untuk jenis data.
Keterangan
Nilainya FLT_EPSILON untuk jenis float
. epsilon
untuk jenis adalah angka floating-point positif terkecil N sehingga Nepsilon
+ + N dapat diwakili.
Contoh
// numeric_limits_epsilon.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "The difference between 1 and the smallest "
<< "value greater than 1" << endl
<< "for float objects is: "
<< numeric_limits<float>::epsilon( ) << endl;
cout << "The difference between 1 and the smallest "
<< "value greater than 1" << endl
<< "for double objects is: "
<< numeric_limits<double>::epsilon( ) << endl;
cout << "The difference between 1 and the smallest "
<< "value greater than 1" << endl
<< "for long double objects is: "
<< numeric_limits<long double>::epsilon( ) << endl;
}
The difference between 1 and the smallest value greater than 1
for float objects is: 1.19209e-007
The difference between 1 and the smallest value greater than 1
for double objects is: 2.22045e-016
The difference between 1 and the smallest value greater than 1
for long double objects is: 2.22045e-016
has_denorm
Menguji apakah jenis memungkinkan nilai denormalisasi.
static constexpr float_denorm_style has_denorm = denorm_absent;
Tampilkan Nilai
Nilai enumerasi jenis const float_denorm_style
, menunjukkan apakah jenis memungkinkan nilai denormalisasi.
Keterangan
Anggota menyimpan denorm_present
untuk jenis floating-point yang memiliki nilai denormalisasi, secara efektif merupakan jumlah variabel bit eksponen.
Contoh
// numeric_limits_has_denorm.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float objects allow denormalized values: "
<< numeric_limits<float>::has_denorm
<< endl;
cout << "Whether double objects allow denormalized values: "
<< numeric_limits<double>::has_denorm
<< endl;
cout << "Whether long int objects allow denormalized values: "
<< numeric_limits<long int>::has_denorm
<< endl;
}
Whether float objects allow denormalized values: 1
Whether double objects allow denormalized values: 1
Whether long int objects allow denormalized values: 0
has_denorm_loss
Menguji apakah hilangnya akurasi terdeteksi sebagai kehilangan denormalisasi alih-alih sebagai hasil yang tidak pasti.
static constexpr bool has_denorm_loss = false;
Tampilkan Nilai
true
jika hilangnya akurasi terdeteksi sebagai kehilangan denormalisasi; false
jika tidak.
Keterangan
Anggota menyimpan true untuk jenis yang menentukan apakah nilai telah kehilangan akurasi karena dikirimkan sebagai hasil yang didenormalisasi (terlalu kecil untuk direpresentasikan sebagai nilai yang dinormalisasi) atau karena nilai tidak tepat (tidak sama dengan hasil yang tidak tunduk pada batasan rentang eksponen dan presisi), opsi dengan representasi titik mengambang IEC 559 yang dapat memengaruhi beberapa hasil.
Contoh
// numeric_limits_has_denorm_loss.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float objects can detect denormalized loss: "
<< numeric_limits<float>::has_denorm_loss
<< endl;
cout << "Whether double objects can detect denormalized loss: "
<< numeric_limits<double>::has_denorm_loss
<< endl;
cout << "Whether long int objects can detect denormalized loss: "
<< numeric_limits<long int>::has_denorm_loss
<< endl;
}
Whether float objects can detect denormalized loss: 1
Whether double objects can detect denormalized loss: 1
Whether long int objects can detect denormalized loss: 0
has_infinity
Menguji apakah jenis memiliki representasi untuk infinitas positif.
static constexpr bool has_infinity = false;
Tampilkan Nilai
true
jika jenis memiliki representasi untuk infinity positif; false
jika tidak.
Keterangan
Anggota mengembalikan true
jika is_iec559 adalah true
.
Contoh
// numeric_limits_has_infinity.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float objects have infinity: "
<< numeric_limits<float>::has_infinity
<< endl;
cout << "Whether double objects have infinity: "
<< numeric_limits<double>::has_infinity
<< endl;
cout << "Whether long int objects have infinity: "
<< numeric_limits<long int>::has_infinity
<< endl;
}
Whether float objects have infinity: 1
Whether double objects have infinity: 1
Whether long int objects have infinity: 0
has_quiet_NaN
Menguji apakah jenis memiliki representasi untuk senyap bukan angka (NAN), yang tidak sejajar.
static constexpr bool has_quiet_NaN = false;
Tampilkan Nilai
true
jika jenis memiliki representasi untuk NAN yang tenang; false
jika tidak.
Keterangan
NAN yang tenang adalah pengodean untuk bukan angka, yang tidak menandakan kehadirannya dalam ekspresi. Nilai yang dikembalikan adalah true
jika is_iec559 benar.
Contoh
// numeric_limits_has_quiet_nan.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float objects have quiet_NaN: "
<< numeric_limits<float>::has_quiet_NaN
<< endl;
cout << "Whether double objects have quiet_NaN: "
<< numeric_limits<double>::has_quiet_NaN
<< endl;
cout << "Whether long int objects have quiet_NaN: "
<< numeric_limits<long int>::has_quiet_NaN
<< endl;
}
Whether float objects have quiet_NaN: 1
Whether double objects have quiet_NaN: 1
Whether long int objects have quiet_NaN: 0
has_signaling_NaN
Menguji apakah jenis memiliki representasi untuk memberi sinyal bukan angka (NAN).
static constexpr bool has_signaling_NaN = false;
Tampilkan Nilai
true
jika jenis memiliki representasi untuk SINYAL NAN; false
jika tidak.
Keterangan
NAN sinyal adalah pengodean untuk bukan angka, yang menandakan kehadirannya dalam ekspresi. Nilai yang dikembalikan adalah true
jika is_iec559 benar.
Contoh
// numeric_limits_has_signaling_nan.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float objects have a signaling_NaN: "
<< numeric_limits<float>::has_signaling_NaN
<< endl;
cout << "Whether double objects have a signaling_NaN: "
<< numeric_limits<double>::has_signaling_NaN
<< endl;
cout << "Whether long int objects have a signaling_NaN: "
<< numeric_limits<long int>::has_signaling_NaN
<< endl;
}
Whether float objects have a signaling_NaN: 1
Whether double objects have a signaling_NaN: 1
Whether long int objects have a signaling_NaN: 0
Infinity
Representasi tak terbatas positif untuk jenis, jika tersedia.
static constexpr Type infinity() throw();
Tampilkan Nilai
Representasi tak terbatas positif untuk jenis, jika tersedia.
Keterangan
Nilai yang dikembalikan bermakna hanya jika has_infinity adalah true
.
Contoh
// numeric_limits_infinity.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << numeric_limits<float>::has_infinity <<endl;
cout << numeric_limits<double>::has_infinity<<endl;
cout << numeric_limits<long double>::has_infinity <<endl;
cout << numeric_limits<int>::has_infinity <<endl;
cout << numeric_limits<__int64>::has_infinity <<endl;
cout << "The representation of infinity for type float is: "
<< numeric_limits<float>::infinity( ) <<endl;
cout << "The representation of infinity for type double is: "
<< numeric_limits<double>::infinity( ) <<endl;
cout << "The representation of infinity for type long double is: "
<< numeric_limits<long double>::infinity( ) <<endl;
}
1
1
1
0
0
The representation of infinity for type float is: inf
The representation of infinity for type double is: inf
The representation of infinity for type long double is: inf
is_bounded
Menguji apakah kumpulan nilai yang mungkin diwakili jenis terbatas.
static constexpr bool is_bounded = false;
Tampilkan Nilai
true
jika jenis memiliki sekumpulan nilai yang dapat direpresentasikan yang terikat; false
jika tidak.
Keterangan
Semua jenis yang telah ditentukan sebelumnya memiliki sekumpulan nilai yang dapat diwakili dan mengembalikan true
.
Contoh
// numeric_limits_is_bounded.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float objects have bounded set "
<< "of representable values: "
<< numeric_limits<float>::is_bounded
<< endl;
cout << "Whether double objects have bounded set "
<< "of representable values: "
<< numeric_limits<double>::is_bounded
<< endl;
cout << "Whether long int objects have bounded set "
<< "of representable values: "
<< numeric_limits<long int>::is_bounded
<< endl;
cout << "Whether unsigned char objects have bounded set "
<< "of representable values: "
<< numeric_limits<unsigned char>::is_bounded
<< endl;
}
Whether float objects have bounded set of representable values: 1
Whether double objects have bounded set of representable values: 1
Whether long int objects have bounded set of representable values: 1
Whether unsigned char objects have bounded set of representable values: 1
is_exact
Pengujian jika perhitungan yang dilakukan pada jenis bebas dari kesalahan pembulatan.
static constexpr bool is_exact = false;
Tampilkan Nilai
true
jika perhitungan bebas dari kesalahan pembulatan; false
jika tidak.
Keterangan
Semua jenis bilangan bulat yang telah ditentukan sebelumnya memiliki representasi yang tepat untuk nilainya dan mengembalikan false
. Representasi tetap atau rasional juga dianggap tepat, tetapi representasi floating-point tidak.
Contoh
// numeric_limits_is_exact.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float objects have calculations "
<< "free of rounding errors: "
<< numeric_limits<float>::is_exact
<< endl;
cout << "Whether double objects have calculations "
<< "free of rounding errors: "
<< numeric_limits<double>::is_exact
<< endl;
cout << "Whether long int objects have calculations "
<< "free of rounding errors: "
<< numeric_limits<long int>::is_exact
<< endl;
cout << "Whether unsigned char objects have calculations "
<< "free of rounding errors: "
<< numeric_limits<unsigned char>::is_exact
<< endl;
}
Whether float objects have calculations free of rounding errors: 0
Whether double objects have calculations free of rounding errors: 0
Whether long int objects have calculations free of rounding errors: 1
Whether unsigned char objects have calculations free of rounding errors: 1
is_iec559
Menguji apakah jenis sesuai dengan standar IEC 559.
static constexpr bool is_iec559 = false;
Tampilkan Nilai
true
jika jenisnya sesuai dengan standar IEC 559; false
jika tidak.
Keterangan
IEC 559 adalah standar internasional untuk mewakili nilai floating-point dan juga dikenal sebagai IEEE 754 di AS.
Contoh
// numeric_limits_is_iec559.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float objects conform to iec559 standards: "
<< numeric_limits<float>::is_iec559
<< endl;
cout << "Whether double objects conform to iec559 standards: "
<< numeric_limits<double>::is_iec559
<< endl;
cout << "Whether int objects conform to iec559 standards: "
<< numeric_limits<int>::is_iec559
<< endl;
cout << "Whether unsigned char objects conform to iec559 standards: "
<< numeric_limits<unsigned char>::is_iec559
<< endl;
}
Whether float objects conform to iec559 standards: 1
Whether double objects conform to iec559 standards: 1
Whether int objects conform to iec559 standards: 0
Whether unsigned char objects conform to iec559 standards: 0
is_integer
Menguji apakah jenis memiliki representasi bilangan bulat.
static constexpr bool is_integer = false;
Tampilkan Nilai
true
jika jenis memiliki representasi bilangan bulat; false
jika tidak.
Keterangan
Semua jenis bilangan bulat yang telah ditentukan sebelumnya memiliki representasi bilangan bulat.
Contoh
// numeric_limits_is_integer.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float objects have an integral representation: "
<< numeric_limits<float>::is_integer
<< endl;
cout << "Whether double objects have an integral representation: "
<< numeric_limits<double>::is_integer
<< endl;
cout << "Whether int objects have an integral representation: "
<< numeric_limits<int>::is_integer
<< endl;
cout << "Whether unsigned char objects have an integral representation: "
<< numeric_limits<unsigned char>::is_integer
<< endl;
}
Whether float objects have an integral representation: 0
Whether double objects have an integral representation: 0
Whether int objects have an integral representation: 1
Whether unsigned char objects have an integral representation: 1
is_modulo
Menguji apakah jenis memiliki representasi modulo.
static constexpr bool is_modulo = false;
Tampilkan Nilai
true
jika jenis memiliki representasi modulo; false
jika tidak.
Keterangan
Representasi modulo adalah representasi di mana semua hasil dikurangi modulo beberapa nilai. Semua jenis bilangan bulat yang tidak ditandatangani sebelumnya memiliki representasi modulo.
Contoh
// numeric_limits_is_modulo.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float objects have a modulo representation: "
<< numeric_limits<float>::is_modulo
<< endl;
cout << "Whether double objects have a modulo representation: "
<< numeric_limits<double>::is_modulo
<< endl;
cout << "Whether signed char objects have a modulo representation: "
<< numeric_limits<signed char>::is_modulo
<< endl;
cout << "Whether unsigned char objects have a modulo representation: "
<< numeric_limits<unsigned char>::is_modulo
<< endl;
}
Whether float objects have a modulo representation: 0
Whether double objects have a modulo representation: 0
Whether signed char objects have a modulo representation: 1
Whether unsigned char objects have a modulo representation: 1
is_signed
Menguji apakah jenis memiliki representasi yang ditandatangani.
static constexpr bool is_signed = false;
Tampilkan Nilai
true
jika jenis memiliki representasi yang ditandatangani; false
jika tidak.
Keterangan
Anggota menyimpan true untuk jenis yang memiliki representasi yang ditandatangani, yang merupakan kasus untuk semua jenis floating-point dan bilangan bulat yang telah ditentukan sebelumnya.
Contoh
// numeric_limits_is_signaled.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float objects have a signed representation: "
<< numeric_limits<float>::is_signed
<< endl;
cout << "Whether double objects have a signed representation: "
<< numeric_limits<double>::is_signed
<< endl;
cout << "Whether signed char objects have a signed representation: "
<< numeric_limits<signed char>::is_signed
<< endl;
cout << "Whether unsigned char objects have a signed representation: "
<< numeric_limits<unsigned char>::is_signed
<< endl;
}
Whether float objects have a signed representation: 1
Whether double objects have a signed representation: 1
Whether signed char objects have a signed representation: 1
Whether unsigned char objects have a signed representation: 0
is_specialized
Menguji apakah jenis memiliki spesialisasi eksplisit yang ditentukan dalam templat numeric_limits
kelas .
static constexpr bool is_specialized = false;
Tampilkan Nilai
true
jika jenis memiliki spesialisasi eksplisit yang ditentukan dalam templat kelas; false
jika tidak.
Keterangan
Semua jenis skalar selain pointer memiliki spesialisasi eksplisit yang ditentukan untuk templat numeric_limits
kelas .
Contoh
// numeric_limits_is_specialized.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float objects have an explicit "
<< "specialization in the class: "
<< numeric_limits<float>::is_specialized
<< endl;
cout << "Whether float* objects have an explicit "
<< "specialization in the class: "
<< numeric_limits<float*>::is_specialized
<< endl;
cout << "Whether int objects have an explicit "
<< "specialization in the class: "
<< numeric_limits<int>::is_specialized
<< endl;
cout << "Whether int* objects have an explicit "
<< "specialization in the class: "
<< numeric_limits<int*>::is_specialized
<< endl;
}
Whether float objects have an explicit specialization in the class: 1
Whether float* objects have an explicit specialization in the class: 0
Whether int objects have an explicit specialization in the class: 1
Whether int* objects have an explicit specialization in the class: 0
terendah
Mengembalikan nilai terbatas yang paling negatif.
static constexpr Type lowest() throw();
Tampilkan Nilai
Mengembalikan nilai terbatas yang paling negatif.
Keterangan
Mengembalikan nilai terbatas paling negatif untuk jenis (yang biasanya min()
untuk jenis bilangan bulat dan -max()
untuk jenis floating-point). Nilai yang dikembalikan bermakna jika is_bounded
adalah true
.
maks
Mengembalikan nilai batas maksimum untuk suatu jenis.
static constexpr Type max() throw();
Tampilkan Nilai
Nilai batas maksimum untuk jenis.
Keterangan
Nilai batas maksimum adalah INT_MAX untuk jenis int
dan FLT_MAX untuk jenis float
. Nilai yang dikembalikan bermakna jika is_bounded adalah true
.
Contoh
// numeric_limits_max.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main() {
cout << "The maximum value for type float is: "
<< numeric_limits<float>::max( )
<< endl;
cout << "The maximum value for type double is: "
<< numeric_limits<double>::max( )
<< endl;
cout << "The maximum value for type int is: "
<< numeric_limits<int>::max( )
<< endl;
cout << "The maximum value for type short int is: "
<< numeric_limits<short int>::max( )
<< endl;
}
max_digits10
Mengembalikan jumlah digit desimal yang diperlukan untuk memastikan bahwa dua nilai yang berbeda dari jenis memiliki representasi desimal yang berbeda.
static constexpr int max_digits10 = 0;
Tampilkan Nilai
Mengembalikan jumlah digit desimal yang diperlukan untuk memastikan bahwa dua nilai berbeda dari jenis memiliki representasi desimal yang berbeda.
Keterangan
Anggota menyimpan jumlah digit desimal yang diperlukan untuk memastikan bahwa dua nilai yang berbeda dari jenis tersebut memiliki representasi desimal yang berbeda.
max_exponent
Mengembalikan eksponen integral positif maksimum yang dapat diwakili oleh jenis floating-point sebagai nilai terbatas saat basis radix dinaikkan ke daya tersebut.
static constexpr int max_exponent = 0;
Tampilkan Nilai
Eksponen berbasis radix integral maksimum yang dapat diwakili oleh jenis .
Keterangan
Pengembalian fungsi anggota hanya bermakna untuk jenis floating-point. max_exponent
adalah nilai FLT_MAX_EXP untuk jenis float
.
Contoh
// numeric_limits_max_exponent.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "The maximum radix-based exponent for type float is: "
<< numeric_limits<float>::max_exponent
<< endl;
cout << "The maximum radix-based exponent for type double is: "
<< numeric_limits<double>::max_exponent
<< endl;
cout << "The maximum radix-based exponent for type long double is: "
<< numeric_limits<long double>::max_exponent
<< endl;
}
The maximum radix-based exponent for type float is: 128
The maximum radix-based exponent for type double is: 1024
The maximum radix-based exponent for type long double is: 1024
max_exponent10
Mengembalikan eksponen integral positif maksimum yang dapat diwakili oleh jenis floating-point sebagai nilai terbatas saat basis sepuluh dinaikkan ke daya tersebut.
static constexpr int max_exponent10 = 0;
Tampilkan Nilai
Basis integral maksimum 10 eksponen yang dapat diwakili oleh jenis .
Keterangan
Pengembalian fungsi anggota hanya bermakna untuk jenis floating-point. max_exponent
adalah nilai FLT_MAX_10 untuk jenis float
.
Contoh
// numeric_limits_max_exponent10.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "The maximum base 10 exponent for type float is: "
<< numeric_limits<float>::max_exponent10
<< endl;
cout << "The maximum base 10 exponent for type double is: "
<< numeric_limits<double>::max_exponent10
<< endl;
cout << "The maximum base 10 exponent for type long double is: "
<< numeric_limits<long double>::max_exponent10
<< endl;
}
The maximum base 10 exponent for type float is: 38
The maximum base 10 exponent for type double is: 308
The maximum base 10 exponent for type long double is: 308
mnt
Mengembalikan nilai minimum yang dinormalisasi untuk suatu jenis.
static constexpr Type min() throw();
Tampilkan Nilai
Nilai minimum yang dinormalisasi untuk jenis tersebut.
Keterangan
Nilai minimum yang dinormalisasi adalah INT_MIN untuk jenis int
dan FLT_MIN untuk jenis float
. Nilai yang dikembalikan bermakna jika is_bounded adalah true
atau jika is_signed adalah false
.
Contoh
// numeric_limits_min.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "The minimum value for type float is: "
<< numeric_limits<float>::min( )
<< endl;
cout << "The minimum value for type double is: "
<< numeric_limits<double>::min( )
<< endl;
cout << "The minimum value for type int is: "
<< numeric_limits<int>::min( )
<< endl;
cout << "The minimum value for type short int is: "
<< numeric_limits<short int>::min( )
<< endl;
}
The minimum value for type float is: 1.17549e-038
The minimum value for type double is: 2.22507e-308
The minimum value for type int is: -2147483648
The minimum value for type short int is: -32768
min_exponent
Mengembalikan eksponen integral negatif maksimum yang dapat diwakili oleh jenis floating-point sebagai nilai terbatas saat basis radix dinaikkan ke daya tersebut.
static constexpr int min_exponent = 0;
Tampilkan Nilai
Eksponen berbasis radix integral minimum yang dapat diwakili oleh jenis .
Keterangan
Fungsi anggota hanya bermakna untuk jenis floating-point. min_exponent
adalah nilai FLT_MIN_EXP untuk jenis float
.
Contoh
// numeric_limits_min_exponent.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "The minimum radix-based exponent for type float is: "
<< numeric_limits<float>::min_exponent
<< endl;
cout << "The minimum radix-based exponent for type double is: "
<< numeric_limits<double>::min_exponent
<< endl;
cout << "The minimum radix-based exponent for type long double is: "
<< numeric_limits<long double>::min_exponent
<< endl;
}
The minimum radix-based exponent for type float is: -125
The minimum radix-based exponent for type double is: -1021
The minimum radix-based exponent for type long double is: -1021
min_exponent10
Mengembalikan eksponen integral negatif maksimum yang dapat diwakili oleh jenis floating-point sebagai nilai terbatas saat basis sepuluh dinaikkan ke daya tersebut.
static constexpr int min_exponent10 = 0;
Tampilkan Nilai
Basis integral minimum 10 eksponen yang dapat diwakili oleh jenis .
Keterangan
Fungsi anggota hanya bermakna untuk jenis floating-point. min_exponent10
adalah nilai FLT_MIN_10_EXP untuk jenis float
.
Contoh
// numeric_limits_min_exponent10.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "The minimum base 10 exponent for type float is: "
<< numeric_limits<float>::min_exponent10
<< endl;
cout << "The minimum base 10 exponent for type double is: "
<< numeric_limits<double>::min_exponent10
<< endl;
cout << "The minimum base 10 exponent for type long double is: "
<< numeric_limits<long double>::min_exponent10
<< endl;
}
The minimum base 10 exponent for type float is: -37
The minimum base 10 exponent for type double is: -307
The minimum base 10 exponent for type long double is: -307
quiet_NaN
Mengembalikan representasi dari sepi bukan angka (NAN) untuk jenis tersebut.
static constexpr Type quiet_NaN() throw();
Tampilkan Nilai
Representasi NAN yang tenang untuk jenis tersebut.
Keterangan
Nilai yang dikembalikan bermakna hanya jika has_quiet_NaN adalah true
.
Contoh
// numeric_limits_quiet_nan.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "The quiet NaN for type float is: "
<< numeric_limits<float>::quiet_NaN( )
<< endl;
cout << "The quiet NaN for type int is: "
<< numeric_limits<int>::quiet_NaN( )
<< endl;
cout << "The quiet NaN for type long double is: "
<< numeric_limits<long double>::quiet_NaN( )
<< endl;
}
The quiet NaN for type float is: 1.#QNAN
The quiet NaN for type int is: 0
The quiet NaN for type long double is: 1.#QNAN
Radix
Mengembalikan basis integral, yang disebut sebagai radix, yang digunakan untuk representasi jenis.
static constexpr int radix = 0;
Tampilkan Nilai
Basis integral untuk representasi jenis .
Keterangan
Basisnya adalah 2 untuk jenis bilangan bulat yang telah ditentukan sebelumnya, dan basis tempat eksponen dinaikkan, atau FLT_RADIX, untuk jenis floating-point yang telah ditentukan sebelumnya.
Contoh
// numeric_limits_radix.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "The base for type float is: "
<< numeric_limits<float>::radix
<< endl;
cout << "The base for type int is: "
<< numeric_limits<int>::radix
<< endl;
cout << "The base for type long double is: "
<< numeric_limits<long double>::radix
<< endl;
}
The base for type float is: 2
The base for type int is: 2
The base for type long double is: 2
round_error
Mengembalikan kesalahan pembulatan maksimum untuk jenis tersebut.
static constexpr Type round_error() throw();
Tampilkan Nilai
Kesalahan pembulatan maksimum untuk jenis tersebut.
Contoh
// numeric_limits_round_error.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "The maximum rounding error for type float is: "
<< numeric_limits<float>::round_error( )
<< endl;
cout << "The maximum rounding error for type int is: "
<< numeric_limits<int>::round_error( )
<< endl;
cout << "The maximum rounding error for type long double is: "
<< numeric_limits<long double>::round_error( )
<< endl;
}
The maximum rounding error for type float is: 0.5
The maximum rounding error for type int is: 0
The maximum rounding error for type long double is: 0.5
round_style
Mengembalikan nilai yang menjelaskan berbagai metode yang dapat dipilih implementasi untuk membulatkan nilai floating-point ke nilai bilangan bulat.
static constexpr float_round_style round_style = round_toward_zero;
Tampilkan Nilai
Nilai dari float_round_style
enumerasi yang menjelaskan gaya pembulatan.
Keterangan
Anggota menyimpan nilai yang menjelaskan berbagai metode yang dapat dipilih implementasi untuk membulatkan nilai floating-point ke nilai bilangan bulat.
Gaya bulat dikodekan secara permanen dalam implementasi ini, jadi bahkan jika program dimulai dengan mode pembulatan yang berbeda, nilai tersebut tidak akan berubah.
Contoh
// numeric_limits_round_style.cpp
// compile with: /EHsc
#include <iostream>
#include <float.h>
#include <limits>
using namespace std;
int main( )
{
cout << "The rounding style for a double type is: "
<< numeric_limits<double>::round_style << endl;
_controlfp_s(NULL,_RC_DOWN,_MCW_RC );
cout << "The rounding style for a double type is now: "
<< numeric_limits<double>::round_style << endl;
cout << "The rounding style for an int type is: "
<< numeric_limits<int>::round_style << endl;
}
The rounding style for a double type is: 1
The rounding style for a double type is now: 1
The rounding style for an int type is: 0
signaling_NaN
Mengembalikan representasi sinyal bukan angka (NAN) untuk jenis tersebut.
static constexpr Type signaling_NaN() throw();
Tampilkan Nilai
Representasi sinyal NAN untuk jenis tersebut.
Keterangan
Nilai yang dikembalikan bermakna hanya jika has_signaling_NaN adalah true
.
Contoh
// numeric_limits_signaling_nan.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "The signaling NaN for type float is: "
<< numeric_limits<float>::signaling_NaN( )
<< endl;
cout << "The signaling NaN for type int is: "
<< numeric_limits<int>::signaling_NaN( )
<< endl;
cout << "The signaling NaN for type long double is: "
<< numeric_limits<long double>::signaling_NaN( )
<< endl;
}
tinyness_before
Menguji apakah jenis dapat menentukan bahwa nilai terlalu kecil untuk diwakili sebagai nilai yang dinormalisasi sebelum membulatkannya.
static constexpr bool tinyness_before = false;
Tampilkan Nilai
true
jika jenis dapat mendeteksi nilai kecil sebelum pembulatan; false
jika tidak bisa.
Keterangan
Jenis yang dapat mendeteksi tingkat kecil disertakan sebagai opsi dengan representasi floating-point IEC 559 dan implementasinya dapat memengaruhi beberapa hasil.
Contoh
// numeric_limits_tinyness_before.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float types can detect tinyness before rounding: "
<< numeric_limits<float>::tinyness_before
<< endl;
cout << "Whether double types can detect tinyness before rounding: "
<< numeric_limits<double>::tinyness_before
<< endl;
cout << "Whether long int types can detect tinyness before rounding: "
<< numeric_limits<long int>::tinyness_before
<< endl;
cout << "Whether unsigned char types can detect tinyness before rounding: "
<< numeric_limits<unsigned char>::tinyness_before
<< endl;
}
Whether float types can detect tinyness before rounding: 1
Whether double types can detect tinyness before rounding: 1
Whether long int types can detect tinyness before rounding: 0
Whether unsigned char types can detect tinyness before rounding: 0
Perangkap
Menguji apakah trapping yang melaporkan pengecualian aritmatika diimplementasikan untuk jenis.
static constexpr bool traps = false;
Tampilkan Nilai
true
jika trapping diimplementasikan untuk jenis; false
jika tidak.
Contoh
// numeric_limits_traps.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>
using namespace std;
int main( )
{
cout << "Whether float types have implemented trapping: "
<< numeric_limits<float>::traps
<< endl;
cout << "Whether double types have implemented trapping: "
<< numeric_limits<double>::traps
<< endl;
cout << "Whether long int types have implemented trapping: "
<< numeric_limits<long int>::traps
<< endl;
cout << "Whether unsigned char types have implemented trapping: "
<< numeric_limits<unsigned char>::traps
<< endl;
}
Whether float types have implemented trapping: 1
Whether double types have implemented trapping: 1
Whether long int types have implemented trapping: 0
Whether unsigned char types have implemented trapping: 0