mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare/integer] Fix negative mixed fraction
Mixed fractions for negative rational numbers are now computed as the opposite of their opposite's mixed fraction, as is conventionnal. ex : -9/5 is now decomposed as -1-4/5 instead of -2+1/5 Change-Id: I6df3dce585ccadd1bcd7cc562576995face98f9c
This commit is contained in:
committed by
Émilie Feral
parent
b92c819ea2
commit
bad21f0ab5
@@ -11,6 +11,8 @@
|
||||
#include <poincare/division_remainder.h>
|
||||
#include <poincare/equal.h>
|
||||
#include <poincare/multiplication.h>
|
||||
#include <poincare/opposite.h>
|
||||
#include <poincare/subtraction.h>
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
extern "C" {
|
||||
@@ -685,9 +687,18 @@ IntegerDivision Integer::udiv(const Integer & numerator, const Integer & denomin
|
||||
}
|
||||
|
||||
Expression Integer::CreateMixedFraction(const Integer & num, const Integer & denom) {
|
||||
Expression quo = DivisionQuotient::Reduce(num, denom);
|
||||
Expression rem = DivisionRemainder::Reduce(num, denom);
|
||||
return Addition::Builder(quo, Division::Builder(rem, Rational::Builder(denom)));
|
||||
Integer numPositive(num), denomPositive(denom);
|
||||
numPositive.setNegative(false);
|
||||
denomPositive.setNegative(false);
|
||||
Expression quo = DivisionQuotient::Reduce(numPositive, denomPositive);
|
||||
Expression rem = DivisionRemainder::Reduce(numPositive, denomPositive);
|
||||
if (num.isNegative() == denom.isNegative()) {
|
||||
return Addition::Builder(quo, Division::Builder(rem, Rational::Builder(denomPositive)));
|
||||
}
|
||||
return Subtraction::Builder(
|
||||
/* Do not add a minus sign before a zero. */
|
||||
(NaturalOrder(numPositive, denomPositive) < 0) ? quo : Opposite::Builder(quo),
|
||||
Division::Builder(rem, Rational::Builder(denomPositive)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user