Skip to content

Commit

Permalink
Back out Stack D13119110..D13236159
Browse files Browse the repository at this point in the history
Summary: backout, causes failures

Reviewed By: adityasharat

Differential Revision: D13376210

fbshipit-source-id: 1fa8823f2dce601c47738f34ddb2674288197e79
  • Loading branch information
davidaurelio authored and facebook-github-bot committed Dec 7, 2018
1 parent 6b7f698 commit b26e637
Show file tree
Hide file tree
Showing 19 changed files with 612 additions and 701 deletions.
23 changes: 20 additions & 3 deletions csharp/Facebook.Yoga/YogaConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
Expand All @@ -9,11 +9,28 @@ namespace Facebook.Yoga
{
public static class YogaConstants
{
public const 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 const float Undefined = 10E20F;

public static bool IsUndefined(float value)
{
return float.IsNaN(value);
// 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 value >= 10E8F || value <= -10E8;
}

public static bool IsUndefined(YogaValue value)
Expand Down
30 changes: 24 additions & 6 deletions java/com/facebook/yoga/YogaConstants.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
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 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) {
Expand Down
205 changes: 0 additions & 205 deletions tests/YGFloatOptionalTest.cpp

This file was deleted.

1 change: 1 addition & 0 deletions tools/build_defs/oss/yoga_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ BASE_COMPILER_FLAGS = [
"-Wall",
"-Werror",
"-O3",
"-ffast-math",
]

LIBRARY_COMPILER_FLAGS = BASE_COMPILER_FLAGS + [
Expand Down
15 changes: 8 additions & 7 deletions yoga/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ float YGFloatSanitize(const float val) {
return yoga::isUndefined(val) ? 0 : val;
}

float YGUnwrapFloatOptional(const YGFloatOptional& op) {
return op.isUndefined() ? YGUndefined : op.getValue();
}

YGFloatOptional YGFloatOptionalMax(
const YGFloatOptional op1,
const YGFloatOptional op2) {
if (op1 > op2) {
return op1;
}
if (op2 > op1) {
return op2;
const YGFloatOptional& op1,
const YGFloatOptional& op2) {
if (!op1.isUndefined() && !op2.isUndefined()) {
return op1.getValue() > op2.getValue() ? op1 : op2;
}
return op1.isUndefined() ? op2 : op1;
}
38 changes: 27 additions & 11 deletions yoga/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,22 @@ bool YGValueEqual(const YGValue a, const YGValue b);
// difference between two floats is less than 0.0001f or both are undefined.
bool YGFloatsEqual(const float a, const float b);

// We need custom max function, since we want that, if one argument is
// YGUndefined then the max funtion should return the other argument as the max
// value. We wouldn't have needed a custom max function if YGUndefined was NAN
// as fmax has the same behaviour, but with NAN we cannot use `-ffast-math`
// compiler flag.
float YGFloatMax(const float a, const float b);

YGFloatOptional YGFloatOptionalMax(
const YGFloatOptional op1,
const YGFloatOptional op2);

const YGFloatOptional& op1,
const YGFloatOptional& op2);

// We need custom min function, since we want that, if one argument is
// YGUndefined then the min funtion should return the other argument as the min
// value. We wouldn't have needed a custom min function if YGUndefined was NAN
// as fmin has the same behaviour, but with NAN we cannot use `-ffast-math`
// compiler flag.
float YGFloatMin(const float a, const float b);

// This custom float comparision function compares the array of float with
Expand All @@ -82,6 +92,11 @@ bool YGFloatArrayEqual(
// This function returns 0 if YGFloatIsUndefined(val) is true and val otherwise
float YGFloatSanitize(const float val);

// This function unwraps optional and returns YGUndefined if not defined or
// op.value otherwise
// TODO: Get rid off this function
float YGUnwrapFloatOptional(const YGFloatOptional& op);

YGFlexDirection YGFlexDirectionCross(
const YGFlexDirection flexDirection,
const YGDirection direction);
Expand All @@ -91,17 +106,18 @@ inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) {
flexDirection == YGFlexDirectionRowReverse;
}

inline YGFloatOptional YGResolveValue(
const YGValue value,
const float ownerSize) {
inline YGFloatOptional YGResolveValue(const YGValue value, const float ownerSize) {
switch (value.unit) {
case YGUnitUndefined:
case YGUnitAuto:
return YGFloatOptional();
case YGUnitPoint:
return YGFloatOptional{value.value};
return YGFloatOptional(value.value);
case YGUnitPercent:
return YGFloatOptional{value.value * ownerSize * 0.01f};
default:
return YGFloatOptional{};
return YGFloatOptional(
static_cast<float>(value.value * ownerSize * 0.01));
}
return YGFloatOptional();
}

inline bool YGFlexDirectionIsColumn(const YGFlexDirection flexDirection) {
Expand All @@ -123,7 +139,7 @@ inline YGFlexDirection YGResolveFlexDirection(
return flexDirection;
}

inline YGFloatOptional YGResolveValueMargin(
static inline YGFloatOptional YGResolveValueMargin(
const YGValue value,
const float ownerSize) {
return value.unit == YGUnitAuto ? YGFloatOptional(0)
Expand Down
Loading

0 comments on commit b26e637

Please sign in to comment.