d06 ex00 ajout qq tests avec limits des floats

This commit is contained in:
hugogogo
2022-03-10 16:14:01 +01:00
parent 04dea6722f
commit 31c9d8af06
10 changed files with 161 additions and 58 deletions

36
d06/ex00/test_float.cpp Normal file
View 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;
}