- formatting implemented for floating point types

- fixed some bugs with width and precision specifiers:
    * Evaluation order of nested replacement fields
This commit is contained in:
2025-12-08 12:13:51 -05:00
parent 9645856554
commit 9553f9b662
4 changed files with 168 additions and 48 deletions

View File

@@ -19,6 +19,7 @@
#ifndef FENNEC_TEST_PRINTING_H
#define FENNEC_TEST_PRINTING_H
#include <iomanip>
#include <iostream>
#include <fennec/filesystem/path.h>
@@ -63,17 +64,17 @@ inline std::ostream& operator<<(std::ostream& os, const quaternion<ScalarT>& q)
// Helper for printing strings
inline std::ostream& operator<<(std::ostream& os, const cstring& str) {
return os << str.data();
return os << std::quoted(str.data());
}
// Helper for printing strings
inline std::ostream& operator<<(std::ostream& os, const string& str) {
return os << str.cstr();
return os << std::quoted(str.cstr());
}
// Helper for printing strings
inline std::ostream& operator<<(std::ostream& os, const path& str) {
return os << str.str();
return os << std::quoted(str.cstr());
}
// Helper for printing types

View File

@@ -83,6 +83,22 @@ inline void fennec_test_format() {
fennec_test_run(fennec::format("{},{}", true, false), string("true,false"));
fennec_test_run(fennec::format("{:#06b},{:#06b}", true, false), string("0b0001,0b0000"));
fennec_test_spacer(1);
fennec_test_run(fennec::format("{:10f}", fennec::pi<float>()), string(" 3.141593"));
fennec_test_run(fennec::format("{:{}f}", fennec::pi<float>(), 10), string(" 3.141593"));
fennec_test_run(fennec::format("{:.5f}", fennec::pi<float>()), string("3.14159"));
fennec_test_run(fennec::format("{:.{}f}", fennec::pi<float>(), 5), string("3.14159"));
fennec_test_run(fennec::format("{:10.5f}", fennec::pi<float>()), string(" 3.14159"));
fennec_test_run(fennec::format("{:{}.{}f}", fennec::pi<float>(), 10, 5), string(" 3.14159"));
fennec_test_spacer(1);
fennec_test_run(fennec::format("{:.5f}", fennec::pi<float>()), string("3.14159"));
fennec_test_run(fennec::format("{:.5a}", fennec::pi<float>()), string("1.921fbp+1"));
fennec_test_run(fennec::format("{:.5g}", fennec::pi<float>()), string("3.1416"));
fennec_test_run(fennec::format("{:.5e}", fennec::pi<float>()), string("3.14159e+00"));
}
}