-
Notifications
You must be signed in to change notification settings - Fork 102
/
fixstring.c
70 lines (62 loc) · 1.66 KB
/
fixstring.c
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
60
61
62
63
64
65
66
67
68
69
70
#include "fixstring.h"
#include <string.h>
void print_fix16_t(FILE *stream, fix16_t value, uint_fast8_t width, uint_fast8_t decimals)
{
char buf[13];
fix16_to_str(value, buf, decimals);
uint_fast8_t len = strlen(buf);
if (len < width)
{
width -= len;
while (width-- > 0)
fputc(' ', stream);
}
fputs(buf, stream);
}
void print_mf16(FILE *stream, const mf16 *matrix)
{
if (matrix->errors)
{
fprintf(stream, "MATRIX ERRORS: %d\n", matrix->errors);
}
int row, column;
for (row = 0; row < matrix->rows; row++)
{
for (column = 0; column < matrix->columns; column++)
{
fix16_t value = matrix->data[row][column];
print_fix16_t(stream, value, 9, 4);
fprintf(stream, " ");
}
fprintf(stream, "\n");
}
}
void print_qf16(FILE *stream, const qf16 *quat)
{
print_fix16_t(stream, quat->a, 9, 4);
fprintf(stream, " ");
print_fix16_t(stream, quat->b, 9, 4);
fprintf(stream, "i ");
print_fix16_t(stream, quat->c, 9, 4);
fprintf(stream, "j ");
print_fix16_t(stream, quat->d, 9, 4);
fprintf(stream, "k");
}
void print_v3d(FILE *stream, const v3d *vector)
{
fprintf(stream, "(");
print_fix16_t(stream, vector->x, 9, 4);
fprintf(stream, ", ");
print_fix16_t(stream, vector->y, 9, 4);
fprintf(stream, ", ");
print_fix16_t(stream, vector->z, 9, 4);
fprintf(stream, ")");
}
void print_v2d(FILE *stream, const v2d *vector)
{
fprintf(stream, "(");
print_fix16_t(stream, vector->x, 9, 4);
fprintf(stream, ", ");
print_fix16_t(stream, vector->y, 9, 4);
fprintf(stream, ")");
}