@@ -356,12 +356,7 @@ Decimal::Decimal(std::string_view str) {
356356}
357357
358358Decimal& Decimal::Negate () {
359- uint64_t result_low = ~low () + 1 ;
360- int64_t result_high = ~high ();
361- if (result_low == 0 ) {
362- result_high = SafeSignedAdd<int64_t >(result_high, 1 );
363- }
364- *this = Decimal (result_high, result_low);
359+ data_ = ~data_ + 1 ;
365360 return *this ;
366361}
367362
@@ -373,35 +368,17 @@ Decimal Decimal::Abs(const Decimal& value) {
373368}
374369
375370Decimal& Decimal::operator +=(const Decimal& other) {
376- int64_t result_high = SafeSignedAdd (high (), other.high ());
377- uint64_t result_low = low () + other.low ();
378- result_high = SafeSignedAdd<int64_t >(result_high, result_low < low ());
379- *this = Decimal (result_high, result_low);
371+ data_ += other.data_ ;
380372 return *this ;
381373}
382374
383375Decimal& Decimal::operator -=(const Decimal& other) {
384- int64_t result_high = SafeSignedSubtract (high (), other.high ());
385- uint64_t result_low = low () - other.low ();
386- result_high = SafeSignedSubtract<int64_t >(result_high, result_low > low ());
387- *this = Decimal (result_high, result_low);
376+ data_ -= other.data_ ;
388377 return *this ;
389378}
390379
391380Decimal& Decimal::operator *=(const Decimal& other) {
392- // Since the max value of Decimal is supposed to be 1e38 - 1 and the min the
393- // negation taking the abosolute values here should aways be safe.
394- const bool negate = Sign () != other.Sign ();
395- Decimal x = Decimal::Abs (*this );
396- Decimal y = Decimal::Abs (other);
397-
398- Uint128 r (x);
399- r *= Uint128 (y);
400-
401- *this = Decimal (static_cast <int64_t >(r.high ()), r.low ());
402- if (negate) {
403- Negate ();
404- }
381+ data_ *= other.data_ ;
405382 return *this ;
406383}
407384
@@ -412,9 +389,7 @@ Result<std::pair<Decimal, Decimal>> Decimal::Divide(const Decimal& divisor) cons
412389}
413390
414391Decimal& Decimal::operator /=(const Decimal& other) {
415- Decimal remainder;
416- auto s = DecimalDivide (*this , other, this , &remainder);
417- assert (s);
392+ data_ /= other.data_ ;
418393 return *this ;
419394}
420395
0 commit comments