d06 ex00 ajout qq tests avec limits des floats
This commit is contained in:
36
d06/ex00/test_float.cpp
Normal file
36
d06/ex00/test_float.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
|
||||
#define MAX_INT 2147483647
|
||||
#define MIN_INT -2147483648
|
||||
#define MAX_FLOAT 340282346638528859811704183484516925440.0f
|
||||
#define MIN_FLOAT -340282346638528859811704183484516925440.0f
|
||||
|
||||
void isFloat(double d) {
|
||||
if (! (d <= std::numeric_limits<float>::max()
|
||||
&& d >= std::numeric_limits<float>::min()) )
|
||||
{
|
||||
std::cout << d << "is outside range of floats\n";
|
||||
return ;
|
||||
}
|
||||
std::cout << std::fixed << static_cast<float>(d) << "\n";
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
double d;
|
||||
double d2;
|
||||
|
||||
d = std::numeric_limits<float>::max();
|
||||
std::cout << std::fixed << d << "\n";
|
||||
d2 = std::nextafter(d, DBL_MAX);
|
||||
std::cout << std::fixed << d2 << "\n";
|
||||
// isFloat(MAX_FLOAT);
|
||||
// d = std::numeric_limits<float>::lowest();
|
||||
// std::cout << std::fixed << d << "\n";
|
||||
// isFloat(d);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user