mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Improved speed of float serialization (about twice faster)
This commit is contained in:
		| @@ -1,6 +1,11 @@ | ||||
| ArduinoJson: change log | ||||
| ======================= | ||||
|  | ||||
| HEAD | ||||
| ---- | ||||
|  | ||||
| * Improved speed of float serialization (about twice faster) | ||||
|  | ||||
| v5.6.2 | ||||
| ------ | ||||
|  | ||||
|   | ||||
| @@ -98,12 +98,6 @@ class JsonWriter { | ||||
|       powersOf10 = 0; | ||||
|     } | ||||
|  | ||||
|     // Round correctly so that print(1.999, 2) prints as "2.00" | ||||
|     JsonFloat rounding = 0.5; | ||||
|     for (uint8_t i = 0; i < digits; ++i) rounding /= 10.0; | ||||
|  | ||||
|     value += rounding; | ||||
|  | ||||
|     // Extract the integer part of the value and print it | ||||
|     JsonUInt int_part = static_cast<JsonUInt>(value); | ||||
|     JsonFloat remainder = value - static_cast<JsonFloat>(int_part); | ||||
| @@ -116,10 +110,16 @@ class JsonWriter { | ||||
|  | ||||
|     // Extract digits from the remainder one at a time | ||||
|     while (digits-- > 0) { | ||||
|       // Extract digit | ||||
|       remainder *= 10.0; | ||||
|       JsonUInt toPrint = JsonUInt(remainder); | ||||
|       writeInteger(JsonUInt(remainder)); | ||||
|       remainder -= static_cast<JsonFloat>(toPrint); | ||||
|       char currentDigit = char(remainder); | ||||
|       remainder -= static_cast<JsonFloat>(currentDigit); | ||||
|  | ||||
|       // Round up last digit (so that print(1.999, 2) prints as "2.00") | ||||
|       if (digits == 0 && remainder >= 0.5) currentDigit++; | ||||
|  | ||||
|       // Print | ||||
|       writeRaw(char('0' + currentDigit)); | ||||
|     } | ||||
|  | ||||
|     if (powersOf10 < 0) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user