summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanJacobs2022-10-03 19:38:23 +0200
committerSanJacobs2022-10-03 19:38:23 +0200
commit38cbad06b849ab53e5629ac076047bc150f42b29 (patch)
treee6799fb9f5dc822c29664044bac3173fe4b23fa4
downloadfloatback-master.tar.gz
floatback-master.tar.bz2
floatback-master.zip
Initial commitHEADmaster
-rw-r--r--.gitignore1
-rw-r--r--main.cpp37
2 files changed, 38 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e660fd9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+bin/
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..0f41258
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,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;
+}