When saving XMLs, don't round floats that are bigger than INT_MAX. Fixes #1278

PiperOrigin-RevId: 590692020
Change-Id: Icd11d20f47bc4163eb4378f4cb031b8fd9d13612
This commit is contained in:
Yuval Tassa
2023-12-13 13:12:29 -08:00
committed by Copybara-Service
parent 0d37670698
commit 5b2c98f8f1
2 changed files with 27 additions and 1 deletions
+3 -1
View File
@@ -14,6 +14,7 @@
#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdio>
@@ -1004,7 +1005,8 @@ void mjXUtil::WriteAttr(XMLElement* elem, string name, int n, const T* data, con
}
// append number
if (isint(data[i])) {
double doubledata = static_cast<double>(data[i]);
if (doubledata < INT_MAX && doubledata > -INT_MAX && isint(data[i])) {
stream << Round(data[i]);
} else {
stream << data[i];