mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibSQL: Implement converting float and tuple values to a boolean
This commit is contained in:
parent
8fab99e920
commit
e13c96157c
Notes:
sideshowbarker
2024-07-17 18:53:26 +09:00
Author: https://github.com/trflynn89
Commit: e13c96157c
Pull-request: https://github.com/SerenityOS/serenity/pull/12433
Reviewed-by: https://github.com/linusg ✅
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