forked from WerWolv/ImHex-Patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfxpt.pat
More file actions
35 lines (25 loc) · 726 Bytes
/
fxpt.pat
File metadata and controls
35 lines (25 loc) · 726 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
#pragma once
namespace std::fxpt {
using fixed = s128;
fn to_float(fixed fxt, u32 precision) {
return double(fxt) / double((1 << precision));
};
fn to_fixed(double flt, u32 precision) {
return fixed((flt * (1 << precision)));
};
fn change_precision(fixed value, u32 start_precision, u32 end_precision) {
return std::fxpt::to_fixed(std::fxpt::to_float(value, start_precision), end_precision);
};
fn add(fixed a, fixed b, u32 precision) {
return a + b;
};
fn subtract(fixed a, fixed b, u32 precision) {
return a - b;
};
fn multiply(fixed a, fixed b, u32 precision) {
return (a * b) / (1 << precision);
};
fn divide(fixed a, fixed b, u32 precision) {
return (a << precision) / b;
};
}