2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTSampleRatio.h>
|
2015-11-19 21:34:53 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
String ASTSampleRatio::toString(BigNum num)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (num == 0)
|
|
|
|
return "0";
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
static const size_t MAX_WIDTH = 40;
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
char tmp[MAX_WIDTH];
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
char * pos;
|
|
|
|
for (pos = tmp + MAX_WIDTH - 1; num != 0; --pos)
|
|
|
|
{
|
|
|
|
*pos = '0' + num % 10;
|
|
|
|
num /= 10;
|
|
|
|
}
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
++pos;
|
2015-11-19 21:34:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return String(pos, tmp + MAX_WIDTH - pos);
|
2015-11-19 21:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String ASTSampleRatio::toString(Rational ratio)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (ratio.denominator == 1)
|
|
|
|
return toString(ratio.numerator);
|
|
|
|
else
|
|
|
|
return toString(ratio.numerator) + " / " + toString(ratio.denominator);
|
2015-11-19 21:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|