Summary: `/*` is the standard throughout open source code. For example, Firefox uses single /*: https://hg.mozilla.org/mozilla-central/file/21d22b2f541258d3d1cf96c7ba5ad73e96e616b5/gfx/ipc/CompositorWidgetVsyncObserver.cpp#l3 In addition, Rust considers `/**` to be a doc comment (similar to Javadoc) and having such a comment at the beginning of the file causes `rustc` to barf. Note that some JavaScript tooling requires `/**`. This is OK since JavaScript files were not covered by the linter in the first place, but it would be good to have that tooling fixed too. Reviewed By: zertosh Differential Revision: D15640366 fbshipit-source-id: b4ed4599071516364d6109720750d6a43304c089
70 lines
1.8 KiB
C++
70 lines
1.8 KiB
C++
/*
|
|
* 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.
|
|
*/
|
|
#pragma once
|
|
|
|
#include <cmath>
|
|
#include <limits>
|
|
#include "Yoga-internal.h"
|
|
|
|
struct YGFloatOptional {
|
|
private:
|
|
float value_ = std::numeric_limits<float>::quiet_NaN();
|
|
|
|
public:
|
|
explicit constexpr YGFloatOptional(float value) : value_(value) {}
|
|
constexpr YGFloatOptional() = default;
|
|
|
|
// returns the wrapped value, or a value x with YGIsUndefined(x) == true
|
|
constexpr float unwrap() const { return value_; }
|
|
|
|
bool isUndefined() const { return std::isnan(value_); }
|
|
};
|
|
|
|
// operators take YGFloatOptional by value, as it is a 32bit value
|
|
|
|
inline bool operator==(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return lhs.unwrap() == rhs.unwrap() ||
|
|
(lhs.isUndefined() && rhs.isUndefined());
|
|
}
|
|
inline bool operator!=(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return !(lhs == rhs);
|
|
}
|
|
|
|
inline bool operator==(YGFloatOptional lhs, float rhs) {
|
|
return lhs == YGFloatOptional{rhs};
|
|
}
|
|
inline bool operator!=(YGFloatOptional lhs, float rhs) {
|
|
return !(lhs == rhs);
|
|
}
|
|
|
|
inline bool operator==(float lhs, YGFloatOptional rhs) {
|
|
return rhs == lhs;
|
|
}
|
|
inline bool operator!=(float lhs, YGFloatOptional rhs) {
|
|
return !(lhs == rhs);
|
|
}
|
|
|
|
inline YGFloatOptional operator+(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return YGFloatOptional{lhs.unwrap() + rhs.unwrap()};
|
|
}
|
|
|
|
inline bool operator>(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return lhs.unwrap() > rhs.unwrap();
|
|
}
|
|
|
|
inline bool operator<(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return lhs.unwrap() < rhs.unwrap();
|
|
}
|
|
|
|
inline bool operator>=(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return lhs > rhs || lhs == rhs;
|
|
}
|
|
|
|
inline bool operator<=(YGFloatOptional lhs, YGFloatOptional rhs) {
|
|
return lhs < rhs || lhs == rhs;
|
|
}
|