mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:27:45 +00:00
LibCrypto: Parse negative input correctly in BigFraction::from_string()
Previously, when calling `BigFraction::from_string()`, the fractional part of the number was always treated as positive. This led to an incorrect result if the input string was negative.
This commit is contained in:
parent
e0fd5beb36
commit
d545fb2b60
3 changed files with 32 additions and 0 deletions
|
@ -36,6 +36,9 @@ ErrorOr<BigFraction> BigFraction::from_string(StringView sv)
|
|||
auto fractional_part = TRY(SignedBigInteger::from_base(10, fraction_part_view));
|
||||
auto fraction_length = UnsignedBigInteger(static_cast<u64>(fraction_part_view.length()));
|
||||
|
||||
if (!sv.is_empty() && sv[0] == '-')
|
||||
fractional_part.negate();
|
||||
|
||||
return BigFraction(move(integer_part)) + BigFraction(move(fractional_part), NumberTheory::Power("10"_bigint, move(fraction_length)));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue