Browse code

q2double and double2q added

Jan Janak authored on 27/04/2004 14:52:57
Showing 1 changed files
... ...
@@ -80,6 +80,7 @@ typedef int qvalue_t;
80 80
 #define Q_PREFIX_LEN (sizeof(Q_PREFIX) - 1)
81 81
 
82 82
 
83
+
83 84
 /*
84 85
  * Calculate the length of printed q
85 86
  */
... ...
@@ -102,6 +103,32 @@ static inline size_t len_q(qvalue_t q)
102 102
 
103 103
 
104 104
 /*
105
+ * Convert qvalue_t to double
106
+ */
107
+static inline double q2double(qvalue_t q)
108
+{
109
+	if (q == Q_UNSPECIFIED) {
110
+		return -1;
111
+	} else {
112
+		return (double)((double)q / (double)1000);
113
+	}
114
+}
115
+
116
+
117
+/*
118
+ * Convert double to qvalue_t
119
+ */
120
+static inline qvalue_t double2q(double q)
121
+{
122
+	if (q == -1) {
123
+		return Q_UNSPECIFIED;
124
+	} else {
125
+		return q * 1000;
126
+	}
127
+}
128
+
129
+
130
+/*
105 131
  * Convert q value to string
106 132
  */
107 133
 static inline char* q2str(qvalue_t q, unsigned int* len)
... ...
@@ -130,12 +157,13 @@ static inline char* q2str(qvalue_t q, unsigned int* len)
130 130
 		q %= 10;
131 131
 		if (!q) goto end;
132 132
 
133
-		*p = q + '0';
134
-		*len = Q_PREFIX_LEN + 3;
133
+		*p++ = q + '0';
135 134
 	}
136 135
  end:
137 136
 	*p = '\0';
138
-	*len = p - buf;
137
+	if (len) {
138
+		*len = p - buf;
139
+	}
139 140
 	return buf;
140 141
 }
141 142