提交 2ae2bdb3 编写于 作者: J John Lindgren

Make code C89-compliant.

上级 dbdd168e
...@@ -258,6 +258,9 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) ...@@ -258,6 +258,9 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
else else
{ {
int exponent = 0; int exponent = 0;
int decimals, digits;
UNITY_INT32 n;
char buf[16];
/* scale up or down by powers of 10 */ /* scale up or down by powers of 10 */
while (number < 100000.0f / 1e6f) { number *= 1e6f; exponent -= 6; } while (number < 100000.0f / 1e6f) { number *= 1e6f; exponent -= 6; }
...@@ -266,7 +269,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) ...@@ -266,7 +269,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
while (number > 1000000.0f) { number /= 10.0f; exponent++; } while (number > 1000000.0f) { number /= 10.0f; exponent++; }
/* round to nearest integer */ /* round to nearest integer */
UNITY_INT32 n = ((UNITY_INT32)(number + number) + 1) / 2; n = ((UNITY_INT32)(number + number) + 1) / 2;
if (n > 999999) if (n > 999999)
{ {
n = 100000; n = 100000;
...@@ -274,8 +277,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) ...@@ -274,8 +277,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
} }
/* determine where to place decimal point */ /* determine where to place decimal point */
int decimals = (exponent <= 0 && exponent >= -9) ? -exponent : 5; decimals = (exponent <= 0 && exponent >= -9) ? -exponent : 5;
exponent += decimals; exponent += decimals;
/* truncate trailing zeroes after decimal point */ /* truncate trailing zeroes after decimal point */
...@@ -286,8 +288,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) ...@@ -286,8 +288,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
} }
/* build up buffer in reverse order */ /* build up buffer in reverse order */
char buf[16]; digits = 0;
int digits = 0;
while (n != 0 || digits < decimals + 1) while (n != 0 || digits < decimals + 1)
{ {
buf[digits++] = (char)('0' + n % 10); buf[digits++] = (char)('0' + n % 10);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册