changeset 147:4ac657b95f52

gsm-fw: sprintf %f: handle infinities and NaNs
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 14 Nov 2013 19:16:38 +0000
parents 4d629b6bbcfd
children 63750f70796d
files gsm-fw/sprintf/float.c
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/gsm-fw/sprintf/float.c	Thu Nov 14 19:03:52 2013 +0000
+++ b/gsm-fw/sprintf/float.c	Thu Nov 14 19:16:38 2013 +0000
@@ -67,6 +67,15 @@
 	double fract, tmp;
 	char *start, *t;
 
+	/* first order of business: weed out infinities and NaNs */
+	if (isinf(number)) {
+		if (number < 0)
+			sign = '-';
+		return _sprintf_field(op, width, flags, sign, "Inf", 3, 0, 0);
+	}
+	if (isnan(number))
+		return _sprintf_field(op, width, flags, sign, "NaN", 3, 0, 0);
+	/* OK, we know it's a valid real like in the good old VAX days */
 	if (number < 0) {
 		sign = '-';
 		number = -number;