-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfloat128.c
More file actions
45 lines (36 loc) · 838 Bytes
/
float128.c
File metadata and controls
45 lines (36 loc) · 838 Bytes
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
#include <stdio.h>
typedef long double float128;
void float128_from_double(float128* a, double* b) {
*a = (float128)(*(double*)(b));
}
void float128_to_double(float128* a, double* b) {
*b = (double)(*(float128*)(b));
}
void float128_add(float128* a, float128* b, float128* c) {
*c = *a + *b;
}
void float128_sub(float128* a, float128* b, float128* c) {
*c = *a - *b;
}
void float128_abs(float128* a, float128* b) {
if (*a > 0) {
*b = *a;
} else {
*b = -*a;
}
}
void float128_mul(float128* a, float128* b, float128* c) {
*c = *a * *b;
}
void float128_div(float128* a, float128* b, float128* c) {
*c = *a / *b;
}
int float128_cmp(float128* a, float128* b) {
if (*a > *b) {
return 1;
} else if (*a < *b) {
return -1;
} else {
return 0;
}
}