Serenity Operating System
1/*
2 * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include "Ratio.h"
8#include <math.h>
9
10namespace Web::CSS {
11
12Ratio::Ratio(float first, float second)
13 : m_first_value(first)
14 , m_second_value(second)
15{
16}
17
18// https://www.w3.org/TR/css-values-4/#degenerate-ratio
19bool Ratio::is_degenerate() const
20{
21 return !isfinite(m_first_value) || m_first_value == 0
22 || !isfinite(m_second_value) || m_second_value == 0;
23}
24
25ErrorOr<String> Ratio::to_string() const
26{
27 return String::formatted("{} / {}", m_first_value, m_second_value);
28}
29
30}