mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:28:12 +00:00
LibSQL: Implement converting float and tuple values to a boolean
This commit is contained in:
parent
8fab99e920
commit
e13c96157c
3 changed files with 32 additions and 2 deletions
|
@ -728,6 +728,11 @@ Optional<int> FloatImpl::to_int() const
|
|||
return static_cast<int>(round(value()));
|
||||
}
|
||||
|
||||
Optional<bool> FloatImpl::to_bool() const
|
||||
{
|
||||
return fabs(value()) > NumericLimits<double>::epsilon();
|
||||
}
|
||||
|
||||
Optional<double> FloatImpl::to_double() const
|
||||
{
|
||||
return value();
|
||||
|
@ -999,6 +1004,19 @@ int TupleImpl::compare(Value const& other) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
Optional<bool> TupleImpl::to_bool() const
|
||||
{
|
||||
for (auto const& value : value()) {
|
||||
auto as_bool = Value(value).to_bool();
|
||||
if (!as_bool.has_value())
|
||||
return {};
|
||||
if (!as_bool.value())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TupleImpl::serialize(Serializer& serializer) const
|
||||
{
|
||||
serializer.serialize<TupleDescriptor>(*m_descriptor);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue