mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-10-31 21:30:58 +00:00 
			
		
		
		
	 cef9564728
			
		
	
	
		cef9564728
		
	
	
	
	
		
			
			This fixes an issue where we'd serialize some floating point numbers with excessive precision, resulting in unpleasant-looking numbers like 0.49999999999999999 and such. At least 90 new subtests passing on WPT, possibly more. :^)
		
			
				
	
	
		
			25 lines
		
	
	
	
		
			590 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
	
		
			590 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 MUST(String::formatted("{:.5}", m_value));
 | |
| }
 | |
| 
 | |
| }
 |