Skip to content

Commit

Permalink
Shaders: Explorer/Parser updated
Browse files Browse the repository at this point in the history
  • Loading branch information
valdok committed Jul 25, 2024
1 parent e809ee6 commit 0e8b5fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions bvm/Shaders/Explorer/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,8 @@ void ParserContext::OnState_DEX(uint32_t /* iVer */)
DocAddTableHeader("Amount1");
DocAddTableHeader("Amount2");
DocAddTableHeader("Amount-LP-Token");
DocAddTableHeader("Rate");
DocAddTableHeader("Rate 1:2");
DocAddTableHeader("Rate 2:2");
}

Env::Key_T<Amm::Pool::Key> k0, k1;
Expand All @@ -2440,53 +2441,36 @@ void ParserContext::OnState_DEX(uint32_t /* iVer */)

if (p.m_Totals.m_Tok1 && p.m_Totals.m_Tok2)
{
char szBuf[MultiPrecision::Float::DecimalForm::s_LenScientificMax + 3];
uint32_t nBuf = 0;

bool b1 = (p.m_Totals.m_Tok1 >= p.m_Totals.m_Tok2);
char szBuf[MultiPrecision::Float::DecimalForm::s_LenScientificMax + 1];

MultiPrecision::Float f1(p.m_Totals.m_Tok1);
MultiPrecision::Float f2(p.m_Totals.m_Tok2);

MultiPrecision::Float k;
if (b1)
k = f1 / f2;
else
for (uint32_t i = 0; i < 2; i++)
{
k = f2 / f1;
szBuf[nBuf++] = '1';
szBuf[nBuf++] = ':';
}
auto k = i ? (f2 / f1) : (f1 / f2);
auto df = k.get_Decimal();

{
// print the ratio nicely. Limit to 8 precision digits, prefer std notation
const uint32_t nPrecision = 8;

MultiPrecision::Float::DecimalForm df;
df.Assign(k);

df.LimitPrecision(nPrecision);

MultiPrecision::Float::DecimalForm::PrintOptions po;

if (df.get_TextLenStd(po) <= nPrecision + 2)
nBuf += df.PrintStd(szBuf + nBuf, po);
df.PrintStd(szBuf, po);
else
nBuf += df.PrintScientific(szBuf + nBuf, po);
}
df.PrintScientific(szBuf, po);

if (b1)
{
szBuf[nBuf++] = ':';
szBuf[nBuf++] = '1';
Env::DocAddText("", szBuf);
}

szBuf[nBuf] = 0;
Env::DocAddText("", szBuf);

}
else
{
Env::DocAddText("", "");
Env::DocAddText("", "");
}
}

}
Expand Down
Binary file modified bvm/Shaders/Explorer/Parser.wasm
Binary file not shown.

0 comments on commit 0e8b5fc

Please sign in to comment.