From 307175b6167232e4bd8a28b3a4f784e85ad3c5d2 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Thu, 8 Aug 2024 17:13:13 -0400 Subject: [PATCH] Fix bug in number printing. --- Utility/print_number.h | 20 ++++++++++++-------- Utility/print_number.test/0.cc | 4 ++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Utility/print_number.h b/Utility/print_number.h index bebb7e2..c53dbcb 100644 --- a/Utility/print_number.h +++ b/Utility/print_number.h @@ -78,16 +78,20 @@ namespace Alepha::Hydrogen::Utility ::detail:: print_number_m value/= 1000; if( not remainder ) continue; std::string next; - if( remainder >= 100 ) next+= names.at( remainder / 100 ) + " hundred "; + if( remainder >= 100 ) next+= names.at( remainder / 100 ) + " hundred"; remainder%= 100; - if( remainder >= 20 ) + if( remainder ) { - next+= tens.at( remainder - remainder % 10 ); - if( remainder % 10 ) next+= " " + names.at( remainder % 10 ); - } - else if( remainder ) - { - next+= names.at( remainder ); + next+= " "; + if( remainder >= 20 ) + { + next+= tens.at( remainder - remainder % 10 ); + if( remainder % 10 ) next+= " " + names.at( remainder % 10 ); + } + else + { + next+= names.at( remainder ); + } } next+= " " + powers.at( millennium ); parts.push_back( std::move( next ) ); diff --git a/Utility/print_number.test/0.cc b/Utility/print_number.test/0.cc index 2549748..09804b8 100644 --- a/Utility/print_number.test/0.cc +++ b/Utility/print_number.test/0.cc @@ -24,6 +24,10 @@ static auto init= Alepha::Utility::enroll <=[] { "1000283000000", { 1'000'283'000'000 }, "one trillion two hundred eighty three million" }, + + // I just detected this weird case: + { "1000100006000500", { 1000100006000500 }, + "one quadrillion one hundred billion six million five hundred" }, }; -"repl"_test <=[]