1
Fork 0
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:
Timothy Flynn 2022-02-11 09:43:02 -05:00 committed by Linus Groh
parent 8fab99e920
commit e13c96157c
3 changed files with 32 additions and 2 deletions

View file

@ -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);