mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-19 13:08:11 +08:00
Change NaN with large number
Reviewed By: emilsjolander Differential Revision: D6969537 fbshipit-source-id: bdc09eaf703e0d313ca65c25a4fb44c99203d9bf
This commit is contained in:
committed by
Facebook Github Bot
parent
af9d6479e5
commit
d174ab8a7a
@@ -9,12 +9,29 @@ package com.facebook.yoga;
|
||||
|
||||
public class YogaConstants {
|
||||
|
||||
public static final float UNDEFINED = Float.NaN;
|
||||
/**
|
||||
* Large positive number signifies that the property(float) is undefined. Earlier we used to have
|
||||
* YGundefined as NAN, but the downside of this is that we can't use -ffast-math compiler flag as
|
||||
* it assumes all floating-point calculation involve and result into finite numbers. For more
|
||||
* information regarding -ffast-math compiler flag in clang, have a look at
|
||||
* https://clang.llvm.org/docs/UsersManual.html#cmdoption-ffast-math
|
||||
*/
|
||||
public static final float UNDEFINED = (float) (10E20);
|
||||
|
||||
public static boolean shouldUseFastMath = false;
|
||||
|
||||
public static boolean isUndefined(float value) {
|
||||
return Float.compare(value, UNDEFINED) == 0;
|
||||
// Value of a float in the case of it being not defined is 10.1E20. Earlier it used to be NAN,
|
||||
// the benefit of which
|
||||
// was that if NAN is involved in any mathematical expression the result was NAN. But since we
|
||||
// want to have `-ffast-math`
|
||||
// flag being used by compiler which assumes that the floating point values are not NAN and Inf,
|
||||
// we represent YGUndefined as 10.1E20.
|
||||
// But now if YGUndefined is involved in any mathematical operations this value(10.1E20) would
|
||||
// change.
|
||||
// So the following check makes sure that if the value is outside a range (-10E8, 10E8) then it
|
||||
// is undefined.
|
||||
return (Float.compare(value, (float) 10E8) >= 0 || Float.compare(value, (float) -10E8) <= 0);
|
||||
}
|
||||
|
||||
public static boolean isUndefined(YogaValue value) {
|
||||
|
||||
@@ -652,11 +652,11 @@ public class YogaNode implements Cloneable {
|
||||
}
|
||||
|
||||
return mMeasureFunction.measure(
|
||||
this,
|
||||
width,
|
||||
YogaMeasureMode.fromInt(widthMode),
|
||||
height,
|
||||
YogaMeasureMode.fromInt(heightMode));
|
||||
this,
|
||||
width,
|
||||
YogaMeasureMode.fromInt(widthMode),
|
||||
height,
|
||||
YogaMeasureMode.fromInt(heightMode));
|
||||
}
|
||||
|
||||
private native void jni_YGNodeSetHasBaselineFunc(long nativePointer, boolean hasMeasureFunc);
|
||||
|
||||
Reference in New Issue
Block a user