-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedfloat32_decode.c
More file actions
59 lines (49 loc) · 1.48 KB
/
medfloat32_decode.c
File metadata and controls
59 lines (49 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Copyright (c) 2025, Christophe Dufaza
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdint.h>
#include <stdio.h>
#include "cmedfloat/medfloat32.h"
#include "cmedfloat_cli_utils.h"
static inline void usage(void)
{
printf("usage: medfloat32-decode <medfloat>\n");
puts("");
puts("<medfloat> medfloat32 data, e.g. 0x07EFEF01");
}
int main(int argc, char *argv[])
{
struct cmedfloat_cli_args_decode cli_args;
struct cmedfloat_medfloat32 mfloat32;
double x;
if (!cmedfloat_cli_decode_parse_args(argc, argv, &cli_args, true)) {
return -1;
}
if (cli_args.opt_h) {
usage();
return 0;
}
mfloat32 = cmedfloat_medfloat32_decode(cli_args.data32);
x = cmedfloat_medfloat32_to_double(mfloat32);
if (cmedfloat_medfloat32_isnres(mfloat32)) {
printf("0x%02x%02x%02x%02x NRes\n", cli_args.data32[0], cli_args.data32[1],
cli_args.data32[2], cli_args.data32[3]);
return 0;
}
if (cmedfloat_medfloat32_isrfu(mfloat32)) {
printf("0x%02x%02x%02x%02x RFU\n", cli_args.data32[0], cli_args.data32[1],
cli_args.data32[2], cli_args.data32[3]);
return 0;
}
if (cmedfloat_medfloat32_isnormal(mfloat32)) {
printf("0x%02x%02x%02x%02x %de%d\n", cli_args.data32[0], cli_args.data32[1],
cli_args.data32[2], cli_args.data32[3], mfloat32.m, mfloat32.e);
} else {
/* Print Nan and +/-INFINITY with %f. */
printf("0x%02x%02x%02x%02x %f\n", cli_args.data32[0], cli_args.data32[1],
cli_args.data32[2], cli_args.data32[3], x);
}
return 0;
}