Skip to content

Commit

Permalink
Trans Codegen C - Work around a MSVC quirk with float literals
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Sep 2, 2023
1 parent 68fe3c6 commit 37ee215
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/trans/codegen_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,12 @@ namespace {
m_of << (v < 0 ? "-" : "") << "INFINITY";
}
else {
if( ty == HIR::CoreType::F32 ) {
// HACK: Always emit float literals as `double` for MSVC, it fails hard with "error C2177: constant too big" otherwise
if( m_compiler == Compiler::Msvc ) {
m_of.precision(::std::numeric_limits<double>::max_digits10 + 1);
m_of << ::std::scientific << v;
}
else if( ty == HIR::CoreType::F32 ) {
m_of.precision(::std::numeric_limits<float>::max_digits10 + 1);
m_of << ::std::scientific << v << "f";
} else {
Expand Down

0 comments on commit 37ee215

Please sign in to comment.