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
  */
... ...
@@ -101,6 +102,32 @@ static inline size_t len_q(qvalue_t q)
101 102
 }
102 103
 
103 104
 
105
+/*
106
+ * Convert qvalue_t to double
107
+ */
108
+static inline double q2double(qvalue_t q)
109
+{
110
+	if (q == Q_UNSPECIFIED) {
111
+		return -1;
112
+	} else {
113
+		return (double)((double)q / (double)1000);
114
+	}
115
+}
116
+
117
+
118
+/*
119
+ * Convert double to qvalue_t
120
+ */
121
+static inline qvalue_t double2q(double q)
122
+{
123
+	if (q == -1) {
124
+		return Q_UNSPECIFIED;
125
+	} else {
126
+		return q * 1000;
127
+	}
128
+}
129
+
130
+
104 131
 /*
105 132
  * Convert q value to string
106 133
  */
... ...
@@ -130,12 +157,13 @@ static inline char* q2str(qvalue_t q, unsigned int* len)
130 157
 		q %= 10;
131 158
 		if (!q) goto end;
132 159
 
133
-		*p = q + '0';
134
-		*len = Q_PREFIX_LEN + 3;
160
+		*p++ = q + '0';
135 161
 	}
136 162
  end:
137 163
 	*p = '\0';
138
-	*len = p - buf;
164
+	if (len) {
165
+		*len = p - buf;
166
+	}
139 167
 	return buf;
140 168
 }
141 169