C4244 possible precision loss warning fix
Summary: Fixing `warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data` Changelog: [Internal] Reviewed By: SidharthGuglani Differential Revision: D27132355 fbshipit-source-id: 55ff35be368ef4f6093865eb88c17e753250d179
This commit is contained in:
committed by
Facebook GitHub Bot
parent
67b6c24d7b
commit
db6be5286e
@@ -55,7 +55,7 @@ bool YGFloatsEqual(const float a, const float b) {
|
|||||||
|
|
||||||
bool YGDoubleEqual(const double a, const double b) {
|
bool YGDoubleEqual(const double a, const double b) {
|
||||||
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
|
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
|
||||||
return fabs(a - b) < 0.0001f;
|
return fabs(a - b) < 0.0001;
|
||||||
}
|
}
|
||||||
return yoga::isUndefined(a) && yoga::isUndefined(b);
|
return yoga::isUndefined(a) && yoga::isUndefined(b);
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,10 @@ inline bool isUndefined(float value) {
|
|||||||
return std::isnan(value);
|
return std::isnan(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool isUndefined(double value) {
|
||||||
|
return std::isnan(value);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace yoga
|
} // namespace yoga
|
||||||
} // namespace facebook
|
} // namespace facebook
|
||||||
|
|
||||||
|
@@ -106,6 +106,10 @@ static int YGDefaultLog(
|
|||||||
#undef YG_UNUSED
|
#undef YG_UNUSED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline bool YGDoubleIsUndefined(const double value) {
|
||||||
|
return facebook::yoga::isUndefined(value);
|
||||||
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGFloatIsUndefined(const float value) {
|
YOGA_EXPORT bool YGFloatIsUndefined(const float value) {
|
||||||
return facebook::yoga::isUndefined(value);
|
return facebook::yoga::isUndefined(value);
|
||||||
}
|
}
|
||||||
@@ -3620,10 +3624,10 @@ YOGA_EXPORT float YGRoundValueToPixelGrid(
|
|||||||
const double pointScaleFactor,
|
const double pointScaleFactor,
|
||||||
const bool forceCeil,
|
const bool forceCeil,
|
||||||
const bool forceFloor) {
|
const bool forceFloor) {
|
||||||
double scaledValue = ((double) value) * pointScaleFactor;
|
double scaledValue = value * pointScaleFactor;
|
||||||
// We want to calculate `fractial` such that `floor(scaledValue) = scaledValue
|
// We want to calculate `fractial` such that `floor(scaledValue) = scaledValue
|
||||||
// - fractial`.
|
// - fractial`.
|
||||||
double fractial = fmod(scaledValue, 1.0f);
|
double fractial = fmod(scaledValue, 1.0);
|
||||||
if (fractial < 0) {
|
if (fractial < 0) {
|
||||||
// This branch is for handling negative numbers for `value`.
|
// This branch is for handling negative numbers for `value`.
|
||||||
//
|
//
|
||||||
@@ -3645,25 +3649,25 @@ YOGA_EXPORT float YGRoundValueToPixelGrid(
|
|||||||
if (YGDoubleEqual(fractial, 0)) {
|
if (YGDoubleEqual(fractial, 0)) {
|
||||||
// First we check if the value is already rounded
|
// First we check if the value is already rounded
|
||||||
scaledValue = scaledValue - fractial;
|
scaledValue = scaledValue - fractial;
|
||||||
} else if (YGDoubleEqual(fractial, 1.0f)) {
|
} else if (YGDoubleEqual(fractial, 1.0)) {
|
||||||
scaledValue = scaledValue - fractial + 1.0f;
|
scaledValue = scaledValue - fractial + 1.0;
|
||||||
} else if (forceCeil) {
|
} else if (forceCeil) {
|
||||||
// Next we check if we need to use forced rounding
|
// Next we check if we need to use forced rounding
|
||||||
scaledValue = scaledValue - fractial + 1.0f;
|
scaledValue = scaledValue - fractial + 1.0;
|
||||||
} else if (forceFloor) {
|
} else if (forceFloor) {
|
||||||
scaledValue = scaledValue - fractial;
|
scaledValue = scaledValue - fractial;
|
||||||
} else {
|
} else {
|
||||||
// Finally we just round the value
|
// Finally we just round the value
|
||||||
scaledValue = scaledValue - fractial +
|
scaledValue = scaledValue - fractial +
|
||||||
(!YGFloatIsUndefined(fractial) &&
|
(!YGDoubleIsUndefined(fractial) &&
|
||||||
(fractial > 0.5f || YGDoubleEqual(fractial, 0.5f))
|
(fractial > 0.5 || YGDoubleEqual(fractial, 0.5))
|
||||||
? 1.0f
|
? 1.0
|
||||||
: 0.0f);
|
: 0.0);
|
||||||
}
|
}
|
||||||
return (YGFloatIsUndefined(scaledValue) ||
|
return (YGDoubleIsUndefined(scaledValue) ||
|
||||||
YGFloatIsUndefined(pointScaleFactor))
|
YGDoubleIsUndefined(pointScaleFactor))
|
||||||
? YGUndefined
|
? YGUndefined
|
||||||
: scaledValue / pointScaleFactor;
|
: (float) (scaledValue / pointScaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT bool YGNodeCanUseCachedMeasurement(
|
YOGA_EXPORT bool YGNodeCanUseCachedMeasurement(
|
||||||
|
Reference in New Issue
Block a user