numeric_limits#
-
class numpy::numeric_limits#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use numeric_limits
numeric_limits obj;
// ... operations ...
Statistics#
Math Operations#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
numpy::float16 |
NP_FLOAT16.H:307 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
numpy::float16 |
NP_FLOAT16.H:311 |
|
|
numpy::float16 |
NP_FLOAT16.H:306 |
|
|
numpy::float16 |
NP_FLOAT16.H:308 |
|
|
numpy::float16 |
NP_FLOAT16.H:305 |
|
|
numpy::float16 |
NP_FLOAT16.H:309 |
|
|
numpy::float16 |
NP_FLOAT16.H:310 |
Code Examples#
The following examples are extracted from the test suite.
max (np_test_1_all.cpp:7274)
7264 if (sizeof(uintp) == sizeof(void*)) {
7265 // std::cout << " -> uintp size matches pointer size";
7266 } else {
7267 // std::cout << " ✗ uintp size doesn't match pointer size" << std::endl;
7268 }
7269
7270 // Test range limits
7271 // std::cout << "Range Information:" << std::endl;
7272 // std::cout << " intp min: " << std::numeric_limits<intp>::min() << std::endl;
7273 // std::cout << " intp max: " << std::numeric_limits<intp>::max() << std::endl;
7274 // std::cout << " uintp max: " << std::numeric_limits<uintp>::max() << std::endl;
7275 // std::cout << " longdouble digits: " << std::numeric_limits<longdouble>::digits << std::endl;
7276
7277 std::cout << " -> tests passed" << std::endl;
7278}
7279
7280void testComplexArithmeticExtendedTypes() {
7281 std::cout << "========= testComplexArithmeticExtendedTypes =======================";
7282
7283 clongdouble c1(3.0L, 4.0L); // 3 + 4i
min (np_test_1_all.cpp:2350)
2340 if (i % 3 == 0) {
2341 large_array.setElementAt({i}, object_(static_cast<int>(i)));
2342 } else if (i % 3 == 1) {
2343 large_array.setElementAt({i}, object_(static_cast<double>(i) * 0.5));
2344 } else {
2345 large_array.setElementAt({i}, object_(std::string("str") + std::to_string(i)));
2346 }
2347 }
2348
2349 // Verify pattern
2350 for (size_t i = 0; i < std::min(large_size, size_t(100)); ++i) { // Check first 100
2351 object_ obj = large_array.getElementAt({i});
2352 if (i % 3 == 0) {
2353 if (!(obj.is_type<int>())) {
2354 std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type<int>())";
2355 std::cout << std::string("[FAIL] ") + description << std::endl;
2356 throw std::runtime_error(description);
2357 }
2358 } else if (i % 3 == 1) {
2359 if (!(obj.is_type<double>())) {
2360 std::string description = std::string("unknown_function():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type<double>())";
epsilon (np_test_1_all.cpp:7822)
7812 // std::cout << " float16: " << sizeof(float16) << " bytes" << std::endl;
7813 // std::cout << " float32: " << sizeof(float32) << " bytes" << std::endl;
7814 // std::cout << " float64: " << sizeof(float64) << " bytes" << std::endl;
7815 // std::cout << " float128: " << sizeof(float128) << " bytes" << std::endl;
7816
7817 // Test numeric limits
7818 // std::cout << "Numeric limits:" << std::endl;
7819 // std::cout << " min: " << std::numeric_limits<float16>::min() << std::endl;
7820 // std::cout << " max: " << std::numeric_limits<float16>::max() << std::endl;
7821 // std::cout << " lowest: " << std::numeric_limits<float16>::lowest() << std::endl;
7822 // std::cout << " epsilon: " << std::numeric_limits<float16>::epsilon() << std::endl;
7823 // std::cout << " digits: " << std::numeric_limits<float16>::digits << std::endl;
7824 // std::cout << " digits10: " << std::numeric_limits<float16>::digits10 << std::endl;
7825
7826 std::cout << " -> tests passed" << std::endl;
7827}
7828
7829void testFloat16BitPatternsFloat16() {
7830 std::cout << "========= testFloat16BitPatternsFloat16 =======================";
7831
7832 // Test some known bit patterns
infinity (np_test_1_all.cpp:1067)
1057 std::cout << " -> tests passed" << std::endl;
1058}
1059
1060void testSpecialValueHandling() {
1061 std::cout << "========= testSpecialValueHandling =======================";
1062
1063 auto arr = createFloat64Array({4});
1064 arr.setElementAt({0}, 1.0);
1065 arr.setElementAt({1}, std::numeric_limits<double>::quiet_NaN());
1066 arr.setElementAt({2}, std::numeric_limits<double>::infinity());
1067 arr.setElementAt({3}, -std::numeric_limits<double>::infinity());
1068
1069 auto scalar_arr = createFloat64Array({4});
1070 scalar_arr.setElementAt({0}, 2.0);
1071 scalar_arr.setElementAt({1}, 1.0);
1072 scalar_arr.setElementAt({2}, 1.0);
1073 scalar_arr.setElementAt({3}, 1.0);
1074
1075 // Test NaN behavior - NaN comparisons should be false
1076 auto gt_result = greater(arr, scalar_arr);
lowest (np_test_1_all.cpp:7821)
7811 // std::cout << "Size comparison:" << std::endl;
7812 // std::cout << " float16: " << sizeof(float16) << " bytes" << std::endl;
7813 // std::cout << " float32: " << sizeof(float32) << " bytes" << std::endl;
7814 // std::cout << " float64: " << sizeof(float64) << " bytes" << std::endl;
7815 // std::cout << " float128: " << sizeof(float128) << " bytes" << std::endl;
7816
7817 // Test numeric limits
7818 // std::cout << "Numeric limits:" << std::endl;
7819 // std::cout << " min: " << std::numeric_limits<float16>::min() << std::endl;
7820 // std::cout << " max: " << std::numeric_limits<float16>::max() << std::endl;
7821 // std::cout << " lowest: " << std::numeric_limits<float16>::lowest() << std::endl;
7822 // std::cout << " epsilon: " << std::numeric_limits<float16>::epsilon() << std::endl;
7823 // std::cout << " digits: " << std::numeric_limits<float16>::digits << std::endl;
7824 // std::cout << " digits10: " << std::numeric_limits<float16>::digits10 << std::endl;
7825
7826 std::cout << " -> tests passed" << std::endl;
7827}
7828
7829void testFloat16BitPatternsFloat16() {
7830 std::cout << "========= testFloat16BitPatternsFloat16 =======================";
quiet_NaN (np_test_1_all.cpp:1066)
1056 // std::cout << "[OK] equal and not_equal functions" << std::endl;
1057
1058 std::cout << " -> tests passed" << std::endl;
1059}
1060
1061void testSpecialValueHandling() {
1062 std::cout << "========= testSpecialValueHandling =======================";
1063
1064 auto arr = createFloat64Array({4});
1065 arr.setElementAt({0}, 1.0);
1066 arr.setElementAt({1}, std::numeric_limits<double>::quiet_NaN());
1067 arr.setElementAt({2}, std::numeric_limits<double>::infinity());
1068 arr.setElementAt({3}, -std::numeric_limits<double>::infinity());
1069
1070 auto scalar_arr = createFloat64Array({4});
1071 scalar_arr.setElementAt({0}, 2.0);
1072 scalar_arr.setElementAt({1}, 1.0);
1073 scalar_arr.setElementAt({2}, 1.0);
1074 scalar_arr.setElementAt({3}, 1.0);
1075
1076 // Test NaN behavior - NaN comparisons should be false