blob: 0f4125899943ca682fb6f89650c9dc14a57488bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include <iostream>
#include <iomanip>
#include <limits>
int main(int argc, char *argv[]){
if(argc==2) {
std::cout << std::fixed;
float printable{std::stof(argv[1])};
std::cout << std::setprecision(std::numeric_limits<float>::max_digits10 + 2);
std::cout << printable << std::endl;
} else if(argc==3) {
std::string floatsize{argv[2]};
if(floatsize=="f") {
std::cout << std::fixed;
float printable{std::stof(argv[1])};
std::cout << std::setprecision(std::numeric_limits<float>::max_digits10 + 2);
std::cout << printable << std::endl;
} else if (floatsize=="d") {
std::cout << std::fixed;
double printable{std::stod(argv[1])};
std::cout << std::setprecision(std::numeric_limits<double>::max_digits10 + 2);
std::cout << printable << std::endl;
} else if (floatsize=="ld") {
std::cout << std::fixed;
long double printable{std::stold(argv[1])};
std::cout << std::setprecision(std::numeric_limits<long double>::max_digits10 + 2);
std::cout << printable << std::endl;
} else {
std::cerr << "That's not a valid floatsize. The only valid sizes are: f, d and ld." << std::endl;
return 1;
}
} else {
std::cerr << "Incorrect number of arguments." << std::endl;
return 1;
}
return 0;
}
|