LibCrypto: Convert BigFraction stringification to String

This commit is contained in:
Timothy Flynn 2024-12-03 11:36:08 -05:00 committed by Tim Flynn
parent 5cfd50224c
commit e6c96ce57e
Notes: github-actions[bot] 2024-12-04 13:02:44 +00:00
3 changed files with 4 additions and 4 deletions

View file

@ -185,7 +185,7 @@ void BigFraction::reduce()
m_denominator = denominator_divide.quotient;
}
ByteString BigFraction::to_byte_string(unsigned rounding_threshold) const
String BigFraction::to_string(unsigned rounding_threshold) const
{
StringBuilder builder;
if (m_numerator.is_negative() && m_numerator != "0"_bigint)
@ -240,7 +240,7 @@ ByteString BigFraction::to_byte_string(unsigned rounding_threshold) const
builder.append(fractional_value);
}
return builder.to_byte_string();
return MUST(builder.to_string());
}
BigFraction BigFraction::sqrt() const

View file

@ -55,7 +55,7 @@ public:
// - m_denominator = 10000
BigFraction rounded(unsigned rounding_threshold) const;
ByteString to_byte_string(unsigned rounding_threshold) const;
String to_string(unsigned rounding_threshold) const;
double to_double() const;
Crypto::SignedBigInteger const& numerator() const& { return m_numerator; }

View file

@ -23,6 +23,6 @@ TEST_CASE(roundtrip_from_string)
for (auto valid_number_string : valid_number_strings) {
auto result = TRY_OR_FAIL(Crypto::BigFraction::from_string(valid_number_string));
auto precision = valid_number_string.length() - valid_number_string.find('.').value();
EXPECT_EQ(result.to_byte_string(precision), valid_number_string);
EXPECT_EQ(result.to_string(precision), valid_number_string);
}
}