Ratio.cpp 617 B

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