use fmod and YGDoubleEquals for double operations instead of float

Summary: Changelog: [Internal][Yoga] Use double operations during rounding

Reviewed By: mdvacca

Differential Revision: D21840018

fbshipit-source-id: c5d17fcb8984b1da9832a15ccd4d628e8d742c6a
This commit is contained in:
Sidharth Guglani
2020-06-08 08:07:37 -07:00
committed by Facebook GitHub Bot
parent ede65bbce4
commit 633cdc9088
3 changed files with 17 additions and 8 deletions

View File

@@ -3668,7 +3668,7 @@ YOGA_EXPORT float YGRoundValueToPixelGrid(
double scaledValue = ((double) value) * pointScaleFactor;
// We want to calculate `fractial` such that `floor(scaledValue) = scaledValue
// - fractial`.
float fractial = fmodf(scaledValue, 1.0f);
double fractial = fmod(scaledValue, 1.0f);
if (fractial < 0) {
// This branch is for handling negative numbers for `value`.
//
@@ -3687,10 +3687,10 @@ YOGA_EXPORT float YGRoundValueToPixelGrid(
// - Finding the `floor`: -2.2 - fractial2 = -2.2 - 0.8 = -3
++fractial;
}
if (YGFloatsEqual(fractial, 0)) {
if (YGDoubleEqual(fractial, 0)) {
// First we check if the value is already rounded
scaledValue = scaledValue - fractial;
} else if (YGFloatsEqual(fractial, 1.0f)) {
} else if (YGDoubleEqual(fractial, 1.0f)) {
scaledValue = scaledValue - fractial + 1.0f;
} else if (forceCeil) {
// Next we check if we need to use forced rounding
@@ -3701,7 +3701,7 @@ YOGA_EXPORT float YGRoundValueToPixelGrid(
// Finally we just round the value
scaledValue = scaledValue - fractial +
(!YGFloatIsUndefined(fractial) &&
(fractial > 0.5f || YGFloatsEqual(fractial, 0.5f))
(fractial > 0.5f || YGDoubleEqual(fractial, 0.5f))
? 1.0f
: 0.0f);
}
@@ -4113,11 +4113,11 @@ static void YGRoundToPixelGrid(
// whole number, we don't have any fraction To verify if the result is close
// to whole number we want to check both floor and ceil numbers
const bool hasFractionalWidth =
!YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 0) &&
!YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 1.0);
!YGDoubleEqual(fmod(nodeWidth * pointScaleFactor, 1.0), 0) &&
!YGDoubleEqual(fmod(nodeWidth * pointScaleFactor, 1.0), 1.0);
const bool hasFractionalHeight =
!YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 0) &&
!YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 1.0);
!YGDoubleEqual(fmod(nodeHeight * pointScaleFactor, 1.0), 0) &&
!YGDoubleEqual(fmod(nodeHeight * pointScaleFactor, 1.0), 1.0);
node->setLayoutDimension(
YGRoundValueToPixelGrid(