Lines Matching +full:5 +full:k +full:- +full:24 +full:k
4 * SPDX-License-Identifier: Apache-2.0
26 int32_t e = -1, v, f = 0; in lwm2m_float_to_b32()
28 int32_t val2 = (*in - (int32_t)*in) * PRECISION32; in lwm2m_float_to_b32()
32 return -EINVAL; in lwm2m_float_to_b32()
64 /* handle -e */ in lwm2m_float_to_b32()
65 e--; in lwm2m_float_to_b32()
68 v -= PRECISION32; in lwm2m_float_to_b32()
69 f |= 1 << (22 - i); in lwm2m_float_to_b32()
91 /* exponent: bits 30-23 */ in lwm2m_float_to_b32()
95 /* fraction: bits 22-0 */ in lwm2m_float_to_b32()
108 int32_t e = -1; in lwm2m_float_to_b64()
110 int64_t val2 = (*in - (int64_t)*in) * PRECISION64; in lwm2m_float_to_b64()
114 return -EINVAL; in lwm2m_float_to_b64()
146 /* handle -e */ in lwm2m_float_to_b64()
147 e--; in lwm2m_float_to_b64()
150 v -= PRECISION64; in lwm2m_float_to_b64()
151 f |= (int64_t)1 << (51 - i); in lwm2m_float_to_b64()
173 /* exponent: bits 62-52 */ in lwm2m_float_to_b64()
177 /* fraction: bits 51-0 */ in lwm2m_float_to_b64()
182 b64[4] = (f >> 24) & 0xFF; in lwm2m_float_to_b64()
183 b64[5] = (f >> 16) & 0xFF; in lwm2m_float_to_b64()
193 int32_t f, k, i, e; in lwm2m_b32_to_float() local
198 return -EINVAL; in lwm2m_b32_to_float()
207 /* calc exponent: bits 30-23 */ in lwm2m_b32_to_float()
211 e -= 127; in lwm2m_b32_to_float()
213 /* enable "hidden" fraction bit 24 which is always 1 */ in lwm2m_b32_to_float()
215 /* calc fraction: bits 22-0 */ in lwm2m_b32_to_float()
221 if (e > -1) { in lwm2m_b32_to_float()
227 val1 = (f >> (23 - e)) * (sign ? -1 : 1); in lwm2m_b32_to_float()
231 k = PRECISION32; in lwm2m_b32_to_float()
233 /* account for -e */ in lwm2m_b32_to_float()
234 while (e < -1) { in lwm2m_b32_to_float()
235 k /= 2; in lwm2m_b32_to_float()
239 for (i = 22 - e; i >= 0; i--) { in lwm2m_b32_to_float()
240 k /= 2; in lwm2m_b32_to_float()
242 val2 += k; in lwm2m_b32_to_float()
248 *out = (double)val1 - (double)val2 / PRECISION32; in lwm2m_b32_to_float()
259 int64_t f, k; in lwm2m_b64_to_float() local
265 return -EINVAL; in lwm2m_b64_to_float()
274 /* get exponent: bits 62-52 */ in lwm2m_b64_to_float()
278 e -= 1023; in lwm2m_b64_to_float()
282 /* get fraction: bits 51-0 */ in lwm2m_b64_to_float()
286 f += ((int64_t)b64[4] << 24); in lwm2m_b64_to_float()
287 f += ((int64_t)b64[5] << 16); in lwm2m_b64_to_float()
292 if (e > -1) { in lwm2m_b64_to_float()
298 val1 = (f >> (52 - e)) * (sign ? -1 : 1); in lwm2m_b64_to_float()
302 k = PRECISION64; in lwm2m_b64_to_float()
304 /* account for -e */ in lwm2m_b64_to_float()
305 while (e < -1) { in lwm2m_b64_to_float()
306 k /= 2; in lwm2m_b64_to_float()
310 for (i = 51 - e; i >= 0; i--) { in lwm2m_b64_to_float()
311 k /= 2; in lwm2m_b64_to_float()
313 val2 += k; in lwm2m_b64_to_float()
319 *out = (double)val1 - (double)val2 / PRECISION64; in lwm2m_b64_to_float()
329 char *pos, *end, buf[24]; in lwm2m_atof()
335 return -EINVAL; in lwm2m_atof()
338 strncpy(buf, input, sizeof(buf) - 1); in lwm2m_atof()
339 buf[sizeof(buf) - 1] = '\0'; in lwm2m_atof()
341 if (strchr(buf, '-')) { in lwm2m_atof()
342 sign = -1; in lwm2m_atof()
353 return -EINVAL; in lwm2m_atof()
365 val2 = val2 * 10 + (*pos - '0'); in lwm2m_atof()
373 return !*pos || base == 1 ? 0 : -EINVAL; in lwm2m_atof()
381 int64_t val2 = (*input - (int64_t)*input) * PRECISION64; in lwm2m_ftoa()
391 bool round_up = buf[dec_limit] >= '5'; in lwm2m_ftoa()
397 dec_limit--; in lwm2m_ftoa()
409 val1--; in lwm2m_ftoa()
417 while (len > 1U && buf[len - 1] == '0') { in lwm2m_ftoa()
418 buf[--len] = '\0'; in lwm2m_ftoa()
424 (val1 == 0 && val2 < 0) ? "-" : "", (long long)val1, buf); in lwm2m_ftoa()
432 /* we should get a value first - consume all numbers */ in lwm2m_atou16()
434 val = val * 10U + (buf[pos] - '0'); in lwm2m_atou16()
446 int i, tokstart = -1, toklen; in lwm2m_string_to_path()
447 int end_index = strlen(pathstr) - 1; in lwm2m_string_to_path()
452 if (tokstart == -1) { in lwm2m_string_to_path()
462 toklen = i - tokstart + 1; in lwm2m_string_to_path()
466 toklen--; in lwm2m_string_to_path()
475 path->level++; in lwm2m_string_to_path()
476 switch (path->level) { in lwm2m_string_to_path()
478 path->obj_id = value; in lwm2m_string_to_path()
482 path->obj_inst_id = value; in lwm2m_string_to_path()
486 path->res_id = value; in lwm2m_string_to_path()
490 path->res_inst_id = value; in lwm2m_string_to_path()
494 return -EINVAL; in lwm2m_string_to_path()
498 tokstart = -1; in lwm2m_string_to_path()
507 uint8_t level = a->level; in lwm2m_obj_path_equal()
509 if (a->level != b->level) { in lwm2m_obj_path_equal()
513 if (level >= LWM2M_PATH_LEVEL_OBJECT && (a->obj_id != b->obj_id)) { in lwm2m_obj_path_equal()
517 if (level >= LWM2M_PATH_LEVEL_OBJECT_INST && (a->obj_inst_id != b->obj_inst_id)) { in lwm2m_obj_path_equal()
521 if (level >= LWM2M_PATH_LEVEL_RESOURCE && (a->res_id != b->res_id)) { in lwm2m_obj_path_equal()
525 if (level >= LWM2M_PATH_LEVEL_RESOURCE_INST && (a->res_inst_id != b->res_inst_id)) { in lwm2m_obj_path_equal()
537 if (addr->sa_family == AF_INET6) { in lwm2m_sprint_ip_addr()
538 return net_addr_ntop(AF_INET6, &net_sin6(addr)->sin6_addr, buf, sizeof(buf)); in lwm2m_sprint_ip_addr()
541 if (addr->sa_family == AF_INET) { in lwm2m_sprint_ip_addr()
542 return net_addr_ntop(AF_INET, &net_sin(addr)->sin_addr, buf, sizeof(buf)); in lwm2m_sprint_ip_addr()
551 return digit - 10U + 'a'; in to_hex_digit()
565 tkl = MIN(tkl, sizeof(buf) / 2 - 1); in sprint_token()
574 strcpy(buf, "[no-token]"); in sprint_token()