/* * Copyright (c) 2022-2025, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #include "Ratio.h" #include #include namespace Web::CSS { Ratio::Ratio(double first, double second) : m_first_value(first) , m_second_value(second) { } // https://www.w3.org/TR/css-values-4/#degenerate-ratio bool Ratio::is_degenerate() const { return !isfinite(m_first_value) || m_first_value == 0 || !isfinite(m_second_value) || m_second_value == 0; } String Ratio::to_string() const { // https://drafts.csswg.org/cssom/#serialize-a-css-value // -> // The numerator serialized as per followed by the literal string " / ", followed by the denominator // serialized as per . StringBuilder builder; serialize_a_number(builder, m_first_value); builder.append(" / "sv); serialize_a_number(builder, m_second_value); return builder.to_string_without_validation(); } }