ladybird/Libraries/LibWeb/CSS/Number.cpp
Sam Atkins 46b9497a66 LibWeb/CSS: Make non-finite Numbers serialize as themselves
We're required to serialize NaN, infinity, and -infinity as their
keyword names, even after they've been converted to Numbers.
2025-01-30 19:31:54 +01:00

25 lines
572 B
C++

/*
* Copyright (c) 2022-2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Math.h>
#include <LibWeb/CSS/Number.h>
namespace Web::CSS {
String Number::to_string() const
{
if (m_type == Type::IntegerWithExplicitSign)
return MUST(String::formatted("{:+}", m_value));
if (m_value == AK::Infinity<double>)
return "infinity"_string;
if (m_value == -AK::Infinity<double>)
return "-infinity"_string;
if (isnan(m_value))
return "NaN"_string;
return String::number(m_value);
}
}